Disable color outputs using NO_COLOR env var#9357
Conversation
Setting this environment variable will not wrap the text in color ANSI code, so that we can print a raw output. Signed-off-by: Rishikesh Nair <alienware505@gmail.com>
| printf '\033['"$codes"'m' | ||
| } | ||
| wrap_color() { | ||
| if [ $RAW_OUTPUT -eq 1 ]; then |
There was a problem hiding this comment.
this seems fine, but an even more minimal change might be to make color() return early if this env var is set?
Also, I think NO_COLOR is a more widely supported variable to use for this. If it is set to anything other than an empty string, color output should be suppressed.
There was a problem hiding this comment.
Yeah that makes sense.
I changed RAW_OUTPUT -> NO_COLOR and changed the behaviour to check if NO_COLOR is set anything other than an empty string, color output will be suppressed.
e21f1d7
I'll also update the PR name and description to reflect these new changes.
Also, if NO_COLOR is empty, output will be colored, otherwise not colored. Signed-off-by: Rishikesh Nair <alienware505@gmail.com>
RAW_OUTPUT env varNO_COLOR env var
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #9357 +/- ##
==========================================
- Coverage 45.69% 41.93% -3.76%
==========================================
Files 154 154
Lines 16623 13523 -3100
==========================================
- Hits 7596 5671 -1925
+ Misses 7814 6735 -1079
+ Partials 1213 1117 -96
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Co-authored-by: Brad Davidson <brad@oatmail.org> Signed-off-by: Rishikesh Nair <42700059+rishinair11@users.noreply.github.com>
|
Thank you for the review @brandond. |
|
No, you are set. We are working through some issues with scheduling work for the next release cycle, so this may remain on hold for a bit longer. |
Proposed Changes
Setting this environment variable will not wrap the text in ANSI color codes, so that we can print a raw output.
This helps us a lot when piping the output to a text file, ANSI color codes make it difficult to read through the output in a text editor.
Types of Changes
Introduced a new environment variable called
NO_COLOR.NO_COLOR=1will disable the wrapping of output text in ANSI color codes.Default functionality will be maintained if the env var is not set at all.
Verification
Testing
Ran this suit of tests:
NO_COLORenv var:NO_COLOR can be set to whatever.
Linked Issues
check-configoutput. #9355User-Facing Change
Further Comments
Let me know if the variable name is not suitable, or any other questions/discussions. Will be happy to refactor my solution if needed.