-
Notifications
You must be signed in to change notification settings - Fork 561
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
Windows color #153
Comments
I have no Windows experience. If you can help fixing this old issue, you are welcome. |
Windows uses different escape sequences than every other OS. I use this: https://github.com/mattn/go-colorable Go-colorable shims os.Stdout and fixes the escape sequences on Windows. Their example is for logrus, but it works for any library that prints colored output. I use it with zerolog ConsoleWriter like this:
Just my $.02, but given that we have go-colorable, I don't think this should be "fixed" in every library that prints colored output. Maybe we can link to go-colorable in the zerolog docs and mark this as closed with the solution being to use go-colorable if you need colored Windows output. It's a Windows-specific problem, and Microsoft has started moving in the direction of conforming to the standard. As of recent patches, I think ANSI sequences are available. I'm not a Windows user, but it looks like they're now supported but just not the default: https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences There was a good MS blog announcement on this, but I can't seem to find it right now. |
@brightpuddle Windows 7 still has 38% market share by some measurements: https://netmarketshare.com/operating-system-market-share.aspx?id=platformsDesktopVersions thats more than Windows 8, all Mac and Linux combined. If you want to hand package main
import (
"github.com/mattn/go-colorable"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)
func main() {
aa := colorable.NewColorableStdout()
log.Logger = log.Output(zerolog.ConsoleWriter{Out: aa})
log.Info().Msg("bb")
} |
Nobody is saying it's not worth fixing. I don't know numbers for Go dev on windows compared to other platforms, but it is certainly not aligned with the number of windows users in general. Certainly still big enough to care though. I'm in favor of adding this dep behind a build flag for windows so the console writer works out of the box. We could also just copy the color codes we need and save the dep and keep the whole thing KISS. |
@cup |
@rs This dependency can probably be removed. Anything after Windows 10 supports colors. |
Using this file:
I get this result:
Note that other projects work as expected:
The text was updated successfully, but these errors were encountered: