fatih / color

Color package for Go (golang)
https://pkg.go.dev/github.com/fatih/color
MIT License
7.24k stars 615 forks source link

colorString() not working on Windows cmd.exe #91

Closed SebastienBoisard closed 6 years ago

SebastienBoisard commented 6 years ago

Hi @fatih

Thanks a lot for your color package. It works great on Linux, but there's a problem under Windows.

package main

import (
       "github.com/fatih/color"
       "fmt"
)

func main() {

    color.Red("1. We have red")

    fmt.Println(color.RedString("2. We have red"))
}

The first line is printed in red, but not the second one:

fatih_color_error

I'm using the default shell (c:\Windows\system32\cmd.exe) on Windows 7.

fatih commented 6 years ago

cc @mattn

mattn commented 6 years ago

cmd.exe does not handle escape sequence in default. Please use Output.

package main

import (
       "github.com/fatih/color"
       "fmt"
)

func main() {

    color.Red("1. We have red")

    fmt.Fprintln(color.Output, color.RedString("2. We have red"))
}
SebastienBoisard commented 6 years ago

Great, it works fine. Thanks @mattn !