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