Skip to content

feat: add support for NO_COLOR standard for controlling usage of colour in console messages#3859

Merged
reubenmiller merged 2 commits intothin-edge:mainfrom
reubenmiller:feat-support-no-color-env-variable
Nov 17, 2025
Merged

feat: add support for NO_COLOR standard for controlling usage of colour in console messages#3859
reubenmiller merged 2 commits intothin-edge:mainfrom
reubenmiller:feat-support-no-color-env-variable

Conversation

@reubenmiller
Copy link
Copy Markdown
Contributor

@reubenmiller reubenmiller commented Nov 13, 2025

Proposed changes

Add support to all tedge binaries to allow users to disable colours by setting the NO_COLOR variable (e.g. export NO_COLOR=1) as per the no-color spec.

This allows users who are on terminals which aren't capable of displaying colours to easily disable it by setting an environment variable in the shell profile.

The printing of terminal messages will be disabled when:

  • stdout or stderr is not a TTY
  • The NO_COLOR environment variable is set to anything but NO_COLOR=0

Note: No tests were added as this feature is difficult to test as the test itself influences the result.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Improvement (general improvements like code refactoring that doesn't explicitly fix a bug or add any new functionality)
  • Documentation Update (if none of the other choices apply)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Paste Link to the issue

#3777

Checklist

  • I have read the CONTRIBUTING doc
  • I have signed the CLA (in all commits with git commit -s. You can activate automatic signing by running just prepare-dev once)
  • I ran just format as mentioned in CODING_GUIDELINES
  • I used just check as mentioned in CODING_GUIDELINES
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Further comments

Signed-off-by: reubenmiller <reuben.d.miller@gmail.com>
@reubenmiller reubenmiller changed the title feat: add support for NO_COLOR standard for printing console messages feat: add support for NO_COLOR standard for controlling usage of colour in console messages Nov 13, 2025
@codecov
Copy link
Copy Markdown

codecov bot commented Nov 13, 2025

Codecov Report

❌ Patch coverage is 30.00000% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/extensions/tedge-p11-server/src/main.rs 0.00% 4 Missing ⚠️
...s/common/tedge_config/src/system_toml/log_level.rs 0.00% 1 Missing and 1 partial ⚠️
crates/core/tedge/src/main.rs 75.00% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Nov 13, 2025

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
742 0 3 742 100 2h17m57.073828999s

@reubenmiller reubenmiller added the theme:cli Theme: cli related topics label Nov 13, 2025
@albinsuresh
Copy link
Copy Markdown
Contributor

For some reason, it isn't working for me:
Screenshot 2025-11-14 at 4 13 50 PM

jarhodes314
jarhodes314 previously approved these changes Nov 14, 2025
@jarhodes314 jarhodes314 dismissed their stale review November 14, 2025 15:07

Tested the NO_COLOR support and also could not get it to work

@jarhodes314
Copy link
Copy Markdown
Contributor

For some reason, it isn't working for me: Screenshot 2025-11-14 at 4 13 50 PM

Ah, yansi is paying attention to NO_COLOR, but the tracing_subscriber isn't, so tedge config list --doc respects NO_COLOR, but the log lines don't.

Signed-off-by: James Rhodes <jarhodes314@gmail.com>
@jarhodes314
Copy link
Copy Markdown
Contributor

jarhodes314 commented Nov 14, 2025

For some reason, it isn't working for me: Screenshot 2025-11-14 at 4 13 50 PM

Ah, yansi is paying attention to NO_COLOR, but the tracing_subscriber isn't, so tedge config list --doc respects NO_COLOR, but the log lines don't.

@reubenmiller @albinsuresh I've now pushed a commit to ensure log lines respect the NO_COLOR variable

Copy link
Copy Markdown
Contributor

@didier-wenzek didier-wenzek left a comment

Choose a reason for hiding this comment

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

Approved

tracing_subscriber::fmt()
.with_writer(std::io::stderr)
.with_ansi(std::io::stderr().is_terminal())
.with_ansi(std::io::stderr().is_terminal() && yansi::Condition::no_color())
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.

I have been puzzled by the no_color() function name (I would expect something like no_no_color()), but that's correct.

Copy link
Copy Markdown
Contributor

@albinsuresh albinsuresh left a comment

Choose a reason for hiding this comment

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

Re-tested with the fix from @jarhodes314 and it is working now.

Copy link
Copy Markdown
Member

@rina23q rina23q left a comment

Choose a reason for hiding this comment

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

All tedge CLI commands seem fine.

@reubenmiller reubenmiller added this pull request to the merge queue Nov 17, 2025
Merged via the queue into thin-edge:main with commit f5297bb Nov 17, 2025
51 of 52 checks passed
@reubenmiller reubenmiller deleted the feat-support-no-color-env-variable branch November 17, 2025 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

theme:cli Theme: cli related topics

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants