#ansi #ansi-codes #terminal #escaping #print #tool #color

rcolors

A simple terminal colorization/style tool written in Rust

1 unstable release

0.1.1 Sep 4, 2024
0.1.0 Sep 4, 2024

#402 in Command-line interface

MIT license

76KB
796 lines

RColors

Crates.io CC0 licensed Tests Clippy Rustfmt Release

RColor lets you use styled outputs in terms of ANSI Escape Codes in Rust.

Usage

Using Macros

The following colors are supported by macros: black, red, green, yellow, blue, magenta, cyan and white.

use rcolors::*;

fn main() {
    // like `print` but with color suffix
    print_red!("This is red print! ");
    
    // like `println` but with color suffix
    println_red!("This is red println!");

    // like `format`
    let x = red!("This is a value");
    println!("{}", x);
}

Using Builder

The builder makes it easier to build complex colored text sections. Unlike the macros, the builder also offers style ANSI codes. E.g.:

fn main() {
    Builder::new()
        .bold().fg_yellow().text("Language: ").reset()
        .fg_cyan().italic().text("Rust\n").reset()
        .bold().fg_yellow().text("Username: ").reset()
        .fg_cyan().italic().text("root\n").reset()
        .bold().fg_yellow().text("Password: ").reset()
        .fg_cyan().italic().text("********\n")
        // .print();
        // .println();
        .as_string();
}

Dependencies