-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
color_windows.go
40 lines (38 loc) · 868 Bytes
/
color_windows.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package color
import (
"os"
"runtime"
"syscall"
)
func init() {
if runtime.GOOS == "windows" {
// Try to make ANSI work
handle := syscall.Handle(os.Stdout.Fd())
kernel32DLL := syscall.NewLazyDLL("kernel32.dll")
setConsoleModeProc := kernel32DLL.NewProc("SetConsoleMode")
// If it fails, fallback to no colors
if _, _, err := setConsoleModeProc.Call(uintptr(handle), 0x0001|0x0002|0x0004); err != nil && err.Error() != "The operation completed successfully." {
Reset = ""
Bold = ""
Underline = ""
Black = ""
Red = ""
Green = ""
Yellow = ""
Blue = ""
Purple = ""
Cyan = ""
Gray = ""
White = ""
BlackBackground = ""
RedBackground = ""
GreenBackground = ""
YellowBackground = ""
BlueBackground = ""
PurpleBackground = ""
CyanBackground = ""
GrayBackground = ""
WhiteBackground = ""
}
}
}