Skip to content

Conversation

@AdrieanKhisbe
Copy link
Contributor

Support --color and --force-color flag to 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.

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\)
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;
}
Copy link
Member

Choose a reason for hiding this comment

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

@AdrieanKhisbe
Copy link
Contributor Author

Thanks @sindresorhus for hinting most of the logic was already there.
I reworked it so that supports-color does the heavy lifting

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).
Copy link
Member

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.

Copy link
Contributor Author

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.

@sindresorhus sindresorhus merged commit 85bd741 into chalk:main May 1, 2025
2 checks passed
@AdrieanKhisbe AdrieanKhisbe deleted the color-flag-support branch May 3, 2025 16:07
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