Skip to content

Commit

Permalink
ui: Properly clear lines no longer used for status
Browse files Browse the repository at this point in the history
Previously, the old status text remained until it was overwritten.
  • Loading branch information
MichaelEischer committed Oct 7, 2022
1 parent 3fe1129 commit ac575af
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions internal/ui/termstatus/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit ac575af

Please sign in to comment.