Skip to content
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

Respect the NO_COLOR environment variable #102

Merged
merged 1 commit into from
Sep 9, 2024

Conversation

ericcornelissen
Copy link
Contributor

@ericcornelissen ericcornelissen commented Sep 8, 2024

This addresses #85, potentially closing it.

I updated the implementation of the coloring logic in this project to respect the NO_COLOR environment variable name to allow users to use the tool without colored output. An alternative approach could be to use an existing library for coloring, which might just support these kinds of features.

I briefly looked at adding a --no-color option1 and while this seems trivial the use of console.error (example) makes this non-trivial because every invocation would need to check --no-color (whereas it does respect NO_COLOR). Since I don't think it makes sense to perform this check every time console.error (or similar) is used, I think a larger refactoring of outputting is instead required if we want to support a flag like --no-color.

Footnotes

  1. A basic implementation can be achieved by adding .option('--no-color', 'Disable colored output.') to index.ts and || process.argv.includes('--no-color') to color.ts.

Update the implementation of the coloring logic in this project to
respect the NO_COLOR environment variable name to allow users to use the
tool without colored output. This can be useful when, e.g., saving the
result to a file.
@jeemok
Copy link
Owner

jeemok commented Sep 9, 2024

using env var for this use case makes sense 👍🏻 thank you for adding this @ericcornelissen !

@jeemok jeemok merged commit 5e64f4a into jeemok:master Sep 9, 2024
5 checks passed
@ericcornelissen ericcornelissen deleted the 85-no-color branch September 9, 2024 14:52
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