Просмотр исходного кода

run finalization synchronously

Signed-off-by: Nicolas De Loof <[email protected]>
Nicolas De Loof 2 недель назад
Родитель
Сommit
aa9a71f37a
1 измененных файлов с 14 добавлено и 15 удалено
  1. 14 15
      cmd/display/tty.go

+ 14 - 15
cmd/display/tty.go

@@ -93,11 +93,6 @@ func (w *ttyWriter) Start(ctx context.Context, operation string) {
 				w.ticker.Stop()
 				return
 			case <-w.done:
-				w.print()
-				w.mtx.Lock()
-				w.ticker.Stop()
-				w.operation = ""
-				w.mtx.Unlock()
 				return
 			case <-w.ticker.C:
 				w.print()
@@ -107,6 +102,11 @@ func (w *ttyWriter) Start(ctx context.Context, operation string) {
 }
 
 func (w *ttyWriter) Done(operation string, success bool) {
+	w.print()
+	w.mtx.Lock()
+	defer w.mtx.Unlock()
+	w.ticker.Stop()
+	w.operation = ""
 	w.done <- true
 }
 
@@ -213,18 +213,17 @@ func (w *ttyWriter) print() {
 		return
 	}
 	terminalWidth := goterm.Width()
-	b := aec.EmptyBuilder
-	for i := 0; i <= w.numLines; i++ {
-		b = b.Up(1)
-	}
+	up := w.numLines + 1
 	if !w.repeated {
-		b = b.Down(1)
+		up--
+		w.repeated = true
 	}
-	w.repeated = true
-	_, _ = fmt.Fprint(w.out, b.Column(0).ANSI)
-
-	// Hide the cursor while we are printing
-	_, _ = fmt.Fprint(w.out, aec.Hide)
+	b := aec.NewBuilder(
+		aec.Hide, // Hide the cursor while we are printing
+		aec.Up(uint(up)),
+		aec.Column(0),
+	)
+	_, _ = fmt.Fprint(w.out, b.ANSI)
 	defer func() {
 		_, _ = fmt.Fprint(w.out, aec.Show)
 	}()