Skip to content

Commit 19b6ec5

Browse files
committed
Improve non-TTY output for progress indicators with status bars.
1 parent 5dacfdd commit 19b6ec5

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

internal/output/progress_with_status_bars.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func newProgressWithStatusBars(bars []ProgressBar, statusBars []*StatusBar, o *O
1515
}
1616

1717
if !o.caps.Isatty {
18-
newProgressWithStatusBarsSimple(barPtrs, statusBars, o)
18+
return newProgressWithStatusBarsSimple(barPtrs, statusBars, o)
1919
}
2020

2121
return newProgressWithStatusBarsTTY(barPtrs, statusBars, o, opts)

internal/output/progress_with_status_bars_simple.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,28 @@ func (p *progressWithStatusBarsSimple) Complete() {
1616
writeStatusBars(p.Output, p.statusBars)
1717
}
1818

19+
func (p *progressWithStatusBarsSimple) StatusBarUpdatef(i int, format string, args ...interface{}) {
20+
if p.statusBars[i] != nil {
21+
p.statusBars[i].Updatef(format, args...)
22+
}
23+
}
24+
25+
func (p *progressWithStatusBarsSimple) StatusBarCompletef(i int, format string, args ...interface{}) {
26+
if p.statusBars[i] != nil {
27+
wasComplete := p.statusBars[i].completed
28+
p.statusBars[i].Completef(format, args...)
29+
if !wasComplete {
30+
writeStatusBar(p.Output, p.statusBars[i])
31+
}
32+
}
33+
}
34+
35+
func (p *progressWithStatusBarsSimple) StatusBarResetf(i int, label, format string, args ...interface{}) {
36+
if p.statusBars[i] != nil {
37+
p.statusBars[i].Resetf(label, format, args...)
38+
}
39+
}
40+
1941
func newProgressWithStatusBarsSimple(bars []*ProgressBar, statusBars []*StatusBar, o *Output) *progressWithStatusBarsSimple {
2042
p := &progressWithStatusBarsSimple{
2143
progressSimple: &progressSimple{
@@ -35,6 +57,7 @@ func newProgressWithStatusBarsSimple(bars []*ProgressBar, statusBars []*StatusBa
3557
case <-ticker.C:
3658
if p.Output.opts.Verbose {
3759
writeBars(p.Output, p.bars)
60+
writeStatusBars(p.Output, p.statusBars)
3861
}
3962

4063
case c := <-p.done:

0 commit comments

Comments
 (0)