diff --git a/cmd/restic/progress.go b/cmd/restic/progress.go index 8b33f94c9..9d93863ad 100644 --- a/cmd/restic/progress.go +++ b/cmd/restic/progress.go @@ -30,7 +30,7 @@ func calculateProgressInterval(show bool, json bool) time.Duration { } // newTerminalProgressMax returns a progress.Counter that prints to stdout or terminal if provided. -func newGenericProgressMax(show bool, max uint64, description string, print func(status string)) *progress.Counter { +func newGenericProgressMax(show bool, max uint64, description string, print func(status string, final bool)) *progress.Counter { if !show { return nil } @@ -46,16 +46,18 @@ func newGenericProgressMax(show bool, max uint64, description string, print func ui.FormatDuration(d), ui.FormatPercent(v, max), v, max, description) } - print(status) - if final { - fmt.Print("\n") - } + print(status, final) }) } func newTerminalProgressMax(show bool, max uint64, description string, term *termstatus.Terminal) *progress.Counter { - return newGenericProgressMax(show, max, description, func(status string) { - term.SetStatus([]string{status}) + return newGenericProgressMax(show, max, description, func(status string, final bool) { + if final { + term.SetStatus([]string{}) + term.Print(status) + } else { + term.SetStatus([]string{status}) + } }) } @@ -64,7 +66,7 @@ func newProgressMax(show bool, max uint64, description string) *progress.Counter return newGenericProgressMax(show, max, description, printProgress) } -func printProgress(status string) { +func printProgress(status string, final bool) { canUpdateStatus := stdoutCanUpdateStatus() @@ -95,6 +97,9 @@ func printProgress(status string) { } _, _ = os.Stdout.Write([]byte(clear + status + carriageControl)) + if final { + _, _ = os.Stdout.Write([]byte("\n")) + } } func newIndexProgress(quiet bool, json bool) *progress.Counter {