-
-
Notifications
You must be signed in to change notification settings - Fork 19
Color flag support #47
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
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
cli.js
Outdated
| if (cli.flags.forceColor) { | ||
| chalk.level = supportsColor.level; | ||
| } else if (cli.flags.color !== undefined) { | ||
| chalk.level = cli.flags.color; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Chalk already has some of this logic: https://github.com/chalk/chalk/blob/5dbc1e2633f3874f43c144fa4919934bc934c495/source/vendor/supports-color/index.js#L16-L31
|
Thanks @sindresorhus for hinting most of the logic was already there. |
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). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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.