2

I have a simple go code that added chars to logger for adding color to logs.

package main

import "fmt"

var (
    Info = Teal
    Warn = Yellow
    Fata = Red
)

var (
    Black   = Color("\033[1;30m%s\033[0m")
    Red     = Color("\033[1;31m%s\033[0m")
    Green   = Color("\033[1;32m%s\033[0m")
    Yellow  = Color("\033[1;33m%s\033[0m")
    Purple  = Color("\033[1;34m%s\033[0m")
    Magenta = Color("\033[1;35m%s\033[0m")
    Teal    = Color("\033[1;36m%s\033[0m")
    White   = Color("\033[1;37m%s\033[0m")
)

func Color(colorString string) func(...interface{}) string {
    sprint := func(args ...interface{}) string {
        return fmt.Sprintf(colorString,
            fmt.Sprint(args...))
    }
    return sprint
}

func main() {
    fmt.Println(Magenta("hello, world!"))
}

when I run it in the PowerShell that run in my vscode, I see the colors as expected: enter image description here when I run it in the PowerShell of windows, I don't see that the colors are parsed well: enter image description here

both of the PowerShells above have the same version. enter image description here

any idea why?

mklement0
  • 382,024
  • 64
  • 607
  • 775
  • 1
    In short: Windows Terminal and Visual Studio Code's integrated terminal have _unconditional_ support for ANSI / VT escape sequences. By contrast, in regular console windows (`conhost.exe`), support is _off by default_ (although individual applications may enable it _for themselves_), but can be enabled globally by setting the `VirtualTerminalLevel` value of key `HKEY_CURRENT_USER\Console` to `1` (`Set-ItemProperty HKCU:\Console VirtualTerminalLevel -Type DWORD 1`; start a new session afterwards.) See the linked duplicate for details. – mklement0 Mar 12 '23 at 13:25

0 Answers0