1
0
Fork 0
mirror of https://github.com/restic/restic.git synced 2024-12-23 08:16:36 +00:00

properly show termstatus progress bar if visible less than one frame

If a progress bar using termstatus was only visible for less than one
frame, then its output could be lost.
This commit is contained in:
Michael Eischer 2024-01-20 18:34:11 +01:00
parent 6b65a495b1
commit d7a50fe739

View file

@ -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. // 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 { if !show {
return nil 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) ui.FormatDuration(d), ui.FormatPercent(v, max), v, max, description)
} }
print(status) print(status, final)
if final {
fmt.Print("\n")
}
}) })
} }
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) { return newGenericProgressMax(show, max, description, func(status string, final bool) {
term.SetStatus([]string{status}) 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) return newGenericProgressMax(show, max, description, printProgress)
} }
func printProgress(status string) { func printProgress(status string, final bool) {
canUpdateStatus := stdoutCanUpdateStatus() canUpdateStatus := stdoutCanUpdateStatus()
@ -95,6 +97,9 @@ func printProgress(status string) {
} }
_, _ = os.Stdout.Write([]byte(clear + status + carriageControl)) _, _ = os.Stdout.Write([]byte(clear + status + carriageControl))
if final {
_, _ = os.Stdout.Write([]byte("\n"))
}
} }
func newIndexProgress(quiet bool, json bool) *progress.Counter { func newIndexProgress(quiet bool, json bool) *progress.Counter {