github.com/secure-build/gitlab-runner@v12.5.0+incompatible/helpers/cli/init_cli_windows.go (about) 1 package cli_helpers 2 3 import ( 4 "github.com/sirupsen/logrus" 5 "golang.org/x/sys/windows" 6 ) 7 8 // InitCli initializes the Windows console window by activating virtual terminal features. 9 // Calling this function enables colored terminal output. 10 func InitCli() { 11 setConsoleMode(windows.Stdout, windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING) // enable VT processing on standard output stream 12 setConsoleMode(windows.Stderr, windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING) // enable VT processing on standard error stream 13 } 14 15 // setConsoleMode sets the given flags on the given 16 // console standard stream. 17 func setConsoleMode(handle windows.Handle, flags uint32) { 18 var mode uint32 19 20 // add console mode flag 21 if err := windows.GetConsoleMode(handle, &mode); err == nil { 22 err := windows.SetConsoleMode(handle, mode|flags) 23 if err != nil { 24 logrus.WithError(err).Info("Failed to set console mode for cli") 25 } 26 } 27 }