fatih / color

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

Set/UnsetWriter asymmetry #230

Open ataypamart opened 2 months ago

ataypamart commented 2 months ago

SetWriter and UnsetWriter on Color are not symmetric when it comes to the autodetection of support: this has created an issue that was difficult to understand in code i have been working on.

Namely, SetWriter delegates the autodetection to isNoColorSet(), while UnsetWriter() does the same, but checks again the global NoColo flag (which is also consulted in isNoColorSet()). The consequence is that when global autodetected NoColor is set, but Color has been forced to not-NoColor (sorry for the double negation), escape sequences are opened, but never closed.

This looks like a minor oversight. See below the proposed change, maybe a bit small to deserve a pull request.

diff --git a/color.go b/color.go index 81094e8..d79a24c 100644 --- a/color.go +++ b/color.go @@ -205,10 +205,6 @@ func (c *Color) UnsetWriter(w io.Writer) { return }

- if NoColor { - return - } - fmt.Fprintf(w, "%s[%dm", escape, Reset) }