Closed mozillazg closed 6 years ago
You're welcome! You can't, because this feature isn't implemented. Why would you need this? What is your use case?
For example:
Download a directory with a progress, but I don't know the total size of all files in this directory(because the api for getting all files info for a directory has pagination).
If you don't know the total beforehand, you can set it to zero or negative. In that case progress bar will be replaced by simple spinner. Is it ok for you?
In that case progress bar will lose progress:
Bar#0: 0 % [|] -5s
If it could still have a progress will be better:
Bar#0: 13 % [===>----------------------------] 3s
I'm quite busy for the next two weeks, so your PR is welcome. However setting (incrementing) total dynamically, may cause undesired/unexpected behaviour of a progress bar. For example, imagine current progress shows 99%, and at that point you increment the total. It means progress will drop from 99% to something lower say 50%. But what if someone will decrement total by mistake?
I'm going to close this issue out because it doesn't seem to be getting any traction. Anyone please feel free to re-open it if you want to work on this :)
Looking at this issue, seems like a big missing feature. I have lots of applications that might make a guess at a total quickly, but then update it as more information becomes available (eventual consistency). e.g. counting all the files in a filesystem or S3 bucket might take hours, but during a copy operation you may have a goro finding files and passing them along to a goro copying them elsewhere. Knowing counts beforehand is actually abnormal at scale. A more practical example is a program that reads lines from stdin and acts on them - it might not know the count ahead of time, but by having separate goros reading vs. processing (thanks, channels), it could be continuously updating the total at a different pace than the processor.
A naive, and working, patch is below. It properly updates the total, and the percentage shifts, the ETA changes, etc. The progress bar, however, is replaced by a spinner, and I'm unsure how to get that back.
func (b *Bar) SetTotal(newTotal int64) {
b.ops <- func(s *state) {
if s.completed == true {
s.completed = false
}
s.total = newTotal
}
}
I haven't looked into the bar issue for more than a few moments.
Dynamic total implemented. See SetTotal.
Works as expected. With the while-running configurability of mpb, this is really a compelling package for tools that may run non-trivially long, and want to report feedback symbolically. Thanks for reassessing this.
You're welcome. Also if you have a chance to make animated gif with dynamic total in action, I will be happy to put it in readme.
Attached please find a demo of the settotal in use. First guess is "50" then it paddles up to the actual total of 142.
First of all, many thanks for your work! I have a question: How can I dynamic setting the total value of bar?
Thanks!