diff --git a/cmd/restic/global.go b/cmd/restic/global.go index e5aa4e2b2..df9461272 100644 --- a/cmd/restic/global.go +++ b/cmd/restic/global.go @@ -8,7 +8,6 @@ import ( "os" "os/exec" "path/filepath" - "runtime" "strconv" "strings" "time" @@ -197,24 +196,6 @@ func collectBackends() *location.Registry { return backends } -// ClearLine creates a platform dependent string to clear the current -// line, so it can be overwritten. -// -// w should be the terminal width, or 0 to let clearLine figure it out. -func clearLine(w int) string { - if runtime.GOOS != "windows" { - return "\x1b[2K" - } - - // ANSI sequences are not supported on Windows cmd shell. - if w <= 0 { - if w = terminal.StdoutWidth(); w <= 0 { - return "" - } - } - return strings.Repeat(" ", w-1) + "\r" -} - // Printf writes the message to the configured stdout stream. func Printf(format string, args ...interface{}) { _, err := fmt.Fprintf(globalOptions.stdout, format, args...) diff --git a/cmd/restic/progress.go b/cmd/restic/progress.go index b0d80a896..b2abd61d2 100644 --- a/cmd/restic/progress.go +++ b/cmd/restic/progress.go @@ -68,7 +68,6 @@ func newProgressMax(show bool, max uint64, description string) *progress.Counter } func printProgress(status string, final bool) { - canUpdateStatus := terminal.StdoutCanUpdateStatus() w := terminal.StdoutWidth() @@ -83,12 +82,7 @@ func printProgress(status string, final bool) { } } - var carriageControl, cl string - - if canUpdateStatus { - cl = clearLine(w) - } - + var carriageControl string if !(strings.HasSuffix(status, "\r") || strings.HasSuffix(status, "\n")) { if canUpdateStatus { carriageControl = "\r" @@ -97,7 +91,12 @@ func printProgress(status string, final bool) { } } - _, _ = os.Stdout.Write([]byte(cl + status + carriageControl)) + if canUpdateStatus { + clearCurrentLine := terminal.ClearCurrentLine(os.Stdout.Fd()) + clearCurrentLine(os.Stdout, os.Stdout.Fd()) + } + + _, _ = os.Stdout.Write([]byte(status + carriageControl)) if final { _, _ = os.Stdout.Write([]byte("\n")) }