Skip to content

Commit ea7e799

Browse files
authored
Do not show colors in Windows CMD & Powershell (#141)
1 parent f878506 commit ea7e799

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

spinner.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ var validColors = map[string]bool{
100100
}
101101

102102
// returns true if the OS is windows and the WT_SESSION env variable is set.
103-
var isWindowsTerminalOnWindows = len(os.Getenv("WT_SESSION")) > 0 && runtime.GOOS == "windows"
103+
var isWindows = runtime.GOOS == "windows"
104+
var isWindowsTerminalOnWindows = len(os.Getenv("WT_SESSION")) > 0 && isWindows
104105

105106
// returns a valid color's foreground text color attribute
106107
var colorAttributeMap = map[string]color.Attribute{
@@ -281,6 +282,12 @@ func (s *Spinner) Start() {
281282
// hides the cursor
282283
fmt.Fprint(s.Writer, "\033[?25l")
283284
}
285+
// Disable colors for simple Windows CMD or Powershell
286+
// as they can not recognize them
287+
if isWindows && !isWindowsTerminalOnWindows {
288+
color.NoColor = true
289+
}
290+
284291
s.active = true
285292
s.mu.Unlock()
286293

@@ -305,7 +312,7 @@ func (s *Spinner) Start() {
305312
}
306313

307314
var outColor string
308-
if runtime.GOOS == "windows" {
315+
if isWindows {
309316
if s.Writer == os.Stderr {
310317
outColor = fmt.Sprintf("\r%s%s%s", s.Prefix, s.chars[i], s.Suffix)
311318
} else {

0 commit comments

Comments
 (0)