mirror of
https://github.com/restic/restic.git
synced 2026-09-28 23:10:31 +00:00
Fix progress output on Windows
The windows cmd shell is not aware of ANSI escape sequences and does print them uninterpreted to the console. This is ugly. Added a function to generate platform specific string for the escape sequence. On Windows this will be 79 white spaces with a trailing \r.
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
@@ -82,6 +83,16 @@ func restoreTerminal() {
|
||||
var globalOpts = GlobalOptions{stdout: os.Stdout, stderr: os.Stderr}
|
||||
var parser = flags.NewParser(&globalOpts, flags.HelpFlag|flags.PassDoubleDash)
|
||||
|
||||
// Clear Line ASCII sequence is invalid on Windows so ignore it here
|
||||
func ClearLine() string {
|
||||
if runtime.GOOS == "windows" {
|
||||
// Ugly Workaround, write 79 Whitespaces and return
|
||||
return " \r"
|
||||
} else {
|
||||
return "\x1b[2K"
|
||||
}
|
||||
}
|
||||
|
||||
// Printf writes the message to the configured stdout stream.
|
||||
func (o GlobalOptions) Printf(format string, args ...interface{}) {
|
||||
_, err := fmt.Fprintf(o.stdout, format, args...)
|
||||
|
||||
Reference in New Issue
Block a user