Simple Colors

This crate provides simple macros for formatting strings with colors, backgrounds and styles like bold, italic and underlined. The crate does not use any external dependencies.

Licenses Crates.io Docs.rs

green all bg bold

Installing

Add the following line to your Cargo.toml file: toml [dependencies] simple_colors = "1"

Overview

Colors

You can style text with colors:

rust use simple_colors::{white, red, printlnc}; println!("{}", red!("This is red")); printlnc!(red!("This is also red")); printlnc!(format!("{}, {}.", white!("This is white"), red!("this is red")))

Output:

red_output

The available colors: - black - white - yellow & lightyellow - red & lightred - cyan & lightcyan - blue & lightblue - magenta & lightmagenta - green & lightgreen - dark_grey & grey

Preview

Backgrounds

You can also add backgrounds: ```rust use simplecolors::{white, bgblack, printlnc};

printlnc!(bg_black!(white!("Black background with white text"))); ```

bg

Styles

You can also make your text bold, italic or underlined.

```rust use simple_colors::bold;

printlnc!(bold!("This text is bold")); ```

Combining styles

You can combine all of the different macros to style your text.

all

Custom styles

You can also specify custom styles:

```rust use simple_colors::{color, Color, Style};

enum MyCustomStyles { Style1, Style2 } impl simplecolors::custom::Style for MyCustomStyles { fn getstylecode(&self) -> String { match self { // Style1 will be bold and light blue MyCustomStyles::Style1 => "\x1b[1m\x1b[94m".tostring(), // Style2 will be bold and red MyCustomStyles::Style2 => format!( "{}{}", Style::Bold.getstylecode(), Color::Red.getstylecode() ) } } } println!("{}", color!(MyCustomStyles::Style2, "Some text that is both bold and red")) ```

Contributing

Everything should be covered in this crate. If you find a bug, feel free to open an issue and then making a pull request (if you know how to fix the bug). If you can think of improvements, they are also always welcome.

License

This crate is licensed under the MIT License or the Apache-2.0 license.