Skip to content

shubhexists/term_ansi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

16 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌈 term_ansi

Crates.io Documentation License: MIT

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:

[dependencies]
term_ansi = "0.2.5"

πŸš€ 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"));

Background Colors

Apply background colors to your text:

println!("{}", bg_yellow!("This has a yellow background"));
println!("{}", bg_cyan!("This has a cyan background"));

Text Styles

Apply text styles:

println!("{}", bold!("This text is bold"));
println!("{}", italic!("This text is italic"));
println!("{}", underline!("This text is underlined"));

Custom Colors

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

Nested Formatting

Combine multiple styles and colors:

println!("{}", red!("{}", bg_white!("{}" bold!("Important: {}"), "Read this!")));

πŸ“š 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 colors
  • bg_rgb!, bg_hsl!, bg_hsv!: Custom background colors

πŸ’‘ Examples

Error Message with Style

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

Colorful Status Message

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

Custom Color Gradient

for i in 0..=255 {
    print!("{}", rgb!(i, 0, 255 - i, "β–ˆ"));
}
println!();

Complex Nested Formatting

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

🀝 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! πŸ¦€πŸŒˆ

About

A compilation of Rust Macros to implement ANSI Colour Encodings

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages