Crates.io | shellcolor |
lib.rs | shellcolor |
version | 0.2.1 |
source | src |
created_at | 2024-01-12 15:14:05.060699 |
updated_at | 2024-02-21 05:39:50.581732 |
description | A utility for coloring and formatting terminal output. It just returns the requested string with the proper formatting applied. |
homepage | https://patbeagan.dev |
repository | https://github.com/patbeagan1/Open-Source-Requests |
max_upload_size | |
id | 1097753 |
size | 17,442 |
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.
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
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]"
Translates CSS colors to ANSI escape sequences
USAGE:
shellcolor [OPTIONS] <TEXT>
ARGS:
<TEXT> The text to display
OPTIONS:
--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
mode)
--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.