Crates.io | term_ansi |
lib.rs | term_ansi |
version | 0.2.5 |
source | src |
created_at | 2024-09-18 15:15:12.036746 |
updated_at | 2024-09-21 17:31:17.475785 |
description | A super lightweight macros crates to add ANSI Codes to your project |
homepage | |
repository | https://github.com/shubhexists/term_ansi |
max_upload_size | |
id | 1379366 |
size | 25,770 |
Colorize your terminal output with ease! ๐จโจ
term_ansi
is a lightweight Rust crate that provides a simple and intuitive way to add colors and formatting to your terminal output using ANSI escape codes. With support for various predefined colors, custom RGB values, and text styles, you can make your CLI applications more visually appealing and user-friendly.
Add term_ansi
to your Cargo.toml
:
[dependencies]
term_ansi = "0.2.5"
First, import the crate in your Rust file:
use term_ansi::*;
Apply colors to your text using the provided macros:
println!("{}", red!("This is red text"));
println!("{}", green!("This is green text"));
println!("{}", blue!("This is blue text"));
Apply background colors to your text:
println!("{}", bg_yellow!("This has a yellow background"));
println!("{}", bg_cyan!("This has a cyan background"));
Apply text styles:
println!("{}", bold!("This text is bold"));
println!("{}", italic!("This text is italic"));
println!("{}", underline!("This text is underlined"));
Use custom RGB, HSL, or HSV colors:
println!("{}", rgb!(255, 128, 0, "This is orange text"));
println!("{}", hsl!(120.0, 1.0, 0.5, "This is green text"));
println!("{}", bg_hsv!(240.0, 1.0, 1.0, "This has a blue background"));
Combine multiple styles and colors:
println!("{}", red!("{}", bg_white!("{}" bold!("Important: {}"), "Read this!")));
red!
, green!
, blue!
, white!
, black!
, yellow!
, magenta!
, cyan!
bg_red!
, bg_green!
, bg_blue!
, bg_white!
, bg_black!
, bg_yellow!
, bg_magenta!
, bg_cyan!
bold!
, italic!
, underline!
rgb!
, hsl!
, hsv!
: Custom foreground colorsbg_rgb!
, bg_hsl!
, bg_hsv!
: Custom background colorsprintln!("{}", red!("{}", bold!("Error: {}"), "File not found"));
println!("{} {} {}", green!("โ"), blue!("Building project:"), yellow!("in progress"));
for i in 0..=255 {
print!("{}", rgb!(i, 0, 255 - i, "โ"));
}
println!();
println!("{}",
bg_blue!("{}",
white!("{}",
bold!("Status: {} | {}",
green!("OK"),
red!("{}", underline!("Failed: {}"), 3)
)
)
)
);
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
Happy colorful coding! ๐ฆ๐