8000 Set/UnsetWriter asymmetry · Issue #230 · fatih/color · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Set/UnsetWriter asymmetry #230
Open
Open
@ataypamart

Description

@ataypamart

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0