Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/src/campaign_progress_printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (p *campaignProgressPrinter) initProgressBar(statuses []*campaigns.TaskStat

statusBars := make([]*output.StatusBar, 0, numStatusBars)
for i := 0; i < numStatusBars; i++ {
statusBars = append(statusBars, output.NewStatusBarWithLabel("Starting worker..."))
statusBars = append(statusBars, output.NewStatusBar())
}

p.progress = p.out.ProgressWithStatusBars([]output.ProgressBar{{
Expand Down
15 changes: 11 additions & 4 deletions internal/output/progress_with_status_bars_tty.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ func newProgressWithStatusBarsTTY(bars []*ProgressBar, statusBars []*StatusBar,
type progressWithStatusBarsTTY struct {
*progressTTY

statusBars []*StatusBar
statusBarLabelWidth int
statusBars []*StatusBar
statusBarLabelWidth int
numPrintedStatusBars int
}

func (p *progressWithStatusBarsTTY) Close() { p.Destroy() }
Expand Down Expand Up @@ -83,7 +84,7 @@ func (p *progressWithStatusBarsTTY) Complete() {
defer p.o.lock.Unlock()

// +1 because of the line between progress and status bars
for i := 0; i < len(p.statusBars)+1; i += 1 {
for i := 0; i < p.numPrintedStatusBars+1; i += 1 {
p.o.moveUp(1)
p.o.clearCurrentLine()
}
Expand All @@ -98,7 +99,7 @@ func (p *progressWithStatusBarsTTY) Complete() {
}

func (p *progressWithStatusBarsTTY) lines() int {
return len(p.bars) + len(p.statusBars) + 1
return len(p.bars) + p.numPrintedStatusBars + 1
}

func (p *progressWithStatusBarsTTY) SetLabel(i int, label string) {
Expand Down Expand Up @@ -162,12 +163,18 @@ func (p *progressWithStatusBarsTTY) draw() {

}

p.numPrintedStatusBars = 0
for i, statusBar := range p.statusBars {
if statusBar == nil {
continue
}
if !statusBar.initialized {
continue
}

last := i == len(p.statusBars)-1
p.writeStatusBar(last, statusBar)
p.numPrintedStatusBars += 1
}
}

Expand Down
9 changes: 7 additions & 2 deletions internal/output/status_bar.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ type StatusBar struct {
format string
args []interface{}

startedAt time.Time
finishedAt time.Time
initialized bool
startedAt time.Time
finishedAt time.Time
}

// Completef sets the StatusBar to completed and updates its text.
Expand All @@ -25,6 +26,7 @@ func (sb *StatusBar) Completef(format string, args ...interface{}) {

// Resetf sets the status of the StatusBar to incomplete and updates its label and text.
func (sb *StatusBar) Resetf(label, format string, args ...interface{}) {
sb.initialized = true
sb.completed = false
sb.label = label
sb.format = format
Expand All @@ -34,6 +36,7 @@ func (sb *StatusBar) Resetf(label, format string, args ...interface{}) {

// Updatef updates the StatusBar's text.
func (sb *StatusBar) Updatef(format string, args ...interface{}) {
sb.initialized = true
sb.format = format
sb.args = args
}
Expand All @@ -52,3 +55,5 @@ func (sb *StatusBar) runtime() time.Duration {
func NewStatusBarWithLabel(label string) *StatusBar {
return &StatusBar{label: label, startedAt: time.Now()}
}

func NewStatusBar() *StatusBar { return &StatusBar{} }