boxy_cli/
macros.rs

1//! The boxy! macro
2
3/// Macro for creating a new Boxy struct
4///
5/// Currently, it has the following accepting fields:
6///
7///  - **type** - takes a [BoxType](crate::constructs::BoxType) enum
8///
9///  - **color** - takes a hex code for a color
10///
11///  - **external_pad** and **internal-pad** - take any integer or float value
12///
13///  - **alignment** - sets the alignment for the text inside the box. Takes a [BoxAlign](crate::constructs::BoxAlign) enum
14///
15///  - **segcount** - sets the number of segments in the textbox (not necessary to use)
16///
17/// # Example
18/// ```
19/// # use boxy_cli::prelude::*;
20/// # fn main() {
21/// // use the boxy macro
22/// let mut boxy = boxy!(type: BoxType::Double, color:"#00ffff", external_pad: 2, internal_pad: 1, alignment: BoxAlign::Left, segcount: 3);
23///
24/// // Adding text segments
25/// boxy.add_text_sgmt("Lorem ipsum dolor sit amet, consectetur adipiscing elit.", "#ffff", BoxAlign::Center);
26/// boxy.add_text_sgmt("et quasi architecto beatae vitae dicta sunt explicabo.", "#ffff", BoxAlign::Left);
27/// boxy.add_text_sgmt("Hello Theree", "#ffff", BoxAlign::Right);
28/// boxy.display();
29/// # }
30/// ```
31/// ! 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.
32/// 
33/// ! The padding values here are taken to be for uniform padding on all sides.
34#[macro_export]
35macro_rules! boxy {
36    ($($key:ident: $value:expr),* $(,)?) => {{
37        let mut boxy = Boxy::default();
38        $(
39            match stringify!($key) {
40                "type" => boxy.type_enum = resolve_type($value.to_string()),
41                "color" => boxy.box_col = resolve_col($value.to_string()),
42                "internal_pad" => boxy.int_padding = resolve_pad($value.to_string()),
43                "external_pad" => boxy.ext_padding = resolve_pad($value.to_string()),
44                "alignment" => boxy.align = resolve_align($value.to_string()),
45                "segcount" => boxy.tot_seg = resolve_segments($value.to_string()),
46                _ => panic!("Unknown field: {}", stringify!($key)),
47            }
48        )*
49        boxy
50    }};
51}