anscape/seq/
styles.rs

1//! # Graphics Modes
2//! Note: Some terminals may not support some of the graphic mode sequences listed above.
3
4/// # Macros for building basic style constants
5///
6/// It generate 2 constants per provided style.
7///
8/// For example, `pub DIM:"2"` will generate:
9///
10/// `pub const DIM:&str = "\x1b[2m"`
11///
12/// `pub const DIM_RST:&str = "\x1b[22m"`
13///
14/// **_RST** - reset style sufix\
15///
16/// ### Usage example:
17/// ```
18/// use anscape::styles;
19/// styles! {
20///     pub DIM:"2"
21/// }
22/// ```
23#[macro_export]
24macro_rules! styles {
25    ($($vis:vis $cname:ident:$cval:literal)*) => {
26        use paste::paste;
27        paste!{
28            $(
29                #[doc="Set " $cname " mode"]
30                $vis const $cname:&str = concat!("\x1b[", $cval,"m");
31                #[doc="Reset " $cname " mode"]
32                $vis const [<$cname _RST>]:&'static str = concat!("\x1b[","2",$cval,"m");
33            )*
34        }
35    };
36}
37
38#[doc = "Set BOLD mode"]
39pub const BOLD: &str = "\x1b[1m";
40#[doc = "Reset BOLD mode"]
41pub const BOLD_RST: &str = "\x1b[22m";
42
43styles! {
44     pub DIM:"2"
45     pub ITALIC:"3"
46     pub UNDERLINE:"4"
47     pub BLINKING:"5"
48     pub INVERSE:"7"
49     pub HIDDEN:"8"
50     pub STRIKETHROUGH:"9"
51}