util.styleText: support background colors with hex codes
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 122k
- Forks
- 37.3k
- Avg merge
- 4d 2h
- Merged PRs (30d)
- 283
Description
What is the problem this feature will solve?
util.styleText() supports arbitrary foreground colors via hex codes (styleText('#ff5733', text), added in #61556), but there's no equivalent for background colors. Predefined colors already have both a foreground (red) and background (bgRed) variant, but hex colors only cover the foreground case (SGR 38;2;r;g;b).
What is the feature you are proposing to solve the problem?
Extend hex color detection in styleText to also accept a background variant, mirroring the existing bgRed/red naming convention by prefixing the hex code with bg:
styleText('bg#ff5733', 'Warning!');
This would emit the background TrueColor SGR sequence (48;2;r;g;b) instead of the foreground one (38;2;r;g;b), and composes with the existing array syntax to combine foreground + background:
styleText(['#ffffff', 'bg#ff5733'], 'Warning!');
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the util.styleText entry point and read the existing hex-color handling for foreground SGR sequences. Extend the behavior for the bg-prefixed form and verify that foreground and background styles compose through the array syntax. Done means bg#ff5733 produces the 48;2;r;g;b sequence while #ffffff plus bg#ff5733 produces both styles.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- cli
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 65/100