1const ANSI_RESET: &str = "\x1b[0m"; #[derive(Debug, Clone, Copy)]
5pub enum Color {
6 Red,
7 Green,
8 Blue,
9 Yellow,
10 Magenta,
11 Cyan,
12 White,
13}
14
15impl Color {
17 fn code(&self) -> &str {
19 match self {
20 Color::Red => "\x1b[1;31m",
21 Color::Green => "\x1b[1;32m",
22 Color::Blue => "\x1b[1;34m",
23 Color::Yellow => "\x1b[1;33m",
24 Color::Magenta => "\x1b[1;35m",
25 Color::Cyan => "\x1b[1;36m",
26 Color::White => "\x1b[1;37m",
27 }
28 }
29}
30
31pub fn color_println(color: Color, text: &str) {
33 println!("{}{}{}", color.code(), text, ANSI_RESET);
34}
35
36pub fn color_println_fmt(color: Color, text: &str) -> String {
38 format!("{}{}{}", color.code(), text, ANSI_RESET)
39}