pb
pb copied to clipboard
Disable when no TTY?
Love this project, thank you!
It would be awesome to be able to disable updates to existing lines when there's no TTY, so that when a tool runs in a docker container in CI for example, it can still have readable output. I recognize that's the whole point of this library, but as it is, I have to write repeated if isTTY
around each call to bar, and it would be cool to be able to instead simply do it once with something like
if isatty.IsTerminal(os.Stdout.Fd()) {
bar.DisableUpdates()
}
or similar.
There's room for debate on the exact functionality, but maybe it could just report on a new line when 25%, 50%, 75%, and 100% done? Or maybe every N seconds it reports % done on a new line.
Hi, thank you!
There are two ways
// first way
if !isatty.IsTerminal(os.Stdout.Fd()) {
bar.SetRefreshRate(time.Minute) // set an desired update interval
}
// second way
if !isatty.IsTerminal(os.Stdout.Fd()) {
// should be called before pb.Start
bar.Set(pb.Static, true)
// later you can print bar.String() whenever you want
}
Thank you @cheggaaa! I'm just seeing this now. I must have missed this solution.
I'm looking forward to trying it soon. Thanks again!