Skip to content

Check NO_COLOR flag before CLICOLOR_FORCE#2763

Draft
braydenkrus wants to merge 2 commits intoninja-build:masterfrom
braydenkrus:patch-2
Draft

Check NO_COLOR flag before CLICOLOR_FORCE#2763
braydenkrus wants to merge 2 commits intoninja-build:masterfrom
braydenkrus:patch-2

Conversation

@braydenkrus
Copy link
Copy Markdown

In response to Issue #2295. This is in progress, and I still need to properly test and format these changes.

// Try enabling ANSI escape sequence support on Windows 10 terminals.
if (supports_color_) {
char* no_color = getenv("NO_COLOR");
if (no_color != NULL && std::string(no_color) != "0") {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: According to https://bixense.com/clicolors/, the simple fact that NO_COLOR is set should be enough to turn off color output, i.e. no interpretation of the "0" value should be necessary.

} else {
const char* clicolor_force = getenv("CLICOLOR_FORCE");
supports_color_ = clicolor_force && std::string(clicolor_force) != "0";
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: It's unfortunate that, even in the original code, CLICOLOR_FORCE is only tested on Unix, and never on Windows. What would you think about using the same logic for both systems, e.g. by moving the detection code to helper functions (e.g. EnvHasNoColor() and EnvHasCliColorForce()) and calling them consistently?

Copy link
Copy Markdown
Contributor

@digit-google digit-google left a comment

Choose a reason for hiding this comment

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

Please squash this into a single commit. It might be useful to add a link to https://bixense.com/clicolors/ in a comment explaining what rules the probes follow. @jhasse, do you think a check for CLICOLOR would be useful here? I see that there is also FORCE_COLOR described at https://force-color.org/

@braydenkrus
Copy link
Copy Markdown
Author

Hello @digit-google! I'm on board with your advice. Also, there may be value in switching from CLICOLOR_FORCE to FORCE_COLOR, as the latter seems to be the most up-to-date (based on the message on top of https://bixense.com/clicolors/), and https://force-color.org/ has an example implementation showing its relation to NO_COLOR (which also appears to give FORCE_COLOR priority over NO_COLOR, even if NO_COLOR is set).

@digit-google
Copy link
Copy Markdown
Contributor

Hello @digit-google! I'm on board with your advice. Also, there may be value in switching from CLICOLOR_FORCE to FORCE_COLOR, as the latter seems to be the most up-to-date (based on the message on top of https://bixense.com/clicolors/), and https://force-color.org/ has an example implementation showing its relation to NO_COLOR (which also appears to give FORCE_COLOR priority over NO_COLOR, even if NO_COLOR is set).

Good point, this seems important too. @khasse what do you think, since you wrote https://bixense.com/clicolors/ ?

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.

2 participants