boxy_cli/
macros.rs

1// boxy macro
2/// Macro for creating a new Boxy struct
3/// 
4/// # Example
5/// ```
6/// # use boxy::prelude::*;
7/// # fn main() {
8/// // use the boxy macro
9/// let boxy = boxy!(type: BoxType::Double, color:"#00ffff", external_pad: 2, internal_pad: 1, alignment: BoxAlign::Left, segcount: 3);
10///
11/// // Adding text segments
12/// boxy.add_text_sgmt("Lorem ipsum dolor sit amet, consectetur adipiscing elit.", "#ffff");
13/// boxy.add_text_sgmt("et quasi architecto beatae vitae dicta sunt explicabo.", "#ffff");
14/// boxy.add_text_sgmt("Hello Theree", "#ffff");
15/// boxy.display();
16/// # }
17/// ```
18/// ! the segcount sets the number of segments in the box. If text for only two segments is provided, the third segment will be displayed empty.
19/// 
20/// ! the padding values here are taken to be for uniform padding on all sides.
21#[macro_export]
22macro_rules! boxy {
23    ($($key:ident: $value:expr),* $(,)?) => {{
24        let mut boxy = Boxy::default();
25        $(
26            match stringify!($key) {
27                "type" => boxy.type_enum = resolve_type($value.to_string()),
28                "color" => boxy.box_col = resolve_col($value.to_string()),
29                "internal_pad" => boxy.int_padding = resolve_pad($value.to_string()),
30                "external_pad" => boxy.ext_padding = resolve_pad($value.to_string()),
31                "alignment" => boxy.align = resolve_align($value.to_string()),
32                "segcount" => boxy.tot_seg = resolve_segments($value.to_string()),
33                _ => panic!("Unknown field: {}", stringify!($key)),
34            }
35        )*
36        boxy
37    }};
38}