logicaffeine_language/
style.rs1pub struct Style;
8
9impl Style {
10 pub const RESET: &'static str = "\x1b[0m";
11 pub const BOLD: &'static str = "\x1b[1m";
12 pub const RED: &'static str = "\x1b[31m";
13 pub const GREEN: &'static str = "\x1b[32m";
14 pub const YELLOW: &'static str = "\x1b[33m";
15 pub const BLUE: &'static str = "\x1b[34m";
16 pub const CYAN: &'static str = "\x1b[36m";
17
18 pub fn red(s: &str) -> String {
19 format!("{}{}{}", Self::RED, s, Self::RESET)
20 }
21
22 pub fn blue(s: &str) -> String {
23 format!("{}{}{}", Self::BLUE, s, Self::RESET)
24 }
25
26 pub fn cyan(s: &str) -> String {
27 format!("{}{}{}", Self::CYAN, s, Self::RESET)
28 }
29
30 pub fn yellow(s: &str) -> String {
31 format!("{}{}{}", Self::YELLOW, s, Self::RESET)
32 }
33
34 pub fn green(s: &str) -> String {
35 format!("{}{}{}", Self::GREEN, s, Self::RESET)
36 }
37
38 pub fn bold(s: &str) -> String {
39 format!("{}{}{}", Self::BOLD, s, Self::RESET)
40 }
41
42 pub fn bold_red(s: &str) -> String {
43 format!("{}{}{}{}", Self::BOLD, Self::RED, s, Self::RESET)
44 }
45}
46
47#[cfg(test)]
48mod tests {
49 use super::*;
50
51 #[test]
52 fn red_wraps_string() {
53 let result = Style::red("error");
54 assert!(result.contains("\x1b[31m"));
55 assert!(result.contains("error"));
56 assert!(result.contains("\x1b[0m"));
57 }
58
59 #[test]
60 fn bold_red_combines_codes() {
61 let result = Style::bold_red("Error");
62 assert!(result.contains("\x1b[1m"));
63 assert!(result.contains("\x1b[31m"));
64 }
65}