forked from TrueCloudLab/restic
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:
parent
8e27a934de
commit
aedead2823
5 changed files with 13 additions and 7 deletions
|
@ -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 {
|
func newTerminalProgressMax(show bool, max uint64, description string, term *termstatus.Terminal) *progress.Counter {
|
||||||
return newGenericProgressMax(show, max, description, func(status string, final bool) {
|
return newGenericProgressMax(show, max, description, func(status string, final bool) {
|
||||||
if final {
|
if final {
|
||||||
term.SetStatus([]string{})
|
term.SetStatus(nil)
|
||||||
term.Print(status)
|
term.Print(status)
|
||||||
} else {
|
} else {
|
||||||
term.SetStatus([]string{status})
|
term.SetStatus([]string{status})
|
||||||
|
|
|
@ -121,7 +121,7 @@ func (b *TextProgress) ReportTotal(start time.Time, s archiver.ScanStats) {
|
||||||
// Reset status
|
// Reset status
|
||||||
func (b *TextProgress) Reset() {
|
func (b *TextProgress) Reset() {
|
||||||
if b.term.CanUpdateStatus() {
|
if b.term.CanUpdateStatus() {
|
||||||
b.term.SetStatus([]string{""})
|
b.term.SetStatus(nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,7 @@ func (t *textPrinter) CompleteItem(messageType ItemAction, item string, size uin
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *textPrinter) Finish(p State, duration time.Duration) {
|
func (t *textPrinter) Finish(p State, duration time.Duration) {
|
||||||
t.terminal.SetStatus([]string{})
|
t.terminal.SetStatus(nil)
|
||||||
|
|
||||||
timeLeft := ui.FormatDuration(duration)
|
timeLeft := ui.FormatDuration(duration)
|
||||||
formattedAllBytesTotal := ui.FormatBytes(p.AllBytesTotal)
|
formattedAllBytesTotal := ui.FormatBytes(p.AllBytesTotal)
|
||||||
|
|
|
@ -315,11 +315,8 @@ func sanitizeLines(lines []string, width int) []string {
|
||||||
|
|
||||||
// SetStatus updates the status lines.
|
// SetStatus updates the status lines.
|
||||||
// The lines should not contain newlines; this method adds them.
|
// 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) {
|
func (t *Terminal) SetStatus(lines []string) {
|
||||||
if len(lines) == 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// only truncate interactive status output
|
// only truncate interactive status output
|
||||||
var width int
|
var width int
|
||||||
if t.canUpdateStatus {
|
if t.canUpdateStatus {
|
||||||
|
|
|
@ -32,6 +32,15 @@ func TestSetStatus(t *testing.T) {
|
||||||
term.SetStatus([]string{"first"})
|
term.SetStatus([]string{"first"})
|
||||||
exp := home + clear + "first" + home
|
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"})
|
term.SetStatus([]string{"foo", "bar", "baz"})
|
||||||
exp += home + clear + "foo\n" + home + clear + "bar\n" +
|
exp += home + clear + "foo\n" + home + clear + "bar\n" +
|
||||||
home + clear + "baz" + home + up + up
|
home + clear + "baz" + home + up + up
|
||||||
|
|
Loading…
Reference in a new issue