mirror of
https://github.com/charmbracelet/glow
synced 2024-11-10 06:04:18 +00:00
Enable ANSI for Windows consoles
This commit is contained in:
parent
225f822a36
commit
a358e8ceca
2 changed files with 24 additions and 0 deletions
23
console_windows.go
Normal file
23
console_windows.go
Normal file
|
@ -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()
|
||||
}
|
1
go.mod
1
go.mod
|
@ -8,4 +8,5 @@ require (
|
|||
github.com/mattn/go-isatty v0.0.4
|
||||
github.com/spf13/cobra v0.0.5
|
||||
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 // indirect
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue