Add progress bar configuration and conditional display

This commit introduces a new configuration module `obidefault` to manage progress bar settings, allowing users to disable progress bars via a `--no-progressbar` option. It updates various packages to conditionally display progress bars based on this new configuration, improving user experience by providing control over progress bar output. The changes also include improvements to progress bar handling in several packages, ensuring they are only displayed when appropriate (e.g., when stderr is a terminal and stdout is not piped).
This commit is contained in:
Eric Coissac
2026-02-08 16:13:27 +01:00
parent b2d16721f0
commit 1a28d5ed64
11 changed files with 193 additions and 125 deletions

View File

@@ -5,18 +5,30 @@ import (
"os"
"time"
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obidefault"
"github.com/schollz/progressbar/v3"
)
func (iterator IBioSequence) Speed(message string, size ...int) IBioSequence {
// If the STDERR is redicted and doesn't end up to a terminal
// If the progress bar is disabled via --no-progressbar option
if !obidefault.ProgressBar() {
return iterator
}
// If the STDERR is redirected and doesn't end up to a terminal
// No progress bar is printed.
o, _ := os.Stderr.Stat()
if (o.Mode() & os.ModeCharDevice) != os.ModeCharDevice {
return iterator
}
// If stdout is piped, no progress bar is printed.
oo, _ := os.Stdout.Stat()
if (oo.Mode() & os.ModeNamedPipe) == os.ModeNamedPipe {
return iterator
}
newIter := MakeIBioSequence()
newIter.Add(1)