summaryrefslogtreecommitdiffstats
path: root/console_windows.go
diff options
context:
space:
mode:
authorChristian Muehlhaeuser <muesli@gmail.com>2020-01-09 11:31:13 +0100
committerChristian Muehlhaeuser <muesli@gmail.com>2020-01-09 11:38:09 +0100
commita358e8ceca66705b362dbd0e7a2eaf9b1d4df21d (patch)
tree546382373d7a35289f819ee1113ec8e40ed10459 /console_windows.go
parent225f822a36e31dbdabbc4548fc78fe216cb1184a (diff)
Enable ANSI for Windows consoles
Diffstat (limited to 'console_windows.go')
-rw-r--r--console_windows.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/console_windows.go b/console_windows.go
new file mode 100644
index 0000000..2516b16
--- /dev/null
+++ b/console_windows.go
@@ -0,0 +1,23 @@
+// +build windows
+
+package main
+
+import (
+ "os"
+
+ "golang.org/x/sys/windows"
+)
+
+// enableAnsiColors enables support for ANSI color sequences in Windows
+// default console. Note that this only works with Windows 10.
+func enableAnsiColors() {
+ stdout := windows.Handle(os.Stdout.Fd())
+ var originalMode uint32
+
+ windows.GetConsoleMode(stdout, &originalMode)
+ windows.SetConsoleMode(stdout, originalMode|windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING)
+}
+
+func init() {
+ enableAnsiColors()
+}