ui/termstatus: fix clearing status lines

To clear the status lines, they should be set to an empty array to
prevent future updates of those lines. Setting the status lines to an
array containing an empty string is wrong as this causes the output to
continuously add that empty status line after each message.
This commit is contained in:
Michael Eischer 2024-07-06 11:27:35 +02:00
parent 8e27a934de
commit aedead2823
5 changed files with 13 additions and 7 deletions

View file

@ -53,7 +53,7 @@ func newGenericProgressMax(show bool, max uint64, description string, print func
func newTerminalProgressMax(show bool, max uint64, description string, term *termstatus.Terminal) *progress.Counter {
return newGenericProgressMax(show, max, description, func(status string, final bool) {
if final {
term.SetStatus([]string{})
term.SetStatus(nil)
term.Print(status)
} else {
term.SetStatus([]string{status})

View file

@ -121,7 +121,7 @@ func (b *TextProgress) ReportTotal(start time.Time, s archiver.ScanStats) {
// Reset status
func (b *TextProgress) Reset() {
if b.term.CanUpdateStatus() {
b.term.SetStatus([]string{""})
b.term.SetStatus(nil)
}
}

View file

@ -62,7 +62,7 @@ func (t *textPrinter) CompleteItem(messageType ItemAction, item string, size uin
}
func (t *textPrinter) Finish(p State, duration time.Duration) {
t.terminal.SetStatus([]string{})
t.terminal.SetStatus(nil)
timeLeft := ui.FormatDuration(duration)
formattedAllBytesTotal := ui.FormatBytes(p.AllBytesTotal)

View file

@ -315,11 +315,8 @@ func sanitizeLines(lines []string, width int) []string {
// SetStatus updates the status lines.
// The lines should not contain newlines; this method adds them.
// Pass nil or an empty array to remove the status lines.
func (t *Terminal) SetStatus(lines []string) {
if len(lines) == 0 {
return
}
// only truncate interactive status output
var width int
if t.canUpdateStatus {

View file

@ -32,6 +32,15 @@ func TestSetStatus(t *testing.T) {
term.SetStatus([]string{"first"})
exp := home + clear + "first" + home
term.SetStatus([]string{""})
exp += home + clear + "" + home
term.SetStatus([]string{})
exp += home + clear + "" + home
// already empty status
term.SetStatus([]string{})
term.SetStatus([]string{"foo", "bar", "baz"})
exp += home + clear + "foo\n" + home + clear + "bar\n" +
home + clear + "baz" + home + up + up