1pub const BOLD: ColorInstruction = ColorInstruction::One(1);
8pub const INVERTED: ColorInstruction = ColorInstruction::One(7);
9pub const BLACK: ColorInstruction = ColorInstruction::One(30);
10pub const RED: ColorInstruction = ColorInstruction::One(31);
11pub const GREEN: ColorInstruction = ColorInstruction::One(32);
12pub const YELLOW: ColorInstruction = ColorInstruction::One(33);
13pub const BLUE: ColorInstruction = ColorInstruction::One(34);
14pub const PURPLE: ColorInstruction = ColorInstruction::One(35);
15pub const CYAN: ColorInstruction = ColorInstruction::One(36);
16pub const WHITE: ColorInstruction = ColorInstruction::One(37);
17pub const GRAY: ColorInstruction = ColorInstruction::One(90);
18pub const ON_BLACK: ColorInstruction = ColorInstruction::One(40);
19pub const ON_RED: ColorInstruction = ColorInstruction::One(41);
20pub const ON_GREEN: ColorInstruction = ColorInstruction::One(42);
21pub const ON_YELLOW: ColorInstruction = ColorInstruction::One(43);
22pub const ON_BLUE: ColorInstruction = ColorInstruction::One(44);
23pub const ON_PURPLE: ColorInstruction = ColorInstruction::One(45);
24pub const ON_CYAN: ColorInstruction = ColorInstruction::One(46);
25pub const ON_WHITE: ColorInstruction = ColorInstruction::One(47);
26pub const BLACK_ON_RED: ColorInstruction = ColorInstruction::Two(30, 41);
27pub const BLACK_ON_GREEN: ColorInstruction = ColorInstruction::Two(30, 42);
28pub const BLACK_ON_YELLOW: ColorInstruction = ColorInstruction::Two(30, 43);
29pub const BLACK_ON_BLUE: ColorInstruction = ColorInstruction::Two(30, 44);
30pub const BLACK_ON_PURPLE: ColorInstruction = ColorInstruction::Two(30, 45);
31pub const BLACK_ON_CYAN: ColorInstruction = ColorInstruction::Two(30, 46);
32pub const BLACK_ON_WHITE: ColorInstruction = ColorInstruction::Two(30, 47);
33pub const RED_ON_BLACK: ColorInstruction = ColorInstruction::Two(31, 40);
34pub const RED_ON_GREEN: ColorInstruction = ColorInstruction::Two(31, 42);
35pub const RED_ON_YELLOW: ColorInstruction = ColorInstruction::Two(31, 43);
36
37pub enum ColorInstruction {
42 One(u8),
43 Two(u8, u8)
44}
45
46pub fn paint(text: impl Into<String>, color: ColorInstruction) -> String {
58 match color {
59 ColorInstruction::One(font_color) => format!("\x1b[{}m{}\x1b[0m", font_color, text.into()),
60 ColorInstruction::Two(font_color, background_color) => format!("\x1b[{};{}m{}\x1b[0m", font_color, background_color, text.into()),
61 }
62}
63
64pub fn color_print(text: impl Into<String>, color: ColorInstruction) {
66 print!("{}", paint(text, color))
67}
68
69pub fn color_println(text: impl Into<String>, color: ColorInstruction) {
71 println!("{}", paint(text, color))
72}