| 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 |
|
| 14 |
out := windows.Handle(os.Stdout.Fd()) |
| 15 |
if err := windows.GetConsoleMode(out, &outMode); err != nil { |
| 16 |
return |
| 17 |
} |
| 18 |
|
| 19 |
outMode |= windows.ENABLE_PROCESSED_OUTPUT | windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING |
| 20 |
_ = windows.SetConsoleMode(out, outMode) |
| 21 |
} |