Crates.io | simple_colors |
lib.rs | simple_colors |
version | 1.0.1 |
source | src |
created_at | 2022-01-19 19:14:40.910232 |
updated_at | 2022-01-19 19:19:57.936986 |
description | Macros for formatting text with colors, backgrounds and styles like bold, italic and underlined. |
homepage | |
repository | https://github.com/Jomy10/simple_colors |
max_upload_size | |
id | 517027 |
size | 39,146 |
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.
Add the following line to your Cargo.toml file:
[dependencies]
simple_colors = "1"
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:
You can also add backgrounds:
use simple_colors::{white, bg_black, printlnc};
printlnc!(bg_black!(white!("Black background with white text")));
You can also make your text bold, italic or underlined.
use simple_colors::bold;
printlnc!(bold!("This text is bold"));
You can combine all of the different macros to style your text.
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"))
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.
This crate is licensed under the MIT License or the Apache-2.0 license.