run finalization synchronously

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof
2025-12-10 14:24:00 +01:00
committed by Nicolas De loof
parent ac211e6e51
commit aa9a71f37a

View File

@@ -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)
}()