4 stable releases

1.2.1 May 24, 2024
1.2.0 Jun 24, 2023
1.1.0 Oct 19, 2022
1.0.0 Oct 18, 2022

#1064 in Command line utilities

26 downloads per month
Used in 2 crates (via pretty-format)

MIT license

24KB
574 lines

ansi-style

CI rust-clippy analyze

ANSI escape codes for styling strings in the terminal

Adding ansi-style as a dependency

[dependencies]
ansi-style = "1.2.1"

Usage

use ansi_style::{Color, Style};

fn main() {
    // You can either color the text directly with the Color enumeration
    println!(
        "{}Cyan colored \"Hello World!\"{}",
        Color::Cyan.open(),
        Color::Cyan.close()
    );

    // or you can use the builder function from within the Style stuct
    // to create a style that can be used for more than one instance of
    // a string and you wouldn't need to have an open and close function
    // prepended and appended to every text you type like the above example

    let style = Style::builder().red().strikethrough().build();

    println!(
        "{}",
        style.stylize("Hello World in red with strikethrough")
    )
}

No runtime deps