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§
- bg
- 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!]) - bg_
black - Adds a background to text
- bg_blue
- bg_blue
- bg_cyan
- bg_
dark_ gray - bg_
green - bg_
light_ blue - bg_
light_ cyan - bg_
light_ gray - bg_
light_ green - bg_
light_ magenta - bg_
light_ red - bg_
light_ yellow - bg_
magenta - bg_red
- bg_
white - bg_
yellow - black
- black black_gif
- blue
- blue
- bold
- Makes text bold
- color
- Formats a string with a color.
- cyan
- cyan
- dark
- Darkens text. You can combine this with a color to get a dark variant of this color
- dark_
gray - dark_grey
- dark_
grey - dark_grey
- gray
- grey
- green
- green green_gif
- grey
- grey
- italic
- italic
- light_
blue - light_blue
- light_
cyan - light_cyan
- light_
gray gray!- light_
green - light_green
- light_
grey grey!- light_
magenta - light_magenta
- light_
red - light_red
- light_
yellow - light_yellow
- magenta
- magenta
- printc
- Prints a color to the screen
- printlnc
- Prints a color to the screen with a new line
- red
- red red_gif
- style
- Formats a string to a color
- underline
- white
- white
- yellow
- yellow