From 8ed7bb7717eae5ea39233aa18d4c1cc70249ff13 Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Mon, 12 Oct 2020 23:57:08 -0400 Subject: [PATCH] Restore ANSI support to non-TUI Glow on Windows --- console_windows.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 console_windows.go 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() +}