mirror of
https://github.com/metabarcoding/obitools4.git
synced 2026-03-25 13:30:52 +00:00
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user