progressbar
progressbar copied to clipboard
Throttle prevents initial RenderBlank from working
If you create a new default bar and immediately try to RenderBlank()
, nothing will render. To work around this:
func NewBar(max int, description ...string) *progressbar.ProgressBar {
bar := progressbar.Default(int64(max), description...)
// wait for throttle duration so initial render doesn't skip
time.Sleep(65 * time.Millisecond)
bar.RenderBlank()
return bar
}
Haven't tested, but I think the problem is the p.state.lastShown
is set to time.Now()
along with p.config.throttleDuration
in:
func getBasicState() state {
now := time.Now()
return state{
startTime: now,
lastShown: now,
counterTime: now,
}
}
Maybe set lastShown
to 0?
i just stumbled across the same issue.
The initial handshake takes a bit ( ~3 seconds) and the bar will not display the blank bar until after the second write of the io.MultiWriter.
Changing getBasicState lastShown to a empty Time{} made it work.
func getBasicState() state {
now := time.Now()
return state{
startTime: now,
lastShown: time.Time{}, // empty time struct.
counterTime: now,
}
}
I ran into this problem too.
The solution above from @kirides almost works however it causes the OptionSetRenderBlankState(true)
option to be ignored. I think a better approach is to simply have RenderBlank
ignore throttling and always trigger a render. I can't imagine anyone would be abusing this API in a tight loop.