Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
SebastienBoisard opened this issue Mar 13, 2018 · 3 comments
Closed

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

SebastienBoisard opened this issue Mar 13, 2018 · 3 comments

Comments

@SebastienBoisard
Copy link

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
Copy link
Owner

fatih commented Mar 13, 2018

cc @mattn

@mattn
Copy link
Contributor

mattn commented Mar 13, 2018

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
Copy link
Author

Great, it works fine.
Thanks @mattn !

@fatih fatih closed this as completed Mar 14, 2018
xenoscopic added a commit to mutagen-io/mutagen that referenced this issue Jul 12, 2018
Using the various colorized string methods on Windows yields strings
containing escape sequences that are not automatically handled by
cmd.exe. Instead, one needs to print to an alternative output stream.
This is described in fatih/color#91.
momiom added a commit to momiom/excelgrep that referenced this issue Sep 7, 2021
cmd.exe で ANSI エスケープシーケンスを扱えるように標準出力を color.Output に変更
参考: fatih/color#91
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants