lukeed / kleur

The fastest Node.js library for formatting terminal text with ANSI colors~!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Builtin color-support detection

amio opened this issue · comments

Nice package!

Just a little annoying issue, testing for cli usually running in a non-colored shell, I have to disable it manually in testing, then found I have to do it in every package switched from chalk to kleur > <

What about considering builtin color-support detection?

Hey, thanks~!

Currently, not now. There are a number of packages made specifically for this, and since there are a number of exceptions, I find it best to use one of those for the time being... at least until I have time to understand the implications of each level.

This is what I use: https://github.com/lukeed/kleur#conditional-support. Any level greater than 0 means that colors are supported.

Hope that helps~! I may revisit in the future

Thanks!

However that means whenever you need to do testing, you will need color-support package with kleur, this could be a common use case, that make me think why not make it a builtin feature?

Yeah, understood. However, that means you'll need/be using a support-check in production too, right? Then don't see much of an issue with that. A module meant for color-checking will already have all its own testing done -- & the one I linked has 0 dependencies.

On the flipside, inlining a check means more testing and has possibility of this work being duplicated across other dependencies in the app's tree. And, if you expect to always have color support, then it goes unused.

Personally, most of my CLIs are bundled for distribution, so the "cost" of a small, single additional dependency (that does its job well) doesn't matter at the end of the day.

Another workaround, how about honoring NODE_DISABLE_COLORS , auto disable color when this presented?

I use node-tap's snapshots to get over my testing issue.

While I still think it would be nice to honor NODE_DISABLE_COLORS, shall I open another issue to address that? What's your idea?