goext/termext/osutil_windows.go

27 lines
537 B
Go
Raw Permalink Normal View History

2022-10-27 16:48:26 +02:00
package termext
2022-10-29 15:34:40 +02:00
import "golang.org/x/sys/windows"
2022-10-27 16:48:26 +02:00
func enableColor() bool {
handle, err := windows.GetStdHandle(windows.STD_OUTPUT_HANDLE)
if err != nil {
return false
}
var mode uint32
err = windows.GetConsoleMode(handle, &mode)
if err != nil {
return false
}
if mode&windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING != windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING {
mode = mode | windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING
err = windows.SetConsoleMode(handle, mode)
if err != nil {
return false
}
}
return true
}