Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit af62c52

Browse files
authored
Merge pull request #1230 from gtardif/fix_progress_time_display
Avoid negative elapsed the display when only one event is sent.
2 parents 09f9a11 + f0dbc60 commit af62c52

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

api/progress/tty.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,10 @@ func (w *ttyWriter) print() {
154154
func lineText(event Event, pad string, terminalWidth, statusPadding int, color bool) string {
155155
endTime := time.Now()
156156
if event.Status != Working {
157-
endTime = event.endTime
157+
endTime = event.startTime
158+
if (event.endTime != time.Time{}) {
159+
endTime = event.endTime
160+
}
158161
}
159162

160163
elapsed := endTime.Sub(event.startTime).Seconds()

api/progress/tty_test.go

+19
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,25 @@ func TestLineText(t *testing.T) {
5656
assert.Equal(t, out, "\x1b[31m . id Text Status 0.0s\n\x1b[0m")
5757
}
5858

59+
func TestLineTextSingleEvent(t *testing.T) {
60+
now := time.Now()
61+
ev := Event{
62+
ID: "id",
63+
Text: "Text",
64+
Status: Done,
65+
StatusText: "Status",
66+
startTime: now,
67+
spinner: &spinner{
68+
chars: []string{"."},
69+
},
70+
}
71+
72+
lineWidth := len(fmt.Sprintf("%s %s", ev.ID, ev.Text))
73+
74+
out := lineText(ev, "", 50, lineWidth, true)
75+
assert.Equal(t, out, "\x1b[34m . id Text Status 0.0s\n\x1b[0m")
76+
}
77+
5978
func TestErrorEvent(t *testing.T) {
6079
w := &ttyWriter{
6180
events: map[string]Event{},

0 commit comments

Comments
 (0)