term_colr
I got tired of hand-rolling ANSI escape codes every time I wanted colored CLI output in Rust. term_colr is a small crate that gives you macros for colors and styles—red, green, bold, underline, RGB/HSL/HSV—and it manages a color context so you can nest them. No need to remember the raw sequences; just wrap your text in a macro and print.
How it works
Under the hood it’s ANSI escape codes. The macros wrap your text with the right codes; the library keeps a stack so when you nest colors (e.g. red inside white), it restores the previous color when the inner one ends. You get predictable, readable output without manual reset codes.
Basic colors and styles
Foreground: red!, green!, blue!, yellow!, black!, white!
Background: bg_red!, bg_green!, bg_blue!, bg_yellow!, bg_gray!
Styles: bold!, underline!, italic!
Advanced colors: rgb!(r, g, b, "text"), hsl!(h, s, l, "text"), hsv!(h, s, v, "text") — and the same for backgrounds with bg_rgb!, bg_hsl!, bg_hsv!.
You can nest them: e.g. white text with red and green words inside.
Examples
Basic:
use term_colr::{red, green, blue};
println!("This is {} text.", red!("red"));
println!("This is {} text.", green!("green"));
println!("This is {} text.", blue!("blue"));
Styles:
use term_colr::{bold, underline, italic};
println!("This is {} text.", bold!("bold"));
println!("This is {} text.", underline!("underlined"));
println!("This is {} text.", italic!("italic"));
Nested:
use term_colr::{white, red, green};
println!("{}", white!("This is {} with {} color", red!("red"), green!("green")));
RGB / HSL / HSV:
use term_colr::{rgb, hsl, hsv};
println!("{}", rgb!(255, 0, 0, "Bright red"));
println!("{}", hsl!(120.0, 1.0, 0.5, "Green"));
println!("{}", hsv!(240.0, 1.0, 1.0, "Blue"));
What’s next
I’d like to add something for ASCII-art style output from text—could be fun for banners and CLI headers.
Tech: Pure Rust, no external deps for the core. Lightweight and easy to plug into any CLI.