forked from TrueCloudLab/restic
Merge pull request #4904 from MichaelEischer/fix-status-cleanup
ui/termstatus: fix clearing status lines
This commit is contained in:
commit
24a7ff45f2
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 {
|
||||
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})
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue