fansi/
lib.rs

1pub mod color;
2pub mod container;
3pub mod string;
4pub mod style;
5pub mod windows;
6
7#[cfg(test)]
8mod tests {
9    use crate::{color::AnsiColor, style::AnsiStyle, string::AnsiString, windows::enable_ansi_support, container::AnsiStyleContainer};
10
11    #[test]
12    fn test_bold() {
13        // Create style.
14        let style = vec![AnsiStyle::Bold];
15        // Create text with style.
16        let text = AnsiString::with_styles_vec("world!", style);
17        // Print text.
18        println!("Hello, {}", text);
19    }
20
21    #[test]
22    fn test_colors() {
23        // Create style.
24        let style = vec![AnsiStyle::ForegroundColor(AnsiColor::Green)];
25        // Create text with style.
26        let text = AnsiString::with_styles_vec("world!", style);
27        // Print text.
28        println!("Hello, {}", text);
29    }
30
31    #[test]
32    fn test_containers() {
33        // Create styles.
34        let style = vec![AnsiStyle::ForegroundColor(AnsiColor::Red)];
35        // Create container.
36        let container = AnsiStyleContainer::from_vec(style);
37        // Apply container's compiled style string to text.
38        let text = container.apply("world!");
39        // Print text.
40        println!("Hello, {}", text);
41    }
42
43    #[test]
44    fn test_windows_enable_ansi_support() {
45        let result = enable_ansi_support();
46        assert_eq!(result, Ok(()));
47    }
48}