1
1
//go:build windows
2
2
// +build windows
3
3
4
- // Display color on windows
4
+ // Display color on Windows
5
+ //
5
6
// refer:
6
- // golang.org/x/sys/windows
7
- // golang.org/x/crypto/ssh/terminal
8
- // https://docs.microsoft.com/en-us/windows/console
7
+ //
8
+ // golang.org/x/sys/windows
9
+ // golang.org/x/crypto/ssh/terminal
10
+ // https://docs.microsoft.com/en-us/windows/console
9
11
package color
10
12
11
13
import (
@@ -39,7 +41,7 @@ func init() {
39
41
return
40
42
}
41
43
42
- // if at windows 's ConEmu, Cmder, putty ... terminals not need VTP
44
+ // if at Windows 's ConEmu, Cmder, putty ... terminals not need VTP
43
45
44
46
// -------- try force enable colors on windows terminal -------
45
47
tryEnableVTP (needVTP )
@@ -48,7 +50,7 @@ func init() {
48
50
// err := getConsoleScreenBufferInfo(uintptr(syscall.Stdout), &defScreenInfo)
49
51
}
50
52
51
- // try force enable colors on windows terminal
53
+ // try force enable colors on Windows terminal
52
54
func tryEnableVTP (enable bool ) bool {
53
55
if ! enable {
54
56
return false
@@ -58,7 +60,7 @@ func tryEnableVTP(enable bool) bool {
58
60
59
61
initKernel32Proc ()
60
62
61
- // enable colors on windows terminal
63
+ // enable colors on Windows terminal
62
64
if tryEnableOnCONOUT () {
63
65
return true
64
66
}
@@ -71,7 +73,7 @@ func initKernel32Proc() {
71
73
return
72
74
}
73
75
74
- // load related windows dll
76
+ // load related Windows dll
75
77
// https://docs.microsoft.com/en-us/windows/console/setconsolemode
76
78
kernel32 = syscall .NewLazyDLL ("kernel32.dll" )
77
79
@@ -112,8 +114,10 @@ var (
112
114
)
113
115
114
116
// refer
115
- // https://github.com/Delta456/box-cli-maker/blob/7b5a1ad8a016ce181e7d8b05e24b54ff60b4b38a/detect_windows.go#L30-L57
116
- // https://github.com/gookit/color/issues/25#issuecomment-738727917
117
+ //
118
+ // https://github.com/Delta456/box-cli-maker/blob/7b5a1ad8a016ce181e7d8b05e24b54ff60b4b38a/detect_windows.go#L30-L57
119
+ // https://github.com/gookit/color/issues/25#issuecomment-738727917
120
+ //
117
121
// detects the color level supported on Windows: cmd, powerShell
118
122
func detectSpecialTermColor (termVal string ) (tl Level , needVTP bool ) {
119
123
if os .Getenv ("ConEmuANSI" ) == "ON" {
@@ -131,7 +135,7 @@ func detectSpecialTermColor(termVal string) (tl Level, needVTP bool) {
131
135
// Detect if using ANSICON on older systems
132
136
if os .Getenv ("ANSICON" ) != "" {
133
137
conVersion := os .Getenv ("ANSICON_VER" )
134
- // 8 bit Colors were only supported after v1.81 release
138
+ // 8- bit Colors were only supported after v1.81 release
135
139
if conVersion >= "181" {
136
140
return terminfo .ColorLevelHundreds , false
137
141
}
@@ -141,7 +145,7 @@ func detectSpecialTermColor(termVal string) (tl Level, needVTP bool) {
141
145
return terminfo .ColorLevelNone , false
142
146
}
143
147
144
- // True Color is not available before build 14931 so fallback to 8 bit color.
148
+ // True Color is not available before build 14931 so fallback to 8- bit color.
145
149
if buildNumber < 14931 {
146
150
return terminfo .ColorLevelHundreds , true
147
151
}
@@ -152,7 +156,7 @@ func detectSpecialTermColor(termVal string) (tl Level, needVTP bool) {
152
156
}
153
157
154
158
/*************************************************************
155
- * render full color code on windows (8,16,24bit color)
159
+ * render full color code on Windows (8,16,24bit color)
156
160
*************************************************************/
157
161
158
162
// docs https://docs.microsoft.com/zh-cn/windows/console/getconsolemode#parameters
@@ -167,9 +171,10 @@ const (
167
171
// doc https://docs.microsoft.com/zh-cn/windows/console/console-virtual-terminal-sequences#samples
168
172
//
169
173
// Usage:
170
- // err := EnableVirtualTerminalProcessing(syscall.Stdout, true)
171
- // // support print color text
172
- // err = EnableVirtualTerminalProcessing(syscall.Stdout, false)
174
+ //
175
+ // err := EnableVirtualTerminalProcessing(syscall.Stdout, true)
176
+ // // support print color text
177
+ // err = EnableVirtualTerminalProcessing(syscall.Stdout, false)
173
178
func EnableVirtualTerminalProcessing (stream syscall.Handle , enable bool ) error {
174
179
var mode uint32
175
180
// Check if it is currently in the terminal
@@ -217,7 +222,7 @@ func EnableVirtualTerminalProcessing(stream syscall.Handle, enable bool) error {
217
222
// }
218
223
219
224
/*************************************************************
220
- * render simple color code on windows
225
+ * render simple color code on Windows
221
226
*************************************************************/
222
227
223
228
// IsTty returns true if the given file descriptor is a terminal.
@@ -232,9 +237,10 @@ func IsTty(fd uintptr) bool {
232
237
// IsTerminal returns true if the given file descriptor is a terminal.
233
238
//
234
239
// Usage:
235
- // fd := os.Stdout.Fd()
236
- // fd := uintptr(syscall.Stdout) // for windows
237
- // IsTerminal(fd)
240
+ //
241
+ // fd := os.Stdout.Fd()
242
+ // fd := uintptr(syscall.Stdout) // for Windows
243
+ // IsTerminal(fd)
238
244
func IsTerminal (fd uintptr ) bool {
239
245
initKernel32Proc ()
240
246
0 commit comments