You can use the colored
crate to do this. Here is a simple example. with multiple colors and formats:
use colored::Colorize;
fn main() {
println!(
"{}, {}, {}, {}, {}, {}, and some normal text.",
"Bold".bold(),
"Red".red(),
"Yellow".yellow(),
"Green Strikethrough".green().strikethrough(),
"Blue Underline".blue().underline(),
"Purple Italics".purple().italic()
);
}
Sample color output:
Each of the format functions (red()
, italics()
, etc.) can be used on it’s own as well as in combination with others. But if you use colors in combination with each other, only the last color to be set shows.