From 8c5f2aa275eae7938d898cde4a33bb58a4fa7849 Mon Sep 17 00:00:00 2001 From: Domantas Giedraitis <32360417+Navusas@users.noreply.github.com> Date: Fri, 22 Apr 2022 03:19:00 +0100 Subject: [PATCH] Do not show colors in Windows CMD & Powershell (#138) --- spinner.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/spinner.go b/spinner.go index 57ff8b3..63b655e 100644 --- a/spinner.go +++ b/spinner.go @@ -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{ @@ -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() @@ -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 {