pb icon indicating copy to clipboard operation
pb copied to clipboard

Disable when no TTY?

Open snarlysodboxer opened this issue 1 year ago • 1 comments

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.

snarlysodboxer avatar Nov 19 '23 16:11 snarlysodboxer

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
}

cheggaaa avatar Jan 19 '24 16:01 cheggaaa

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!

snarlysodboxer avatar Feb 28 '24 03:02 snarlysodboxer