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:
Jan Stürtz
2016-08-21 22:38:22 +02:00
parent 1c703e4161
commit 08eb5b42eb
5 changed files with 19 additions and 8 deletions
+11
View File
@@ -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...)