-
Notifications
You must be signed in to change notification settings - Fork 251
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Allow to manually redraw the progress bar #688
Comments
Hi, not 100% sure I understand your issue. But have you had a look at That will decouple rendering of the progress bar from your calls to |
Hmm seems like [ But basically I'd like to manually redraw the progress bar without having a separate thread. I'd like the output to be refreshed synchronously when the progress bar changes. When you look at the example code I provided, I would expect the call to |
Not every call to Normally you would call AFAIK, there is no other way to enforce that the bar is drawn. |
Would it be possible to add a method that allows to force re-rendering of the progress bar? To ensure it is completely synchronized with its internal state. |
Can you talk a bit about your use-case? I'm curious to learn why the intended ways don't match your needs. In my view it should be fine to add a There is also suspend, which is essentially just a force draw: for _ in 0..LEN {
pb.inc(1);
}
pb.suspend(|| {}); Alternatively you can use pb.set_draw_target(ProgressDrawTarget::term_like(Box::new(Term::stderr())));
for _ in 0..LEN {
pb.inc(1);
}
pb.tick(); |
I have several use cases where I had this problem, one of them is a progress bar to follow the copy of lots of small files. After the copying is done, the program continues by doing other things, but keeps the progress bar displayed as it provides informations on how much time was spent and how many files were copied. Using just |
I guess the canonical way would be to enable the steady tick, since that would also update the ETA, etc. I also think it's fine to have a separate thread to manage that. But I also see little harm in allowing users to force a redraw. |
This is a pretty niche use case for sure, in most cases I agree it's better to use [`enable_steady_stick']. |
Why doesn't |
What I want to do is to ensure, at one specific point in time, that the displayed progress bar matches the position. I don't want to have a delay between the moment I call |
Your exact requirements still aren't making sense to me. Either you call |
Sorry if I didn't explain it well (english is not my first language so it's pretty hard to explain some things). |
The rate limiting is in place to make sure you don't inadvertently incur a relatively large overhead just from drawing the progress bar, though. So why is it important to you to draw every time you call |
Ok so let me explain the concrete problem (maybe I should have started from that): I'm currently building a shell (akin to Bash / ZSH / Fish / etc.) which exposes some functions to create and manipulate a progress bar. Due to the nature of shell scripting, there can be other outputs from other commands at the same time that the progress bar is making progress. So it's important that the output is more or less instantly updated when the progress bar's advancement changes. One other problem I've had is when the progress bar is making changes rapidly, and the program exits before the progress bar has updated the terminal's output. In such case, we end up with the problem that occurs in the first example I gave, in which when the program ends the progress bar's displayed position does not match its internal state. Hence why I'd like to have instant synchronization, even if it indeed creates a large overhead. But this is something I can handle or customize in my own shell if necessary. |
Okay, and #689 would address your use case? |
Hi!
I've been using this crate a lot and it's been amazing, thanks for making it <3
I only have one problem currently, which is that the progress bar doesn't update visually when position changes happen too quickly. Here is an example:
If you run this program, you will see when we reach the
sleep
portion that the program only has a part of the progress bar filled. Every time you run the program, the final position is a little bit different.Uncommenting the
pb.tick();
line worsens the problem as the bar gets stuck on position 10 / 10000 (I understand the problem with the previous code why not sure why for this one?)So I'd like to be able to manually refresh the progress bar and redraw it. Something like
pb.redraw()
orpb.refresh()
. It would obviously greatly increase latency and this example code would become a lot slower, but that would solve the problem I have.I didn't find a way to do this currently ; would it be possible to add this feature?
Many thanks :)
The text was updated successfully, but these errors were encountered: