-
Notifications
You must be signed in to change notification settings - Fork 621
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
Address feedback from pellared #187
Conversation
martinlindhe
commented
Mar 1, 2023
- NO_COLOR env is respected in color_windows.go
- fixes indent
EDIT: Tested working |
color_windows.go
Outdated
if err := windows.GetConsoleMode(out, &outMode); err == nil { | ||
outMode |= windows.ENABLE_PROCESSED_OUTPUT | windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING | ||
_ = windows.SetConsoleMode(out, outMode) | ||
if err := windows.GetConsoleMode(out, &outMode); err == nil || NoColor { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if err := windows.GetConsoleMode(out, &outMode); err == nil || NoColor { | |
if err := windows.GetConsoleMode(out, &outMode); err != nil { |
see #186 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it would be better to add opt-out code as a separate PR 😉
color_windows.go
Outdated
if err := windows.GetConsoleMode(out, &outMode); err == nil { | ||
outMode |= windows.ENABLE_PROCESSED_OUTPUT | windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING | ||
_ = windows.SetConsoleMode(out, outMode) | ||
if err := windows.GetConsoleMode(out, &outMode); err == nil || NoColor { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wrote more here, but let's remove NoColor
integration. It wouldn't work during runtime. See my comment: #186 (comment)
Also we want to return if GetConsoleMode doesn't work, so err should be non-nil
if err := windows.GetConsoleMode(out, &outMode); err == nil || NoColor { | |
if err := windows.GetConsoleMode(out, &outMode); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also we want to return if GetConsoleMode doesn't work, so err should be non-nil.
D'oh. Fixed.
So, should we just abandon this PR then, since it just attempts the NoColor integration?
- NO_COLOR env is respected in color_windows.go - fixes indent
@martinlindhe thank you. So the issue with no_color is, as I said happens during runtime. Here is an example it would fail: package main
import (
"github.com/fatih/color"
)
func main() {
c := color.New(color.FgCyan).Add(color.Underline)
c.Println("Prints cyan text with an underline.")
color.NoColor = false
c.Println("Prints cyan text with an underline.") // this is still not colored
} |
Well, this example also fails under Linux with fatih/color v1.14.1 (both lines are colored, or both are non-colored if NO_COLOR=1), so is it fair to try to address it in a corner-case for only Windows? |
@martinlindhe I think we just discovered a bug here. I'll push a fix. Looks like when you use an environment variable, it sticks and won't change in runtime afterwards. But the code should work as I described. |
@fatih Cool. I'll take a step away from this. Please use these changes or drop this PR as you see fit. Thanks for your help! |
Closing this, as I merged #188 and the |
Thank you @fatih! |