Skip to content

Commit

Permalink
progress: fix edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
jedib0t committed Oct 6, 2024
1 parent 8515c8f commit 94eef78
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
16 changes: 9 additions & 7 deletions progress/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,16 @@ func (p *Progress) renderTracker(out *strings.Builder, t *Tracker, hint renderHi
}

func (p *Progress) renderTrackerDone(out *strings.Builder, t *Tracker, message string) {
out.WriteString(p.style.Colors.Message.Sprint(message))
out.WriteString(p.style.Colors.Message.Sprint(p.style.Options.Separator))
if !t.IsErrored() {
out.WriteString(p.style.Colors.Message.Sprint(p.style.Options.DoneString))
} else {
out.WriteString(p.style.Colors.Error.Sprint(p.style.Options.ErrorString))
if !t.RemoveOnCompletion {
out.WriteString(p.style.Colors.Message.Sprint(message))
out.WriteString(p.style.Colors.Message.Sprint(p.style.Options.Separator))
if !t.IsErrored() {
out.WriteString(p.style.Colors.Message.Sprint(p.style.Options.DoneString))
} else {
out.WriteString(p.style.Colors.Error.Sprint(p.style.Options.ErrorString))
}
p.renderTrackerStats(out, t, renderHint{hideTime: !p.style.Visibility.Time, hideValue: !p.style.Visibility.Value})
}
p.renderTrackerStats(out, t, renderHint{hideTime: !p.style.Visibility.Time, hideValue: !p.style.Visibility.Value})
}

func (p *Progress) renderTrackerMessage(out *strings.Builder, t *Tracker, message string) {
Expand Down
4 changes: 2 additions & 2 deletions progress/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,8 @@ func TestProgress_RenderSomeTrackers_AndRemove(t *testing.T) {
pw := generateWriter()
pw.SetOutputWriter(&renderOutput)
pw.SetTrackerPosition(PositionLeft)
go trackSomething(pw, &Tracker{Message: "Calculating Total # 1\r", Total: 1000, Units: UnitsDefault, RemoveOnCompletion: true})
go trackSomething(pw, &Tracker{Message: "Downloading File\t# 2", Total: 1000, Units: UnitsBytes, RemoveOnCompletion: true})
go trackSomething(pw, &Tracker{Message: "Calculating Total # 1", Total: 1000, Units: UnitsDefault, RemoveOnCompletion: true})
go trackSomething(pw, &Tracker{Message: "Downloading File # 2", Total: 1000, Units: UnitsBytes, RemoveOnCompletion: true})
go trackSomething(pw, &Tracker{Message: "Transferring Amount # 3", Total: 1000, Units: UnitsCurrencyDollar, RemoveOnCompletion: true})
renderAndWait(pw, false)
out := renderOutput.String()
Expand Down

0 comments on commit 94eef78

Please sign in to comment.