Skip to content

Commit

Permalink
Do not show colors in Windows CMD & Powershell (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
Navusas authored Apr 22, 2022
1 parent 553002f commit 8c5f2aa
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions spinner.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ var validColors = map[string]bool{
}

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

// returns a valid color's foreground text color attribute
var colorAttributeMap = map[string]color.Attribute{
Expand Down Expand Up @@ -281,6 +282,12 @@ func (s *Spinner) Start() {
// hides the cursor
fmt.Fprint(s.Writer, "\033[?25l")
}
// Disable colors for simple Windows CMD or Powershell
// as they can not recognize them
if isWindows && !isWindowsTerminalOnWindows {
color.NoColor = true
}

s.active = true
s.mu.Unlock()

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

var outColor string
if runtime.GOOS == "windows" {
if isWindows {
if s.Writer == os.Stderr {
outColor = fmt.Sprintf("\r%s%s%s", s.Prefix, s.chars[i], s.Suffix)
} else {
Expand Down

0 comments on commit 8c5f2aa

Please sign in to comment.