simple_colors 1.0.1

Macros for formatting text with colors, backgrounds and styles like bold, italic and underlined.
Documentation
  • Coverage
  • 45.93%
    62 out of 135 items documented20 out of 21 items with examples
  • Size
  • Source code size: 38.83 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 3.37 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Jomy10/simple_colors
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Jomy10

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

Installing

Add the following line to your Cargo.toml file:

[dependencies]
simple_colors = "1"

Overview

Colors

You can style text with colors:

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:

The available colors:

  • black
  • white
  • yellow & light_yellow
  • red & light_red
  • cyan & light_cyan
  • blue & light_blue
  • magenta & light_magenta
  • green & light_green
  • dark_grey & grey

Preview

Backgrounds

You can also add backgrounds:

use simple_colors::{white, bg_black, printlnc};

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

Styles

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

use simple_colors::bold;

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

Combining styles

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

Custom styles

You can also specify custom styles:

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

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"))

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.