Skip to content

Commit

Permalink
windows: enable virtual terminal processing, fixes fatih#169
Browse files Browse the repository at this point in the history
  • Loading branch information
martinlindhe committed Mar 1, 2023
1 parent 3d5097c commit 2f1c461
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
17 changes: 17 additions & 0 deletions color_windows.go
@@ -0,0 +1,17 @@
package color

import (
"os"

"golang.org/x/sys/windows"
)

func init() {
// Opt-in for ansi color support for current process.
// https://learn.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences#output-sequences
var outMode uint32
out := windows.Handle(os.Stdout.Fd())
if err := windows.GetConsoleMode(out, &outMode); err == nil {
_ = windows.SetConsoleMode(out, outMode|windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING)
}
}
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -7,4 +7,4 @@ require (
github.com/mattn/go-isatty v0.0.17
)

require golang.org/x/sys v0.3.0 // indirect
require golang.org/x/sys v0.5.0
4 changes: 2 additions & 2 deletions go.sum
Expand Up @@ -4,5 +4,5 @@ github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

0 comments on commit 2f1c461

Please sign in to comment.