Skip to content

Commit aa9a71f

Browse files
committed
run finalization synchronously
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent ac211e6 commit aa9a71f

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

cmd/display/tty.go

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,6 @@ func (w *ttyWriter) Start(ctx context.Context, operation string) {
9393
w.ticker.Stop()
9494
return
9595
case <-w.done:
96-
w.print()
97-
w.mtx.Lock()
98-
w.ticker.Stop()
99-
w.operation = ""
100-
w.mtx.Unlock()
10196
return
10297
case <-w.ticker.C:
10398
w.print()
@@ -107,6 +102,11 @@ func (w *ttyWriter) Start(ctx context.Context, operation string) {
107102
}
108103

109104
func (w *ttyWriter) Done(operation string, success bool) {
105+
w.print()
106+
w.mtx.Lock()
107+
defer w.mtx.Unlock()
108+
w.ticker.Stop()
109+
w.operation = ""
110110
w.done <- true
111111
}
112112

@@ -213,18 +213,17 @@ func (w *ttyWriter) print() {
213213
return
214214
}
215215
terminalWidth := goterm.Width()
216-
b := aec.EmptyBuilder
217-
for i := 0; i <= w.numLines; i++ {
218-
b = b.Up(1)
219-
}
216+
up := w.numLines + 1
220217
if !w.repeated {
221-
b = b.Down(1)
218+
up--
219+
w.repeated = true
222220
}
223-
w.repeated = true
224-
_, _ = fmt.Fprint(w.out, b.Column(0).ANSI)
225-
226-
// Hide the cursor while we are printing
227-
_, _ = fmt.Fprint(w.out, aec.Hide)
221+
b := aec.NewBuilder(
222+
aec.Hide, // Hide the cursor while we are printing
223+
aec.Up(uint(up)),
224+
aec.Column(0),
225+
)
226+
_, _ = fmt.Fprint(w.out, b.ANSI)
228227
defer func() {
229228
_, _ = fmt.Fprint(w.out, aec.Show)
230229
}()

0 commit comments

Comments
 (0)