# ๐ term_ansi
[](https://crates.io/crates/term_ansi)
[](https://docs.rs/term_ansi)
[](https://opensource.org/licenses/MIT)
> Colorize your terminal output with ease! ๐จโจ
`term_ansi` is a super-light weight 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 and custom RGB values, you can make your CLI applications more visually appealing and user-friendly.
## โ ๏ธ Important Version Notice
**Versions before v0.2.2 are unstable.**
**v0.2.2 and above are fully tested and stable. We strongly recommend using this version or later for production use.**
## ๐ Table of Contents
- [Features](#-features)
- [Installation](#-installation)
- [Usage](#-usage)
- [Basic Colors](#basic-colors)
- [Nested Colors](#nested-colors)
- [Custom RGB Colors](#custom-rgb-colors)
- [Available Macros](#-available-macros)
- [Examples](#-examples)
- [Contributing](#-contributing)
- [License](#-license)
## โจ Features
- ๐จ Easy-to-use macros for applying colors
- ๐ Support for 8 predefined colors
- ๐ข Custom RGB color support
- ๐ช Nested color application
- ๐งต Thread-safe color context management
## ๐ฆ Installation
Add `term_ansi` to your `Cargo.toml`:
```toml
[dependencies]
term_ansi = "0.2.2" # Make sure to use version 0.2.2 or later
```
## ๐ Usage
First, import the crate in your Rust file:
```rust
use term_ansi::*;
```
### Basic Colors
Apply colors to your text using the provided macros:
```rust
println!("{}", red!("This is red text"));
println!("{}", green!("This is green text"));
println!("{}", blue!("This is blue text"));
```
### Nested Colors
You can nest color macros for more complex formatting:
```rust
println!("{}", white!("This is {} with {} color", red!("red"), green!("green")));
```
### Custom RGB Colors
Use the `colour!` macro to apply custom RGB colors:
```rust
println!("{}", colour!(255, 128, 0, "This is orange text"));
```
## ๐ Available Macros
- `red!`: Apply red color
- `green!`: Apply green color
- `blue!`: Apply blue color
- `white!`: Apply white color
- `black!`: Apply black color
- `yellow!`: Apply yellow color
- `magenta!`: Apply magenta color
- `cyan!`: Apply cyan color
- `colour!`: Apply a custom RGB color
## ๐ก Examples
### Simple Error Message
```rust
println!("{}", red!("Error: {}", "File not found"));
```
### Colorful Status Message
```rust
println!("{} {} {}", green!("โ"), blue!("Building project:"), yellow!("in progress"));
```
### Nested Color Formatting
```rust
### Custom Color Gradient
```rust
for i in 0..=255 {
print!("{}", colour!(i, 0, 255 - i, "โ"));
}
println!();
```
## ๐ค Contributing
Contributions are welcome! Do discuss any improvements in the Issues first : )
Please make sure to update tests as appropriate and adhere to the existing coding style.
## ๐ License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
---
Happy coding! Hope it helps ๐ฆ