-
Notifications
You must be signed in to change notification settings - Fork 86
Add support for NO_COLOR and CLICOLOR (#428) #432
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
Conversation
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.
Thanks for the patch. Please see below few comments.
It could be good to also add tests in CLIDisplay I think and also add somewhere in some docs that these variables are now supported.
lib/ClusterShell/CLI/Display.py
Outdated
"""Tests NO_COLOR environment variable to determine if color | ||
must be muted on output.""" | ||
|
||
if os.getenv('NO_COLOR') is not None: |
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.
prefer
return 'NO_COLOR' in os.environ
And this could be directly use above maybe, no need for a function?
|
||
cli_color = os.getenv("CLICOLOR") | ||
|
||
if cli_color is None: |
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.
Looks like:
if cli_color is None:
return None
elif cli_color != "0":
return sys.stdout.isatty()
else:
return False
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.
Overall ok, just minor style change
lib/ClusterShell/CLI/Display.py
Outdated
elif cli_color != "0": | ||
# CLICOLOR should be used but stdout is not a tty. | ||
return False | ||
# CLICOLOR are ment to be used if stdout is a tty |
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.
not sure what 'ment' means?
lib/ClusterShell/CLI/Display.py
Outdated
# CLICOLOR should be used but stdout is not a tty. | ||
return False | ||
# CLICOLOR are ment to be used if stdout is a tty | ||
return sys.stdout.isatty() | ||
elif cli_color == "0": |
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.
prefer a simple else
here
Could be good to change the commit message.
See how other commit messages look like. |
Looks good to me. I was wondering if the doc text should not be written using a dedicated section for Environment variables, or something similar. I will let @thiell validate this part. |
Hi @dupgit, |
doc/txt/clubak.txt
Outdated
@@ -57,7 +57,7 @@ OPTIONS | |||
node / line content separator string (default: `:`) | |||
-F, --fast faster but memory hungry mode (preload all messages per node) | |||
-T, --tree message tree trace mode; switch to enable ``ClusterShell.MsgTree`` trace mode, all keys/nodes being kept for each message element of the tree, thus allowing special output gathering | |||
--color=WHENCOLOR whether to use ANSI colors to surround node or nodeset prefix/header with escape sequences to display them in color on the terminal. *WHENCOLOR* is ``never``, ``always`` or ``auto`` (which use color if standard output refers to a terminal). Color is set to [34m (blue foreground text) and cannot be modified. | |||
--color=WHENCOLOR ``clush`` is compliant with NO_COLOR, CLICOLOR and CLICOLOR_FORCE environment variables. NO_COLOR takes precedence over CLICOLOR_FORCE which takes precedence over CLICOLOR. If these environment variables are not used then ``--color`` tells whether to use ANSI colors to surround node or nodeset prefix/header with escape sequences to display them in color on the terminal. *WHENCOLOR* is ``never``, ``always`` or ``auto`` (which use color if standard output refers to a terminal). Color is set to [34m (blue foreground text) and cannot be modified. |
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.
--color should have precedence over environment variables
Hi, |
Hi @dupgit, Thanks for the change and sorry for the delay. While testing your patch, I found an issue that annoys me a bit. If We could fix the patch so that if Or perhaps even better, I'm wondering if we should offer more choices in |
Hi @thiell,
Thanks for the rewiew. I thought that options that are set in either command line or configuration file should take precedence over color environment variables.
I will fix the proposed patch in that way: environment variable are still taken into account when color:auto or no color option is configured in
I think that this will be more confusing to the user and will make the patch more complex. Getting |
@thiell @degremont is there anything left here to help merging this patch ? |
Adds support for NO_COLOR and CLICOLOR specification standard for ANSI colors in terminals. --color option takes precedence over environment variables. It also takes care of configuration file options. Changes THREE_CHOICES index in order to test things correctly. Closes cea-hpc#428. Signed-off-by: Olivier DELHOMME <[email protected]>
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.
Thank you, @dupgit, for your contribution!
Takes care of NO_COLOR, CLICOLOR and CLICOLOR_FORCE environment variables. NO_COLOR takes precedence over CLICOLOR_FORCE itself taking precedence over CLICOLOR itself taking precedence over --color command line option.
When none of NO_COLOR, CLICOLOR and CLICOLOR_FORCE environment variables
are defined the old behavior still works and command line options are taken into account.