rustcolor/
lib.rs

1/*!
2# Rust Color
3Rust Color is a terminal color rendering library,
4thats supports 3/4 bit colors, 8 bit colors, 24 bit color
5rendering output, compatible with windows.
6
7## ANSI Escape Codes for Terminal Graphics
8The ANSI escape code standard, formally adopted as ISO/IEC 6429, defines a series of control sequences.
9Each control sequence begins with a **Control Sequence Introducer** (CSI), defined as a scape character
10followed immediately by a bracket: **ESC[**.
11*/
12pub mod color;
13
14pub mod macros;
15pub mod printer;
16pub mod style;
17
18#[cfg(test)]
19mod tests {
20    use super::*;
21    use crate::color::*;
22    use printer::*;
23
24    #[test]
25    fn test_color16_printer() {
26        let red_fg_text = "this is a red foreground color text".print_c16(FG_RED, BG_BLACK);
27
28        assert_eq!(
29            "\u{001b}[31;40mthis is a red foreground color text\u{001b}[0m",
30            red_fg_text
31        );
32    }
33
34    #[test]
35    fn test_color256_printer() {
36        let red_fg_text = "this is a red foreground color text".print_c256(1, 0);
37
38        let expected = "\u{001b}[38;5;1;48;5;0mthis is a red foreground color text\u{001b}[0m";
39        assert_eq!(expected, red_fg_text);
40    }
41
42    #[test]
43    fn test_default_3bit_color() {
44        let error_text = "white text with red bg".error();
45        let mut expected = "\u{001b}[37;41mwhite text with red bg\u{001b}[0m";
46        assert_eq!(expected, error_text);
47
48        let primary_text = "blue text with primary style".primary();
49        expected = "\u{001b}[34;49mblue text with primary style\u{001b}[0m";
50        assert_eq!(expected, primary_text);
51
52        let danger = "red text with danger style".danger();
53        expected = "\u{001b}[31;49mred text with danger style\u{001b}[0m";
54        assert_eq!(expected, danger);
55
56        let info_text = "green text with info style".info();
57        expected = "\u{001b}[32;49mgreen text with info style\u{001b}[0m";
58        assert_eq!(expected, info_text);
59
60        let warn_text = "yellow text with warn style".warn();
61        expected = "\u{001b}[33;49myellow text with warn style\u{001b}[0m";
62        assert_eq!(expected, warn_text);
63
64        let blink_text = "this is a text with blink style".blink();
65        expected = "\u{001b}[31;5mthis is a text with blink style\u{001b}[0m";
66        assert_eq!(expected, blink_text);
67
68        let underlined_text = "this is a text with underlined style".underline();
69        expected = "\u{001b}[33;4mthis is a text with underlined style\u{001b}[0m";
70        assert_eq!(expected, underlined_text);
71    }
72
73    #[test]
74    fn test_darken() {
75        let result = darken(FG_LIGHT_RED);
76        assert_eq!(FG_RED, result);
77    }
78
79    #[test]
80    fn test_lighten() {
81        let result = lighten(FG_RED);
82        assert_eq!(FG_LIGHT_RED, result);
83    }
84
85    #[test]
86    fn test_info_macro() {
87        info!("this is an info text");
88    }
89
90    #[test]
91    fn test_primary_macro() {
92        primary!("this is a primary text");
93    }
94
95    #[test]
96    fn test_warn_macro() {
97        warn!("this is a warn text");
98    }
99
100    #[test]
101    fn test_danger_macro() {
102        danger!("this is a danger text");
103    }
104
105    #[test]
106    fn test_error_macro() {
107        error!("this is an error text");
108    }
109
110    #[test]
111    fn test_blink_macro() {
112        blink!("this is a blink text");
113    }
114
115    #[test]
116    fn test_underline_macro() {
117        underline!("this is an underline text");
118    }
119}