term_colr 0.1.0

A super fast short one-liner about your crate
Documentation
  • Coverage
  • 20.69%
    6 out of 29 items documented6 out of 13 items with examples
  • Size
  • Source code size: 17.29 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.87 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 13s Average build duration of successful builds.
  • all releases: 13s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Documentation
  • Shivrajsoni/term_colr
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Shivrajsoni

term_colr

A simple Rust library for adding color to your terminal output using ASCII escape codes.

Features

  • Easy to use macros for coloring text.
  • Supports foreground and background colors.
  • Supports text formatting like bold, underline and italic.
  • Supports RGB, HSL, and HSV colors.
  • Nestable colors.

Usage

Add this to your Cargo.toml:

[dependencies]
term_colr = "0.1.0"

And then in your code:

use term_colr::{red, blue, green, bg_yellow, bold, italic, underline, rgb, hsl, hsv, bg_rgb, bg_hsl, bg_hsv};

fn main() {
    println!("This is the default color.");
    println!("{}", red!("This is red!"));
    println!("{}", blue!("This is blue!"));
    println!("{}", green!("This is green!"));
    println!("{}", bg_yellow!("This has a yellow background!"));
    println!("{} and this is also red!", red!("This is red"));
    println!("{}", blue!("This is blue {}!", green!("and this is green")));
    println!("{}", bold!("This is bold text."));
    println!("{}", italic!("This is italic text."));
    println!("{}", underline!("This is underlined text."));
    println!("{}", rgb!(255, 0, 0, "This is bright red using RGB!"));
    println!("{}", hsl!(120.0, 1.0, 0.5, "This is green using HSL!"));
    println!("{}", hsv!(240.0, 1.0, 1.0, "This is blue using HSV!"));
    println!("{}", bg_rgb!(100, 150, 200, "Custom background color using RGB!"));
    println!("{}", bg_hsl!(180.0, 0.5, 0.5, "Custom background color using HSL!"));
    println!("{}", bg_hsv!(270.0, 0.7, 0.9, "Custom background color using HSV!"));
}

Available Macros and Functions

Foreground Colors

  • black!(...)
  • red!(...)
  • green!(...)
  • yellow!(...)
  • blue!(...)
  • white!(...)

Background Colors

  • bg_red!(...)
  • bg_green!(...)
  • bg_blue!(...)
  • bg_yellow!(...)
  • bg_gray!(...)

Formatting

  • bold!(...)
  • italic!(...)
  • underline!(...)

Advanced Colors

RGB

  • rgb!(r, g, b, ...): Applies a foreground color using RGB values.
  • bg_rgb!(r, g, b, ...): Applies a background color using RGB values.

Example:

println!("{}", rgb!(255, 0, 0, "This is bright red"));
println!("{}", bg_rgb!(0, 0, 255, "This has a blue background"));

HSL

  • hsl!(h, s, l, ...): Applies a foreground color using HSL values.
  • bg_hsl!(h, s, l, ...): Applies a background color using HSL values.

Example:

println!("{}", hsl!(120.0, 1.0, 0.5, "This is green"));
println!("{}", bg_hsl!(0.0, 0.0, 0.5, "This has a gray background"));

HSV

  • hsv!(h, s, v, ...): Applies a foreground color using HSV values.
  • bg_hsv!(h, s, v, ...): Applies a background color using HSV values.

Example:

println!("{}", hsv!(240.0, 1.0, 1.0, "This is blue"));
println!("{}", bg_hsv!(300.0, 0.5, 0.7, "This has a purple background"));

Utility Functions

These functions are public and can be used for color conversions if needed.

  • hsl_to_rgb(h: f64, s: f64, l: f64) -> (u8, u8, u8): Converts HSL color values to RGB.
  • hsv_to_rgb(h: f64, s: f64, v: f64) -> (u8, u8, u8): Converts HSV color values to RGB.
  • reset_all() -> &'static str: Returns the ANSI code to reset all terminal formatting.