Crate simple_colors

Crate simple_colors 

Source
Expand description

Simple colors provides macros for styling text with colors, backgrounds and styles like bold, italic and underline.

Licenses

green all bg bold

§Usage

println!("{}", red!("This is red"));
printlnc!(red!("This is also red"));
printlnc!(format!("{}, {}.", white!("This is white"), red!("this is red")))
red_output
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")));
output

§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."))
output
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"))
output

Modules§

custom

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

Enums§

Background
Color
Style