Skip to content

Commit 02ab2ea

Browse files
committed
windows: enable virtual terminal processing, fixes #169
1 parent 3d5097c commit 02ab2ea

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

color_windows.go

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package color
2+
3+
import (
4+
"os"
5+
6+
"golang.org/x/sys/windows"
7+
)
8+
9+
func init() {
10+
// Opt-in for ansi color support for current process.
11+
// https://learn.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences#output-sequences
12+
var outMode uint32
13+
out := windows.Handle(os.Stdout.Fd())
14+
if err := windows.GetConsoleMode(out, &outMode); err == nil {
15+
outMode |= windows.ENABLE_PROCESSED_OUTPUT | windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING
16+
_ = windows.SetConsoleMode(out, outMode)
17+
}
18+
}

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ require (
77
github.com/mattn/go-isatty v0.0.17
88
)
99

10-
require golang.org/x/sys v0.3.0 // indirect
10+
require golang.org/x/sys v0.5.0

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/
44
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
55
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
66
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
7-
golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=
8-
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
7+
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
8+
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

0 commit comments

Comments
 (0)