ctongfei / progressbar

Terminal-based progress bar for Java / JVM
http://tongfei.me/progressbar/
MIT License
1.07k stars 102 forks source link

Progress bar reset does not do anything #124

Closed Bricktheworld closed 1 year ago

Bricktheworld commented 2 years ago

Hello, I'm not sure if I am doing something wrong however I need the progress bar to be able to dip to a lower percentage when necessary. I am calling "stepTo", however, this does not move the progress bar down if a lower percentage is provided. If I try to call "reset", the bar simply ignores that call and continues on. Is this behavior intended? If so is there a way a change can either be implemented or I can modify the library? I am using Arch Linux with alacrity in the zsh shell.

Bricktheworld commented 2 years ago

Actually, I'm sorry, this is my mistake, using the ProgressBarBuilder to continuously update has fixed the issue.

ctongfei commented 2 years ago

Hello @Bricktheworld , this does seem like a bug to me. Can you paste your minimized snippet here?

Bricktheworld commented 2 years ago

Hey @ctongfei, sorry for the late response! Here is a simple example that should show how it can be reproduced, please let me know if you are able to replicate and if you need anything else.

int someProgress = 0;
try (var pb = new ProgressBar("Some progress", 100)) {
     while(true) {
          Thread.sleep(500);
          if (someProgress >= 100) {
                  pb.reset();
                  someProgress = 0;
                  continue;
          }
          someProgress += 10;
          pb.stepTo(someProgress);
     }
}
ctongfei commented 1 year ago

Hi @Bricktheworld sorry for the late response. This is a bug due to a recent optimization that only refreshes the progress bar if it went forward. It did not account for the condition where it stepped backward when calling stepTo. This will be fixed in the next version. Thanks!