Rust Color
Rust Color is a terminal color rendering library, thats supports 3/4 bit colors, 8 bit colors, 24 bit color rendering output, compatible with windows.
ANSI Escape Codes for Terminal Graphics
The ANSI escape code standard, formally adopted as ISO/IEC 6429, defines a series of control sequences. Each control sequence begins with a Control Sequence Introducer (CSI), defined as a scape character followed immediately by a bracket: ESC[. In particular, a CSI followed by a certain number of "parameter bytes" (ASCII 0-9:; <=>?) then the letter m forms a control sequence known as Select Graphic Rendition (SGR). If no parameter bytes are explicitly given, then it is assumed to be 0. SGR parameters can be chained together with a semicolon ; as delimiter.
Some common SGR parameters are shown below.
| Parameter | Effect |
|---|---|
| 0 | reset all SGR effects to their default |
| 1 | bold or increased intensity |
| 2 | faint or decreased insensity |
| 4 | singly underlined |
| 5 | slow blink |
| 30-37 | foreground color (3/4 bit) |
| 38;5;x | foreground color (256 colors, non-standard) |
| 38;2;r;g;b | foreground color (RGB, non-standard) |
| 40-47 | background color (8 colors) |
| 48;5;x | background color (256 colors, non-standard) |
| 48;2;r;g;b | background color (RGB, non-standard) |
| 90-97 | bright foreground color (non-standard) |
| 100-107 | bright background color (non-standard) |
- Below example will print a red underlined text.
![]()
- How to install - Add the rustcolor crate to your Cargo.toml
[dependencies]
rustcolor = {git = "https://github.com/jcbritobr/rustcolor"}
How to use
- Styles - The best way to start with rustcolor is using the predefined styles.
info!;
primary!;
warn!;
danger!;
error!;
underline!;
blink!;
![]()
- Printing 4bit color - If you only need to change foreground and background colors, it's possible change a text using print_c16 function.
![]()
- Printing 8bit color - Its possible to print 8bit colors using print_c256 function.
![]()
- Custom Styles - The style module makes possible to build custom styles.
![]()
- 24 Bit Color Support - Draw 24 bit color using print_24bit function.
![]()
- 3/4, 8 bit colors cheat sheet - Click here to download