Skip to content

util.styleText: support background colors with hex codes #64685

Description

@araujogui

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!');

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions