crossterm-rs / crossterm

Cross platform terminal library rust
MIT License
3.28k stars 281 forks source link

Add doc: how to use SetForegroundColor() in println! macro #827

Open bestia-dev opened 1 year ago

bestia-dev commented 1 year ago

I have an old project where I used to insert ansi codes into println!() like this:

// ANSI colors for Linux terminal
pub const YELLOW: &str = "\x1b[33m";
pub const GREEN: &str = "\x1b[32m";
pub const RESET: &str = "\x1b[0m";

println!(r#"{YELLOW} Yellow {RESET} White {GREEN} Green {RESET}"#);

I struggled to find documentation how to do the same with crossterm. I discovered it on my own and I would like to add it to the documentation of Module crossterm::style.

println!(r#"{yellow} Yellow {reset} White {green} Green {reset}"#,
    green= crossterm::style::SetForegroundColor(crossterm::style::Color::Green),
    yellow= crossterm::style::SetForegroundColor(crossterm::style::Color::Yellow),
    reset= crossterm::style::ResetColor,
);

May I write a PR just for the doc-comments?

//! Displayable:
//! 
//! SetForegroundColor() can be used in println! macro like:
//! 
//! println!(r#"{yellow} Yellow {reset} White {green} Green {reset}"#,
//!     green= crossterm::style::SetForegroundColor(crossterm::style::Color::Green),
//!     yellow= crossterm::style::SetForegroundColor(crossterm::style::Color::Yellow),
//!     reset= crossterm::style::ResetColor,
//! );