Crate simple_colors
source · [−]Expand description
Simple colors provides macros for styling text with colors, backgrounds and styles like bold, italic and underline.
Usage
println!("{}", red!("This is red"));
printlnc!(red!("This is also red"));
printlnc!(format!("{}, {}.", white!("This is white"), red!("this is red")))
println!("{}", color!(Color::Red, "This is red"));
println!("{}", red!("This will be the same color"));
pritlnc!(bg_red("This text has a red background"));
println!("{}", bold!(green!("This text is bold and green")));
Define your own styles
You can create your own styles like:
struct MyCustomStyle;
impl simple_colors::custom::Style for MyCustomStyle {
fn get_style_code(&self) -> String {
// This will return a code for bold and light blue text
format!("{}{}",
Style::Bold.get_style_code(),
Color::LightBlue.get_style_code()
)
}
}
println!("{}", color!(MyCustomStyle,
"This text is light blue and bold, \
but on some terminals it is purple."))
enum MyCustomStyles {
Style1,
Style2
}
impl simple_colors::custom::Style for MyCustomStyles {
fn get_style_code(&self) -> String {
match self {
// Style1 will be bold and light blue
MyCustomStyles::Style1 => "\x1b[1m\x1b[94m".to_string(),
// Style2 will be bold and red
MyCustomStyles::Style2 =>
format!(
"{}{}",
Style::Bold.get_style_code(),
Color::Red.get_style_code()
)
}
}
}
println!("{}", color!(MyCustomStyles::Style2, "Some text that is both bold and red"))
Modules
Macros
Adds a background to text. See also the different bg_{color} methods to be able to display
text with a background and text color (e.g. bg_blue!
)
Adds a background to text
bg_blue
black
black_gif
blue
Makes text bold
Formats a string with a color.
cyan
Darkens text. You can combine this with a color to get a dark variant of this color
dark_grey
dark_grey
grey
green
green_gif
grey
italic
light_blue
light_cyan
light_green
light_magenta
light_red
light_yellow
magenta
Prints a color to the screen
Prints a color to the screen with a new line
red
red_gif
Formats a string to a color
white
yellow