use colored::*;
pub fn red(text: &str) -> ColoredString {
text.red()
}
pub fn green(text: &str) -> ColoredString {
text.green()
}
pub fn blue(text: &str) -> ColoredString {
text.blue()
}
pub fn yellow(text: &str) -> ColoredString {
text.yellow()
}
pub fn purple(text: &str) -> ColoredString {
text.purple()
}
pub fn cyan(text: &str) -> ColoredString {
text.cyan()
}
pub fn white(text: &str) -> ColoredString {
text.white()
}
pub fn black(text: &str) -> ColoredString {
text.black()
}
pub fn bold(text: &str) -> ColoredString {
text.bold()
}
pub fn italic(text: &str) -> ColoredString {
text.italic()
}
pub fn underline(text: &str) -> ColoredString {
text.underline()
}
pub fn dimmed(text: &str) -> ColoredString {
text.dimmed()
}
pub fn blink(text: &str) -> ColoredString {
text.blink()
}
pub fn reversed(text: &str) -> ColoredString {
text.reversed()
}
pub fn strikethrough(text: &str) -> ColoredString {
text.strikethrough()
}
pub fn rgb(text: &str, r: u8, g: u8, b: u8) -> ColoredString {
text.truecolor(r, g, b)
}
pub fn custom_style(text: &str, styles: &[&str]) -> ColoredString {
let mut colored_text = ColoredString::from(text);
for style in styles {
colored_text = match *style {
"red" => colored_text.red(),
"green" => colored_text.green(),
"blue" => colored_text.blue(),
"yellow" => colored_text.yellow(),
"purple" => colored_text.purple(),
"cyan" => colored_text.cyan(),
"white" => colored_text.white(),
"black" => colored_text.black(),
"bold" => colored_text.bold(),
"italic" => colored_text.italic(),
"underline" => colored_text.underline(),
"dimmed" => colored_text.dimmed(),
"blink" => colored_text.blink(),
"reversed" => colored_text.reversed(),
"strikethrough" => colored_text.strikethrough(),
_ => colored_text, };
}
colored_text
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_basic_colors() {
let red_text = red("Hello");
assert!(red_text.to_string().contains("Hello"));
let green_text = green("World");
assert!(green_text.to_string().contains("World"));
}
#[test]
fn test_styles() {
let bold_text = bold("Bold");
assert!(bold_text.to_string().contains("Bold"));
let italic_text = italic("Italic");
assert!(italic_text.to_string().contains("Italic"));
}
#[test]
fn test_rgb() {
let rgb_text = rgb("RGB Color", 255, 128, 64);
assert!(rgb_text.to_string().contains("RGB Color"));
}
#[test]
fn test_custom_style() {
let styled_text = custom_style("Styled", &["red", "bold"]);
assert!(styled_text.to_string().contains("Styled"));
}
}