Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
benmurden opened this issue May 10, 2020 · 5 comments
Closed

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

benmurden opened this issue May 10, 2020 · 5 comments

Comments

@benmurden
Copy link

benmurden commented May 10, 2020

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
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
Copy link

nektro commented May 11, 2020

potential dupe of #55

@benmurden
Copy link
Author

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
Copy link
Owner

Can you please check master branch? Should be fixed.

@benmurden
Copy link
Author

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

@vbauerster
Copy link
Owner

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

vbauerster added a commit that referenced this issue Jul 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants