From f37477b26c772381c20037f62176e822df0c15aa Mon Sep 17 00:00:00 2001 From: Eric Coissac Date: Mon, 22 Apr 2024 12:23:59 +0200 Subject: [PATCH] Progress bar are automagically disabled if stderr is redirected Former-commit-id: 20a3a22db7dcf530b9e9cad9090b46f22db0d078 --- pkg/obitools/obiconvert/options.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pkg/obitools/obiconvert/options.go b/pkg/obitools/obiconvert/options.go index 255e208..a552e7f 100644 --- a/pkg/obitools/obiconvert/options.go +++ b/pkg/obitools/obiconvert/options.go @@ -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 {