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

Allow forcing color output #179

Closed
nabaco opened this issue Jan 5, 2023 · 2 comments
Closed

Allow forcing color output #179

nabaco opened this issue Jan 5, 2023 · 2 comments

Comments

@nabaco
Copy link

nabaco commented Jan 5, 2023

As described in https://github.com/fatih/color#disableenable-color and can be seen in https://github.com/fatih/color/blob/main/color.go#L23, when piping the output no colors will be applied.
There are some usecases when the user might want the colors to persist even when piping (e.g. piping a command output to less -R).
Is it possible to add an option to force colors unconditionally?

@fatih
Copy link
Owner

fatih commented Jan 5, 2023

If you explicitly set NoColor to false, it will forcefully log with escape characters, so (it's false instead of true):

if *flagForceColor {
	color.NoColor = false // force colorized output
}

Does this solve your issue?

@nabaco
Copy link
Author

nabaco commented Jan 7, 2023

Confirmed as working, thanks.

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