Skip to content

Only apply FORCE_COLOR, NO_COLOR and ANSI_COLORS_DISABLED when present and not an empty string #92

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

Merged
merged 2 commits into from
Mar 31, 2025

Conversation

hugovk
Copy link
Member

@hugovk hugovk commented Feb 28, 2025

Similar to the CPython fix: python/cpython#129061 / python/cpython#129140

The NO_COLOR spec was changed in 2022:

Tweak the spec wording to explain that it should be not empty
"the presence of... when present" was redundant.

jcs/no_color@99f90e2

It added "and not an empty string" and now reads:

Command-line software which adds ANSI color to its output by default should check for a NO_COLOR environment variable that, when present and not an empty string (regardless of its value), prevents the addition of ANSI color.

https://no-color.org/

FORCE_COLOR has similar wording:

Command-line software which outputs colored text should check for a FORCE_COLOR environment variable. When this variable is present and not an empty string (regardless of its value), it should force the addition of ANSI color.

https://force-color.org/

@hugovk hugovk added the changelog: Changed For changes in existing functionality label Feb 28, 2025
Copy link

codecov bot commented Feb 28, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.82%. Comparing base (a5799f8) to head (88f4b92).
Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #92      +/-   ##
==========================================
+ Coverage   97.77%   97.82%   +0.04%     
==========================================
  Files           3        3              
  Lines         135      138       +3     
==========================================
+ Hits          132      135       +3     
  Misses          3        3              
Flag Coverage Δ
macos-latest 97.82% <100.00%> (+0.04%) ⬆️
ubuntu-latest 97.82% <100.00%> (+0.04%) ⬆️
windows-latest 97.82% <100.00%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@hugovk
Copy link
Member Author

hugovk commented Feb 28, 2025

It looks like ANSI_COLORS_DISABLED is originally from Perl? At least this definition says it should be a set to a true value:

If this environment variable is set to a true value, all of the functions defined by this module (color(), colored(), and all of the constants) will not output any escape sequences and instead will just return the empty string or pass through the original text as appropriate. This is intended to support easy use of scripts using this module on platforms that don't support ANSI escape sequences.

https://metacpan.org/pod/Term::ANSIColor#ANSI_COLORS_DISABLED

The uncolor() function and support for ANSI_COLORS_DISABLED were added in Term::ANSIColor 1.04, included in Perl 5.8.0.

Perl 5.8.0 was released in 2002: https://dev.perl.org/perl5/news/2002/07/18/580ann/

So perhaps we should change if "ANSI_COLORS_DISABLED" in os.environ as well?

@hugovk
Copy link
Member Author

hugovk commented Mar 21, 2025

So perhaps we should change if "ANSI_COLORS_DISABLED" in os.environ as well?

Changed.

@hugovk hugovk changed the title Only apply FORCE_COLOR and NO_COLOR when present and not an empty string Only apply FORCE_COLOR, NO_COLOR and ANSI_COLORS_DISABLED when present and not an empty string Mar 21, 2025
@hugovk hugovk merged commit 5761438 into termcolor:main Mar 31, 2025
31 checks passed
@hugovk hugovk deleted the empty-string branch March 31, 2025 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: Changed For changes in existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Empty values of FORCE_COLOR and NO_COLOR are not ignored
1 participant