vbauerster / mpb

multi progress bar for Go cli applications
The Unlicense
2.29k stars 123 forks source link

[Windows] Single bar duplicates when exactly terminal width #66

Closed benmurden closed 4 years ago

benmurden commented 4 years ago

Running the IO example given here https://github.com/vbauerster/mpb/blob/master/_examples/io/main.go with some modifications to prepend a long name, I have reproduced an issue I'm having where bars get duplicated once they reach the edge of the terminal window.

image

Actual code ```golang package main import ( "crypto/rand" "io" "io/ioutil" "time" "github.com/vbauerster/mpb/v5" "github.com/vbauerster/mpb/v5/decor" ) func main() { var total int64 = 1024 * 1024 * 1024 reader := io.LimitReader(rand.Reader, total) p := mpb.New( mpb.WithWidth(60), mpb.WithRefreshRate(180*time.Millisecond), ) bar := p.AddBar(total, mpb.BarStyle("[=>-|"), mpb.PrependDecorators( decor.Name("This is a really long name. I'm sorry it's so long but that's just the way it goes sometimes. "), decor.CountersKibiByte("% .2f / % .2f"), decor.Percentage(decor.WCSyncSpace), ), mpb.AppendDecorators( decor.EwmaETA(decor.ET_STYLE_GO, 90), decor.Name(" ] "), decor.EwmaSpeed(decor.UnitKiB, "% .2f", 60), ), ) // create proxy reader proxyReader := bar.ProxyReader(reader) defer proxyReader.Close() // copy from proxyReader, ignoring errors io.Copy(ioutil.Discard, proxyReader) p.Wait() } ```

The bar is clearly flexing to fill available space, but is still one character too long, it seems. Shorter names do not produce this issue.

OS: Windows 10

nektro commented 4 years ago

potential dupe of #55

benmurden commented 4 years ago

While it seems that way on the surface, I think this is a subtle bug, because the bar is being shrunk to fit the terminal width, but still wraps. Looks like the final size needs to be one or two characters shorter.

vbauerster commented 4 years ago

Can you please check master branch? Should be fixed.

benmurden commented 4 years ago

@vbauerster Looks good over here with the master branch. Thanks so much for your time and effort on this.

vbauerster commented 4 years ago

Thank you for reporting as well. I'll bump version soon.