mirror of
https://github.com/restic/restic.git
synced 2025-12-13 12:52:34 +00:00
use standard line clearing in printProgress
This commit is contained in:
@@ -8,7 +8,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -197,24 +196,6 @@ func collectBackends() *location.Registry {
|
|||||||
return backends
|
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.
|
// Printf writes the message to the configured stdout stream.
|
||||||
func Printf(format string, args ...interface{}) {
|
func Printf(format string, args ...interface{}) {
|
||||||
_, err := fmt.Fprintf(globalOptions.stdout, format, args...)
|
_, err := fmt.Fprintf(globalOptions.stdout, format, args...)
|
||||||
|
|||||||
@@ -68,7 +68,6 @@ func newProgressMax(show bool, max uint64, description string) *progress.Counter
|
|||||||
}
|
}
|
||||||
|
|
||||||
func printProgress(status string, final bool) {
|
func printProgress(status string, final bool) {
|
||||||
|
|
||||||
canUpdateStatus := terminal.StdoutCanUpdateStatus()
|
canUpdateStatus := terminal.StdoutCanUpdateStatus()
|
||||||
|
|
||||||
w := terminal.StdoutWidth()
|
w := terminal.StdoutWidth()
|
||||||
@@ -83,12 +82,7 @@ func printProgress(status string, final bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var carriageControl, cl string
|
var carriageControl string
|
||||||
|
|
||||||
if canUpdateStatus {
|
|
||||||
cl = clearLine(w)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !(strings.HasSuffix(status, "\r") || strings.HasSuffix(status, "\n")) {
|
if !(strings.HasSuffix(status, "\r") || strings.HasSuffix(status, "\n")) {
|
||||||
if canUpdateStatus {
|
if canUpdateStatus {
|
||||||
carriageControl = "\r"
|
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 {
|
if final {
|
||||||
_, _ = os.Stdout.Write([]byte("\n"))
|
_, _ = os.Stdout.Write([]byte("\n"))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user