Merge pull request #4904 from MichaelEischer/fix-status-cleanup

ui/termstatus: fix clearing status lines
This commit is contained in:
Michael Eischer 2024-07-08 19:31:55 +02:00 committed by GitHub
commit 24a7ff45f2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
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