Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set/UnsetWriter asymmetry #230

Open
ataypamart opened this issue Apr 27, 2024 · 1 comment
Open

Set/UnsetWriter asymmetry #230

ataypamart opened this issue Apr 27, 2024 · 1 comment

Comments

@ataypamart
Copy link

ataypamart commented Apr 27, 2024

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

@fatih
Copy link
Owner

fatih commented Oct 3, 2024

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

ataypamart added a commit to ataypamart/color-issue-230 that referenced this issue Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants