-
Notifications
You must be signed in to change notification settings - Fork 232
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
turning colors on/off #445
Comments
IIUC you can use the following code today to do that: func DisableColors() {
os.Setenv("NO_COLOR", "true")
}
func ForceColors() {
os.Unsetenv("NO_COLOR")
os.Setenv("CLICOLOR_FORCE", "true")
}
func EnableColors() {
os.Unsetenv("NO_COLOR")
os.Unsetenv("CLICOLOR_FORCE")
os.Setenv("CLICOLOR", "true")
} |
thank you very much @testinfected |
Hey @marcotrosi my pleasure You can find more info here: Standard for ANSI Colors in Terminals I had the same issue as you a few months ago and dived into lipgloss source code to see this was properly supported. |
thanks again @testinfected edit: assuming t2 is my tool |
I believe the env vars would be inherited by the subshell right? In which case let's that you want to re-enable colors for t3 you would have to use something like:
(hope I got the syntax right) |
as far as I know on unixoid systems env vars are only inherited to sub shells if one uses the export command supporting the NO_COLOR solution is definitely a very good and needed feature, but looking at your proposed of changing the environment variables before piping into t3, I must say I would definitely prefer a proper command line parameter for t2
basically back to my original request/question. |
Lipgloss doesn't have a CLI tool right? |
the link you sent @testinfected perfectly states what I mean. Also consider letting the user override these with command-line options like --color and --color=WHEN ... |
correct, lipgloss is only a lib, but I'm the one who has to take care of the cli options. |
Agreed, so we're in the same situation, I added the following to my CLI app: --color=auto|always|never Then I use the functions above depending on the flag value. |
exactly, and now the question if you would have manipulated the behavior of t3 in the example? |
Your link shows it perfectly. Again thanks for sharing it. We need both, NO_COLOR and cli options, but we shouldn't solve the cli options by setting the env vars, this will cause problems from what I see. Do you agree? |
Sure does. It's only a workaround for now. I hope #293 will help here |
Hello everyone,
this is maybe more a question, that becomes a Feature Request if there is no simple solution yet, but at least I couldn't find anything in the documentation.
As you know some command line tools have something like a --no-color option to turn off all escape sequences for colors etc., or some do it automatically when they detect the tools is getting used in a pipe chain.
My first question would be "how do you implement such feature and is there some switch or other easy solution available in lipgloss?"
Describe alternatives you've considered
Currently I'm overwriting the Styles like this (just the basic concept, the code looks actually a bit different) ...
I want to avoid wrapping everything and having if-else statements everywhere.
Describe the solution you'd like
I thought maybe something simple like the following concept would be simple ...
Additional context
Of course in my example I only used 2 Styles, imagine it being many more.
And for every new Style I shall not forget to add also the overwriting.
thanks for your feedback upfront.
looking forward to learn how you guys do it
have a great day
--marco
The text was updated successfully, but these errors were encountered: