Skip to content

Commit

Permalink
Improve support for Windows platforms
Browse files Browse the repository at this point in the history
This enables ANSI support on older Windows versions and ensures correct
rendering when using the classic command prompt.
  • Loading branch information
muesli committed Oct 25, 2020
1 parent 0f54e4d commit 71b3e45
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions 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()
}

0 comments on commit 71b3e45

Please sign in to comment.