...
1
2
3
4 package text
5
6 import (
7 "os"
8 "sync"
9
10 "golang.org/x/sys/windows"
11 )
12
13 var (
14 enableVTPMutex = sync.Mutex{}
15 )
16
17 func areANSICodesSupported() bool {
18 enableVTPMutex.Lock()
19 defer enableVTPMutex.Unlock()
20
21 outHandle := windows.Handle(os.Stdout.Fd())
22 var outMode uint32
23 if err := windows.GetConsoleMode(outHandle, &outMode); err == nil {
24 if outMode&windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING != 0 {
25 return true
26 }
27 if err := windows.SetConsoleMode(outHandle, outMode|windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING); err == nil {
28 return true
29 }
30 }
31 return false
32 }
33
View as plain text