Merged
Conversation
Goal is to enable invocation of cli forcing color without having to play with the FORCE_COLOR env variable. (in the spirit of this chalk section: https://github.com/chalk/chalk\?tab\=readme-ov-file\#supportscolor\)
note false eslint positive rule had to be disabled. see sindresorhus/eslint-plugin-unicorn#1795
sindresorhus
requested changes
Apr 29, 2025
cli.js
Outdated
Comment on lines
182
to
186
| if (cli.flags.forceColor) { | ||
| chalk.level = supportsColor.level; | ||
| } else if (cli.flags.color !== undefined) { | ||
| chalk.level = cli.flags.color; | ||
| } |
Member
There was a problem hiding this comment.
Chalk already has some of this logic: https://github.com/chalk/chalk/blob/5dbc1e2633f3874f43c144fa4919934bc934c495/source/vendor/supports-color/index.js#L16-L31
Contributor
Author
|
Thanks @sindresorhus for hinting most of the logic was already there. |
sindresorhus
requested changes
Apr 30, 2025
cli.js
Outdated
| ${chalk.yellow('--stdin')} Read input from stdin rather than from arguments. | ||
| ${chalk.yellow('--no-newline, -n')} Don't emit a newline (\`\\n\`) after the input. | ||
| ${chalk.yellow('--demo')} Demo of all Chalk styles. | ||
| ${chalk.yellow('--color, -c')} Behave as FORCE_COLOR set to given value (0, 1, 2, 3, 256, 16m). |
Member
There was a problem hiding this comment.
I don't think the color flag supports levels. And it should be made clear that value is optional. And it doesn't behave like FORCE_COLOR.
Contributor
Author
There was a problem hiding this comment.
You're right.
I addressed it turning it into a boolean flags, and adding test to ensure the --color=true and --color=always works as expected.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Support
--colorand--force-color flagto force color display in terminal.(Original use case come from crafting a colored message in fzf preview)
Took the opportunity to bump the underneath main dependancies, notably chalk itself.