๐ term_ansi
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.
๐ Table of Contents
โจ Features
- ๐จ Easy-to-use macros for applying colors and styles
- ๐ Support for 8 predefined foreground and background colors
- ๐ข Custom RGB, HSL, and HSV color support for text and background
- ๐งต Text styles: Bold, Italic, Underline
- ๐ช Nested color and style application
- ๐งช Thread-safe color context management
๐ฆ Installation
Add term_ansi to your Cargo.toml:
[]
= "0.2.5"
๐ Usage
First, import the crate in your Rust file:
use *;
Basic Colors
Apply colors to your text using the provided macros:
println!;
println!;
println!;
Background Colors
Apply background colors to your text:
println!;
println!;
Text Styles
Apply text styles:
println!;
println!;
println!;
Custom Colors
Use custom RGB, HSL, or HSV colors:
println!;
println!;
println!;
Nested Formatting
Combine multiple styles and colors:
println!;
๐ Available Macros
Text Colors
red!,green!,blue!,white!,black!,yellow!,magenta!,cyan!
Background Colors
bg_red!,bg_green!,bg_blue!,bg_white!,bg_black!,bg_yellow!,bg_magenta!,bg_cyan!
Text Styles
bold!,italic!,underline!
Custom Colors
rgb!,hsl!,hsv!: Custom foreground colorsbg_rgb!,bg_hsl!,bg_hsv!: Custom background colors
๐ก Examples
Error Message with Style
println!;
Colorful Status Message
println!;
Custom Color Gradient
for i in 0..=255
println!;
Complex Nested Formatting
println!;
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
Happy colorful coding! ๐ฆ๐