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,6 +5,7 @@ import (
"sort"
"unsafe"
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obidefault"
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obifp"
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obilog"
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiseq"
@@ -267,20 +268,23 @@ func NewKmerMap[T obifp.FPUint[T]](
}
n := len(sequences)
pbopt := make([]progressbar.Option, 0, 5)
pbopt = append(pbopt,
progressbar.OptionSetWriter(os.Stderr),
progressbar.OptionSetWidth(15),
progressbar.OptionShowCount(),
progressbar.OptionShowIts(),
progressbar.OptionSetDescription("Indexing kmers"),
)
var bar *progressbar.ProgressBar
if obidefault.ProgressBar() {
pbopt := make([]progressbar.Option, 0, 5)
pbopt = append(pbopt,
progressbar.OptionSetWriter(os.Stderr),
progressbar.OptionSetWidth(15),
progressbar.OptionShowCount(),
progressbar.OptionShowIts(),
progressbar.OptionSetDescription("Indexing kmers"),
)
bar := progressbar.NewOptions(n, pbopt...)
bar = progressbar.NewOptions(n, pbopt...)
}
for i, sequence := range sequences {
kmap.Push(sequence, maxoccurs)
if i%100 == 0 {
if bar != nil && i%100 == 0 {
bar.Add(100)
}
}