schollz / progressbar

A really basic thread-safe progress bar for Golang applications
https://pkg.go.dev/github.com/schollz/progressbar/v3?tab=doc
MIT License
4.1k stars 219 forks source link

Duplicate rendering of extra empty lines #97

Open zc2638 opened 3 years ago

zc2638 commented 3 years ago

When revert 3e6b9bf007862f9acf97b7cdc2dc2c8f6683f110 Each time the progress bar is rendered, an empty line is added.

func main() {
    bar := progressbar.Default(100)
    for i := 0; i < 100; i++ {
        bar.Add(1)
        time.Sleep(40 * time.Millisecond)
    }
}

image

zc2638 commented 3 years ago

@schollz

schollz commented 3 years ago

3e6b9bf didn't fix any particular problem I knew of and caused a new problem - that progressbars that are shorter than previous are not be cleared so you get things like [0s:3s]s] at the end...

but now I see you have a particular problem that you were trying to fix. I think the fix for that problem you are having is related to the calculation of the window width used with the Default function. Can you try reducing the width here: https://github.com/schollz/progressbar/blob/master/progressbar.go#L679-L688

Also, what system are you seeing this (terminal, shell, OS, etc.)?

zc2638 commented 3 years ago

I found that the default progress bar symbol width is uncontrollable. Apart from replacing it, how to solve it?

schollz commented 3 years ago

See my previous comment

zc2638 commented 3 years ago

I haven't found a way to calculate the width of symbol. Do you have any good solution?

When I set it like this, the performance is normal:

progressbar.OptionSetTheme(progressbar.Theme{
    Saucer:        "=",
    SaucerPadding: " ",
    BarStart:      "|",
    BarEnd:        "|",
    SaucerHead:    ">",
})
axetroy commented 2 years ago

I also encountered this problem on macOS with version v3.8.3

reber0 commented 2 years ago

macOS, v3.8.3, same problem

Lan-ce-lot commented 1 year ago

macOS, v3.13.0, same problem

JohnieXu commented 1 year ago

The same problem on Window10 powershell with version v3.13.1 image

tukaelu commented 12 months ago

@schollz I too am having trouble with this issue. Is it correct to say that the reason for reverting 3e6b9bf is the issue where a display like [0s:3s] shown at the end of the progress bar during execution remains even after execution?

If that is correct, it seems to me that you probably have a terminal that is not working correctly because the current implementation keeps increasing s.maxLineWidth, which embeds extra space.

https://github.com/schollz/progressbar/blob/3d122971646c65a9eff62c04531ec131ffb7ce5a/progressbar.go#L990

I think that filling in the terminal with white space for the width of the terminal would solve all problems.

I created a pull request that deals with this issue. As far as I can tell from the examples/basic code, it doesn't seem to reproduce the problem, but please check just in case.

tukaelu commented 12 months ago

I found an error in the correction, so I withdrew the pull request(#168). I finally understood that the cause of this issue lies in the part that counts the width of the symbol.

I made a fix to keep the s.maxLineWidth variable fixed at the terminal width, as I had observed it increasing as the progress bar advanced. However, it was not the correct approach.

When I set the C value for the LANG environment variable and ran it, s.maxLineWidth continued to return a fixed value. However, when I changed it to my usual setting, ja_JP.UTF-8, the issue of continuous line breaks reappeared.

This seems to be caused by the current implementation counting the number of runes.

Currently, since the library update for mattn/go-runewidth, which we use for calculating the width of runes, is lagging behind, it seems that the issue can be resolved by replacing it with rivo/uniseg that it internally uses.

tukaelu commented 11 months ago

@zc2638 @axetroy @reber0 @Lan-ce-lot @JohnieXu

I apologize for mentioning many of you. The PR #169 that resolves this issue has been merged, and it has been released as v3.14.0.

I believe this problem has likely been resolved, so please everyone check it out.

Lan-ce-lot commented 11 months ago

@zc2638 @axetroy @reber0 @Lan-ce-lot @JohnieXu

I apologize for mentioning many of you. The PR #169 that resolves this issue has been merged, and it has been released as v3.14.0.

I believe this problem has likely been resolved, so please everyone check it out.

I'm glad to hear that.👍