stilo/
wrappers.rs

1/// Format stylized strings individually, concatenated.
2///
3/// Wrapper for `stylize_many!`
4#[macro_export]
5macro_rules! print_styles {
6    ( $( $arg: tt )* ) => {
7        print!("{}", $crate::stylize_many!($( $arg )*))
8    };
9}
10
11/// Format stylized strings individually, concatenated.
12///
13/// Wrapper for `stylize_many!`
14#[macro_export]
15macro_rules! println_styles {
16    ( $( $arg: tt )* ) => {
17        println!("{}", $crate::stylize_many!($( $arg )*))
18    };
19}
20
21/// Format stylized strings individually, concatenated.
22///
23/// Wrapper for `stylize_many!`
24#[macro_export]
25macro_rules! eprint_styles {
26    ( $( $arg: tt )* ) => {
27        eprint!("{}", $crate::stylize_many!($( $arg )*))
28    };
29}
30
31/// Format stylized strings individually, concatenated.
32///
33/// Wrapper for `stylize_many!`
34#[macro_export]
35macro_rules! eprintln_styles {
36    ( $( $arg: tt )* ) => {
37        eprintln!("{}", $crate::stylize_many!($( $arg )*))
38    };
39}
40
41/// Format stylized strings individually, concatenated.
42///
43/// Wrapper for `stylize_many!`
44#[macro_export]
45macro_rules! write_styles {
46    ( $f: expr, $( $arg: tt )* ) => {
47        write!($f, "{}", $crate::stylize_many!($( $arg )*))
48    };
49}
50
51/// Format stylized strings individually, concatenated.
52///
53/// Wrapper for `stylize_many!`
54#[macro_export]
55macro_rules! writeln_styles {
56    ( $f: expr, $( $arg: tt )* ) => {
57        writeln!($f, "{}", $crate::stylize_many!($( $arg )*))
58    };
59}
60
61#[cfg(test)]
62mod tests {
63    use crate::style;
64
65    #[test]
66    fn println_styles_compiles() {
67        let world = "World!";
68
69        println_styles!(
70            "Hello";
71            "\nHello": Red;
72            "\nHello": Blue+italic;
73            "\nHello": + i+b;
74            "\n";
75            "\nHello {}": Red, world;
76            "\nHello {}": Blue+italic, world;
77            "\nHello {}": +italic, world;
78            "\nHello {} {}": +underline+dim, world, 123;
79            "\nHello {world}": Green;
80            "\nHello {world:?}": Green+b;
81            "\nHello {} {}": Red, world, 123;
82            "\nHello {} {}": Red+d, world, 123;
83            "\nHello {world} {}", 123;
84        );
85
86        let style = style!(Yellow + italic);
87
88        println_styles!(
89            "Hello": {style!(Red)};
90            "Hello": {style};
91            "Hello": {style} if true;
92        );
93    }
94}