Skip to content

[util] Allow styleText to take in hex colors #61543

@JoshuaKGoldberg

Description

@JoshuaKGoldberg

What is the problem this feature will solve?

Many userland projects use manual hex codes for color printing to the terminal. 256 and true color printing in supported terminals is supported in several libraries that existed prior to util.styleText. For example:

  • ansis: supports 256 and truecolor support with fallbacks to base 16 colors
  • chalk: has full 256 and truecolor support with fallbacks to terminal-supported levels
  • gradient-string: dedicated library for terminal gradients (see their 'who uses gradient string' for some pretty examples)

However, util.styleText only supports the standard 16 colors.

What is the feature you are proposing to solve the problem?

Could util.styleText take in hex codes?

styleText('#ffcc00', 'Success!');

They could be detected as anything starting with #.

What alternatives have you considered?

Userland code could stick with raw hex code printing. But that's rather inconvenient and error-prone. Plus, functions like styleText respect the NO_COLOR, NODE_DISABLE_COLORS and FORCE_COLOR environment variables.

Was this discussed in the design of styleText? I searched around and couldn't find it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.

    Type

    No type

    Projects

    Status

    Awaiting Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions