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 return 16 } 17 outMode |= windows.ENABLE_PROCESSED_OUTPUT | windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING 18 _ = windows.SetConsoleMode(out, outMode) 19 } 20