Closed Integralist closed 2 years ago
Hi @Integralist
If you use color.Output
, it should work for both macOS and Windows:
fmt.Fprint(color.Output, Bold(s))
This makes sure to use the correct parser. You can also use the handy Printxxx
methods of the color instance you created, which use the correct stdout under the hood:
Bold.Print(s)
Thanks I'll take a look at this 👍🏻
@fatih Thanks for the feedback, this appears to work but I'm just noting for future travellers that I was initially still seeing an issue with escape codes being displayed rather than rendered.
For example, using your suggestion...
fmt.Fprint(color.Output, Bold(s))
This printed fine on macOS but on Windows, although the text was 'bolded' I was seeing it prefixed with ←[0m
...
Turns out this was because before that line I still had...
fmt.Fprint(os.Stdout, Bold(s))
And so I'm guessing that was not closing off the ANSI escape code properly. So doing the following would make Windows render correctly...
fmt.Fprint(os.Stdout, Bold(s))
fmt.Println("---")
fmt.Fprintf(color.Output, bold(s))
Oh! and for anyone using os.Stderr
, the equivalent to use is color.Error
.
👋🏻
I'm testing the following code:
On macOS the output is correctly bolded (as expected), while the output on Windows 10 cmd.exe displays:
I've noticed old issues like https://github.com/fatih/color/issues/91 where it mentions certain functions aren't supported by cmd.exe and so I'm not sure if there's a similar resolution here?
Any feedback/guidance appreciated.
Thanks.