fatih/color

Set/UnsetWriter asymmetry

ataypamart opened this issue · 1 comments

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)
}

@ataypamart would you like to open a Pull Request? Happy to go over it.