#color #formatting #ansi-colors #terminal #terminal-colors #output #styling

app shellcolor

A utility for coloring and formatting terminal output. It just returns the requested string with the proper formatting applied.

3 unstable releases

0.2.1 Feb 21, 2024
0.2.0 Jan 13, 2024
0.1.0 Jan 12, 2024

#5 in #styling

34 downloads per month

Custom license

130 lines


Looking up ANSI color codes is difficult and time consuming - realistically, who knows what "\033[31;1;4mHello\033[0m" means off the top of their head1?

shellcolor provides an easy way of styling text in CLI scripts. It uses memorable flags like --bg and --bold to provide style to text.

Getting the ASCII output

If you need to see the ASCII output for compatibility with another program, you can pipe it into another file, and copy it from there.

shellcolor --bg red hello > hi.txt    

Experimental format support

While applying styles to text is great, it would be better to be able to interleave styles throughout the text. If we attempt to style a single string in multiple ways, we'd get some ugly text like this

echo "$(shellcolor --bg black --fg red "hello there,") $(shellcolor --fg green --bold "General") $(shellcolor --fg bright_white --underline Kenobi)"

In an effort to make it more approachable, there is a flag called --format which will allow for a BBCode-like syntax. It's currently pretty primitive (as in, doesn't handle nesting well), but something like this will get you close without requiring a series of subshells.

shellcolor --format "[color=red]Hello there,[/color] [bold]General[/bold]"

Man page

Translates CSS colors to ANSI escape sequences

    shellcolor [OPTIONS] <TEXT>

    <TEXT>    The text to display

        --bg <bg>      Set background color (e.g., red, green, blue, or 0-255 for 256-color mode)
        --blink        Set text to blink
        --bold         Set text to bold
        --fg <fg>      Set foreground (text) color (e.g., red, green, blue, or 0-255 for 256-color
        --format       Formats the text with a BBCode-like syntax. For example, "Hello
                       [color=red]World[/color]! This is a [bold]Bold[/bold] text."
    -h, --help         Print help information
        --hidden       Hide text (but it can be selected/copied)
        --reverse      Reverse background and foreground colors
        --underline    Set text to underline
    -V, --version      Print version information

1: It is the string "Hello", with red text, bolded, and underlined.


~76K SLoC