| Crates.io | term_colr |
| lib.rs | term_colr |
| version | 0.1.0 |
| created_at | 2025-08-16 06:00:48.092103+00 |
| updated_at | 2025-08-16 06:00:48.092103+00 |
| description | A super fast short one-liner about your crate |
| homepage | |
| repository | https://github.com/Shivrajsoni/term_colr |
| max_upload_size | |
| id | 1798044 |
| size | 17,299 |
A simple Rust library for adding color to your terminal output using ASCII escape codes.
Add this to your Cargo.toml:
[dependencies]
term_colr = "0.1.0"
And then in your code:
use term_colr::{red, blue, green, bg_yellow, bold, italic, underline, rgb, hsl, hsv, bg_rgb, bg_hsl, bg_hsv};
fn main() {
println!("This is the default color.");
println!("{}", red!("This is red!"));
println!("{}", blue!("This is blue!"));
println!("{}", green!("This is green!"));
println!("{}", bg_yellow!("This has a yellow background!"));
println!("{} and this is also red!", red!("This is red"));
println!("{}", blue!("This is blue {}!", green!("and this is green")));
println!("{}", bold!("This is bold text."));
println!("{}", italic!("This is italic text."));
println!("{}", underline!("This is underlined text."));
println!("{}", rgb!(255, 0, 0, "This is bright red using RGB!"));
println!("{}", hsl!(120.0, 1.0, 0.5, "This is green using HSL!"));
println!("{}", hsv!(240.0, 1.0, 1.0, "This is blue using HSV!"));
println!("{}", bg_rgb!(100, 150, 200, "Custom background color using RGB!"));
println!("{}", bg_hsl!(180.0, 0.5, 0.5, "Custom background color using HSL!"));
println!("{}", bg_hsv!(270.0, 0.7, 0.9, "Custom background color using HSV!"));
}
black!(...)red!(...)green!(...)yellow!(...)blue!(...)white!(...)bg_red!(...)bg_green!(...)bg_blue!(...)bg_yellow!(...)bg_gray!(...)bold!(...)italic!(...)underline!(...)rgb!(r, g, b, ...): Applies a foreground color using RGB values.bg_rgb!(r, g, b, ...): Applies a background color using RGB values.Example:
println!("{}", rgb!(255, 0, 0, "This is bright red"));
println!("{}", bg_rgb!(0, 0, 255, "This has a blue background"));
hsl!(h, s, l, ...): Applies a foreground color using HSL values.bg_hsl!(h, s, l, ...): Applies a background color using HSL values.Example:
println!("{}", hsl!(120.0, 1.0, 0.5, "This is green"));
println!("{}", bg_hsl!(0.0, 0.0, 0.5, "This has a gray background"));
hsv!(h, s, v, ...): Applies a foreground color using HSV values.bg_hsv!(h, s, v, ...): Applies a background color using HSV values.Example:
println!("{}", hsv!(240.0, 1.0, 1.0, "This is blue"));
println!("{}", bg_hsv!(300.0, 0.5, 0.7, "This has a purple background"));
These functions are public and can be used for color conversions if needed.
hsl_to_rgb(h: f64, s: f64, l: f64) -> (u8, u8, u8): Converts HSL color values to RGB.hsv_to_rgb(h: f64, s: f64, v: f64) -> (u8, u8, u8): Converts HSV color values to RGB.reset_all() -> &'static str: Returns the ANSI code to reset all terminal formatting.