fatih / color

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

feat: Add support for `Errorf` #167

Closed wafuwafu13 closed 1 year ago

wafuwafu13 commented 1 year ago

I want to add support for Errorf.

Before

func exampleFunc() error {
    ex, err := foo()
    red := color.New(color.FgRed)
    if err != nil {
        return fmt.Errorf(red.Sprintf("this is error: %s", err))
    }
...
}

After

func exampleFunc() error {
    ex, err := foo()
    red := color.New(color.FgRed)
    if err != nil {
        return red.Errorf("this is error: %s", err)
    }
...
}
fatih commented 1 year ago

Hi @wafuwafu13 Thanks for your contribution.

Errors are not meant to be colorized. They are values, and adding a color means you're creating a new error from scratch.