term_ansi 0.2.4

A super lightweight macros crates to add ANSI Codes to your project
Documentation

๐ŸŒˆ term_ansi

Crates.io Documentation License: 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

  • ๐ŸŽจ 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:

[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:

use term_ansi::*;

Basic Colors

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

Nested Colors

You can nest color macros for more complex formatting:

println!("{}", white!("This is {} with {} color", red!("red"), green!("green")));

Custom RGB Colors

Use the colour! macro to apply custom RGB colors:

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

println!("{}", red!("Error: {}", "File not found"));

Colorful Status Message

println!("{} {} {}", green!("โœ“"), blue!("Building project:"), yellow!("in progress"));

Nested Color Formatting

println!("{}", white!("Status: {} | {}", green!("OK"), red!("Failed: {}", 3)));

Custom Color Gradient

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 file for details.


Happy coding! Hope it helps ๐Ÿฆ€