Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

cmd: Make --progress work on Windows

Nick Craig-Wood1cccfa7331eb
diff --git a/cmd/progress.go b/cmd/progress.go
index 5aa43fc7d..a76acf882 100644
--- a/cmd/progress.go
+++ b/cmd/progress.go
@@ -114,5 +114,5 @@ func printProgress(logMessage string) {
out("\n")
}
}
- os.Stdout.Write(buf.Bytes())
+ writeToTerminal(buf.Bytes())
}
diff --git a/cmd/progress_other.go b/cmd/progress_other.go
new file mode 100644
index 000000000..aef00cd4b
--- /dev/null
+++ b/cmd/progress_other.go
@@ -0,0 +1,9 @@
+//+build !windows
+
+package cmd
+
+import "os"
+
+func writeToTerminal(b []byte) {
+ _, _ = os.Stdout.Write(b)
+}
diff --git a/cmd/progress_windows.go b/cmd/progress_windows.go
new file mode 100644
index 000000000..aa7493b8f
--- /dev/null
+++ b/cmd/progress_windows.go
@@ -0,0 +1,28 @@
+//+build windows
+
+package cmd
+
+import (
+ "fmt"
+ "os"
+ "sync"
+
+ ansiterm "github.com/Azure/go-ansiterm"
+ "github.com/Azure/go-ansiterm/winterm"
+)
+
+var (
+ initAnsiParser sync.Once
+ ansiParser *ansiterm.AnsiParser
+)
+
+func writeToTerminal(b []byte) {
+ initAnsiParser.Do(func() {
+ winEventHandler := winterm.CreateWinEventHandler(os.Stdout.Fd(), os.Stdout)
+ ansiParser = ansiterm.CreateParser("Ground", winEventHandler)
+ })
+ _, err := ansiParser.Parse(b)
+ if err != nil {
+ _, _ = fmt.Fprintf(os.Stderr, "\n*** Error from ANSI parser: %v\n", err)
+ }
+}