1pub mod colors {
7 pub const RESET: &str = "\x1b[0m";
8 pub const BOLD: &str = "\x1b[1m";
9 pub const BLUE: &str = "\x1b[36;1m";
10 pub const YELLOW: &str = "\x1b[33;1m";
11 pub const PINK: &str = "\x1b[38;5;200m";
12 pub const GREEN: &str = "\x1b[32;1m";
13 pub const RED: &str = "\x1b[31;1m";
14}
15
16pub fn print_colored_text(text: &str, color: Option<&str>) {
18 match color {
19 Some(color) => println!("{}{}{}", color, text, colors::RESET),
20 None => println!("{text}"),
21 }
22}
23
24pub fn print_bold_text(text: &str) {
26 println!("{}{}{}", colors::BOLD, text, colors::RESET);
27}
28
29pub fn get_color_mapping(
31 items: &[String],
32 excluded_colors: Option<&[String]>,
33) -> std::collections::HashMap<String, String> {
34 let available_colors = vec![
35 "blue".to_string(),
36 "yellow".to_string(),
37 "pink".to_string(),
38 "green".to_string(),
39 "red".to_string(),
40 ];
41
42 let mut colors = available_colors;
43 if let Some(excluded) = excluded_colors {
44 colors.retain(|c| !excluded.contains(c));
45 }
46
47 let mut mapping = std::collections::HashMap::new();
48 for (i, item) in items.iter().enumerate() {
49 let color = &colors[i % colors.len()];
50 mapping.insert(item.clone(), color.clone());
51 }
52
53 mapping
54}
55
56pub fn get_colored_text(text: &str, color: &str) -> String {
58 let color_code = match color {
59 "blue" => colors::BLUE,
60 "yellow" => colors::YELLOW,
61 "pink" => colors::PINK,
62 "green" => colors::GREEN,
63 "red" => colors::RED,
64 _ => colors::RESET,
65 };
66 format!("{}{}{}", color_code, text, colors::RESET)
67}
68
69pub fn get_bolded_text(text: &str) -> String {
71 format!("{}{}{}", colors::BOLD, text, colors::RESET)
72}