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

Address feedback from pellared #187

Closed
wants to merge 1 commit into from
Closed

Conversation

martinlindhe
Copy link
Contributor

  • NO_COLOR env is respected in color_windows.go
  • fixes indent

@martinlindhe
Copy link
Contributor Author

martinlindhe commented Mar 1, 2023

Please wait a minute with merging this. Verifying on my windows machine that NO_COLOR=1 works as expected.

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 {
Copy link
Contributor

@pellared pellared Mar 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if err := windows.GetConsoleMode(out, &outMode); err == nil || NoColor {
if err := windows.GetConsoleMode(out, &outMode); err != nil {

see #186 (comment)

Copy link
Contributor

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 {
Copy link
Owner

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

Suggested change
if err := windows.GetConsoleMode(out, &outMode); err == nil || NoColor {
if err := windows.GetConsoleMode(out, &outMode); err != nil {

Copy link
Contributor Author

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?

@martinlindhe
Copy link
Contributor Author

Capture

Tested NO_COLOR override on windows (works).

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

- NO_COLOR env is respected in color_windows.go
- fixes indent
@fatih
Copy link
Owner

fatih commented Mar 1, 2023

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

@martinlindhe
Copy link
Contributor Author

martinlindhe commented Mar 1, 2023

@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?

@fatih
Copy link
Owner

fatih commented Mar 1, 2023

@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.

@martinlindhe
Copy link
Contributor Author

@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!

@fatih
Copy link
Owner

fatih commented Mar 12, 2023

Closing this, as I merged #188 and the no color approach needs to be rethought. I'm going to look into it. Thanks for the work so far @martinlindhe and @pellared

@fatih fatih closed this Mar 12, 2023
@martinlindhe martinlindhe deleted the extras branch March 12, 2023 15:12
@martinlindhe
Copy link
Contributor Author

Thank you @fatih!

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

Successfully merging this pull request may close these issues.

None yet

3 participants