fatih / color

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

Optionally force colour output #66

Closed sublimino closed 7 years ago

sublimino commented 7 years ago

Would it be possible to force colour output without a terminal i.e. in a pipe? This would allow grep-ing for errors while maintaining useful colourised output.

This would provide the opposite functionality to https://github.com/fatih/color#disable-color - perhaps usage could look similar

var flagForceColor = flag.Bool("force-color", false, "Force color output")

if *flagForceColor {
    color.ForceColor = true // forces colorized output, even without a terminal attached
}

As a data point, grep also implements this with a flag:

$ grep --help | grep color -A 2
  --color[=WHEN],
  --colour[=WHEN]       use markers to highlight the matching strings;
                        WHEN is 'always', 'never', or 'auto'

This feature request is spawned from a dependent project https://github.com/wercker/stern/issues/33#issuecomment-289045171

fatih commented 7 years ago

Hi @sublimino

You can do it via

color.NoColor = false

This will force the color output. It's the same with what you want.