Skip to content

Commit 603ab33

Browse files
bug: show success in the previous step instead of current (#508)
when we break the line for a new message we need to flag the previous as success and not the current one. this commit addresses it.
1 parent f1bd95b commit 603ab33

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

pkg/spinner/spinner.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ func (m *MessageWriter) loop() {
9696
var ticker = time.NewTicker(50 * time.Millisecond)
9797
var end bool
9898
for {
99+
previous := message
100+
99101
select {
100102
case msg, open := <-m.ch:
101103
if !open {
@@ -108,7 +110,7 @@ func (m *MessageWriter) loop() {
108110
}
109111

110112
var lbreak bool
111-
if m.lbreak != nil {
113+
if m.lbreak != nil && previous != message {
112114
lbreak = m.lbreak(message)
113115
}
114116

@@ -118,11 +120,10 @@ func (m *MessageWriter) loop() {
118120

119121
pos := counter % len(blocks)
120122
if !end {
121-
prefix, suffix := blocks[pos], ""
122123
if lbreak {
123-
prefix, suffix = "✔", "\n"
124+
m.printf("\033[K\r✔ %s\n", previous)
124125
}
125-
m.printf("\033[K\r%s %s %s", prefix, message, suffix)
126+
m.printf("\033[K\r%s %s", blocks[pos], message)
126127
continue
127128
}
128129

pkg/spinner/spinner_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,11 @@ func TestLineBreak(t *testing.T) {
123123
}
124124
pb.Close()
125125
// we expect the following output:
126-
// ✔ test 3 (\n)
127-
// ✔ test 8 (\n)
126+
// ✔ test 2 (\n)
127+
// ✔ test 7 (\n)
128128
// ✔ test 99 (\n)
129129
assert.Equal(t, strings.Count(buf.String(), "\n"), 3)
130-
assert.Contains(t, buf.String(), "test 3")
131-
assert.Contains(t, buf.String(), "test 8")
130+
assert.Contains(t, buf.String(), "test 2")
131+
assert.Contains(t, buf.String(), "test 7")
132132
assert.Contains(t, buf.String(), "test 99")
133133
}

0 commit comments

Comments
 (0)