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

lib/terminal: enable windows console virtual terminal sequences processing (ANSI/VT100 colors)

albertonyf9d50f677d61
diff --git a/cmd/cmd.go b/cmd/cmd.go
index f6365cee8..73fe98a2d 100644
--- a/cmd/cmd.go
+++ b/cmd/cmd.go
@@ -401,9 +401,15 @@ func initConfig() {
// Start accounting
accounting.Start(ctx)
- // Hide console window
+ // Configure console
if ci.NoConsole {
+ // Hide the console window
terminal.HideConsole()
+ } else {
+ // Enable color support on stdout if possible.
+ // This enables virtual terminal processing on Windows 10,
+ // adding native support for ANSI/VT100 escape sequences.
+ terminal.EnableColorsStdout()
}
// Load filters
diff --git a/lib/terminal/terminal.go b/lib/terminal/terminal.go
index 532cf1fcc..f933de719 100644
--- a/lib/terminal/terminal.go
+++ b/lib/terminal/terminal.go
@@ -111,3 +111,14 @@ func Write(out []byte) {
Start()
_, _ = Out.Write(out)
}
+
+// EnableColorsStdout enable colors if possible.
+// This enables virtual terminal processing on Windows 10 console,
+// adding native support for VT100 escape codes. When this terminal
+// package is used for output, the result is that the colorable library
+// don't have to decode the escapes and explicitely write text with color
+// formatting to the console using Windows API functions, but can simply
+// relay everything to stdout.
+func EnableColorsStdout() {
+ _ = colorable.EnableColorsStdout(nil)
+}