fatih / color

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

Is there a way to clear the set color string? #111

Closed Like0x closed 4 years ago

Like0x commented 4 years ago

Is there a way to clear the set color string?

I used color in other places, but I just want to clear the color in the specified place.

Yellow = color.New(color.FgYellow).SprintFunc()
s := Yellow(str)
// clear color s ?

I don't want to turn off the color globally.

var flagNoColor = flag.Bool("no-color", false, "Disable color output")

if *flagNoColor {
    color.NoColor = true // disables colorized output
}

Is there any code to do that?

fatih commented 4 years ago

Yeah create your color instance first before using SprintFunc() and then you can disable it via DisableColor(), see: https://github.com/fatih/color#disableenable-color