From b52a8ff05c82e82914d931ae11d5909eb0712bf6 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Fri, 7 Oct 2022 20:40:39 +0200 Subject: [PATCH] ui: Properly clear lines no longer used for status Previously, the old status text remained until it was overwritten. --- internal/ui/termstatus/status.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/internal/ui/termstatus/status.go b/internal/ui/termstatus/status.go index 88c4f898e..fdc7e14f6 100644 --- a/internal/ui/termstatus/status.go +++ b/internal/ui/termstatus/status.go @@ -25,6 +25,7 @@ type Terminal struct { msg chan message status chan status canUpdateStatus bool + lastStatusLen int // will be closed when the goroutine which runs Run() terminates, so it'll // yield a default value immediately @@ -154,6 +155,18 @@ func (t *Terminal) run(ctx context.Context) { } func (t *Terminal) writeStatus(status []string) { + statusLen := len(status) + status = append([]string{}, status...) + for i := len(status); i < t.lastStatusLen; i++ { + // clear no longer used status lines + status = append(status, "") + if i > 0 { + // all lines except the last one must have a line break + status[i-1] = status[i-1] + "\n" + } + } + t.lastStatusLen = statusLen + for _, line := range status { t.clearCurrentLine(t.wr, t.fd)