Expand description
§Color Formatting Crate
This crate provides macros and functions for formatting terminal output with colors, background colors, and styles using ANSI escape codes. It supports various colors and allows nesting of colors for flexible and dynamic terminal output.
§Features
- Apply predefined colors: Red, Green, Blue, White, Black, Yellow, Magenta, Cyan
- Apply background colors
- Apply text styles: Bold, Italic, Underline
- Custom RGB color support for text and background
- HSL and HSV color support for text and background
- Nested color support
§Usage
To use this crate, add it to your Cargo.toml
:
[dependencies]
term_ansi = "0.2.5"
Then you can use the provided macros to format your terminal output. Here are some examples:
use term_ansi::*;
// Simple color application
println!("{}", red!("Error message"));
// Background color
println!("{}", bg_blue!("Blue background"));
// Styles
println!("{}", bold!("Bold text"));
// Combining color, background, and style
println!("{}", red!("{}", bg_yellow!("{}", bold!("Warning: Important message"))));
// Custom RGB color
println!("{}", rgb!(255, 0, 0, "This is red text"));
// HSL and HSV colors
println!("{}", hsl!(120.0, 1.0, 0.5, "This is green text"));
println!("{}", bg_hsv!(240.0, 1.0, 1.0, "This has a blue background"));
§Macros
§Text Colors
red!
,green!
,blue!
,white!
,black!
,yellow!
,magenta!
,cyan!
§Background Colors
bg_red!
,bg_green!
,bg_blue!
,bg_white!
,bg_black!
,bg_yellow!
,bg_magenta!
,bg_cyan!
§Styles
bold!
,italic!
,underline!
§Custom Colors
rgb!
,bg_rgb!
: Apply custom RGB colors for text and background.hsl!
,hsv!
,bg_hsl!
,bg_hsv!
: Apply colors using HSL or HSV color models for text and background.
§License
This crate is licensed under the MIT License. See the LICENSE file for details.
Macros§
- apply_
color - Applies a color code to the provided format string.
- bg_
black - Applies a black background color to the provided format string.
- bg_blue
- Applies a blue background color to the provided format string.
- bg_cyan
- Applies a cyan background color to the provided format string.
- bg_
green - Applies a green background color to the provided format string.
- bg_hsl
- Applies a background color specified in HSL color space to the provided format string.
- bg_hsv
- Applies a background color specified in HSV color space to the provided format string.
- bg_
magenta - Applies a magenta background color to the provided format string.
- bg_red
- Applies a red background color to the provided format string.
- bg_rgb
- Applies a custom RGB background color to the provided format string.
- bg_
white - Applies a white background color to the provided format string.
- bg_
yellow - Applies a yellow background color to the provided format string.
- black
- Applies black color to the provided format string.
- blue
- Applies blue color to the provided format string.
- bold
- Applies bold formatting to the provided format string.
- cyan
- Applies cyan color to the provided format string.
- green
- Applies green color to the provided format string.
- hsl
- Applies HSL color to the provided format string.
- hsv
- Applies HSV color to the provided format string.
- italic
- Applies italic formatting to the provided format string.
- magenta
- Applies magenta color to the provided format string.
- red
- Applies red color to the provided format string.
- rgb
- Applies a custom RGB color to the provided format string.
- underline
- Applies underline formatting to the provided format string.
- white
- Applies white color to the provided format string.
- yellow
- Applies yellow color to the provided format string.