Progress bar are automagically disabled if stderr is redirected

Former-commit-id: 20a3a22db7dcf530b9e9cad9090b46f22db0d078
This commit is contained in:
Eric Coissac
2024-04-22 12:23:59 +02:00
parent 8f08959ebb
commit f37477b26c

View File

@ -1,6 +1,10 @@
package obiconvert
import (
"os"
log "github.com/sirupsen/logrus"
"github.com/DavidGamba/go-getoptions"
)
@ -182,7 +186,14 @@ func CLIAnalyzeOnly() int {
}
func CLIProgressBar() bool {
return !__no_progress_bar__
// If the output is not a terminal, then we do not display the progress bar
o, _ := os.Stderr.Stat()
onTerminal := (o.Mode() & os.ModeCharDevice) == os.ModeCharDevice
if !onTerminal {
log.Info("Stderr is redirected, progress bar disabled")
}
return onTerminal && !__no_progress_bar__
}
func CLIOutPutFileName() string {