term_colr
A simple Rust library for adding color to your terminal output using ASCII escape codes.
Features
- Easy to use macros for coloring text.
- Supports foreground and background colors.
- Supports text formatting like bold, underline and italic.
- Supports RGB, HSL, and HSV colors.
- Nestable colors.
Usage
Add this to your Cargo.toml:
[]
= "0.1.0"
And then in your code:
use ;
Available Macros and Functions
Foreground Colors
black!(...)red!(...)green!(...)yellow!(...)blue!(...)white!(...)
Background Colors
bg_red!(...)bg_green!(...)bg_blue!(...)bg_yellow!(...)bg_gray!(...)
Formatting
bold!(...)italic!(...)underline!(...)
Advanced Colors
RGB
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!;
println!;
HSL
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!;
println!;
HSV
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!;
println!;
Utility Functions
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.