1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
pub struct Table(comfy_table::Table);
impl Table {
#[allow(clippy::new_without_default)]
pub fn new() -> Self {
let mut tbl = comfy_table::Table::new();
tbl.load_preset(comfy_table::presets::NOTHING);
Self(tbl)
}
pub fn add_row<T: Into<comfy_table::Row>>(&mut self, row: T) -> &Self {
self.0.add_row(row);
self
}
}
impl std::fmt::Display for Table {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
writeln!(f, "{}", textwrap::indent(&self.0.trim_fmt(), " "))
}
}
#[macro_export]
macro_rules! parser {
($id: ident, $ret: ty, $body: expr) => {
impl $id {
pub fn parse() -> impl chumsky::Parser<
$crate::TagType,
$ret,
Error = chumsky::prelude::Simple<$crate::TagType>,
> {
$body
}
}
};
($id: ident, $body: expr) => {
$crate::parser!($id, Self, $body);
};
}
#[macro_export]
macro_rules! header {
($f:expr, $name:expr, $tag:expr) => {{
let len = $name.len();
if len > 40 || $tag.len() > 40 {
writeln!($f, "{:>80}", format!("*{}*", $tag))?;
writeln!($f, "{}", $name)
} else {
writeln!(
$f,
"{}{}",
$name,
format_args!("{:>w$}", format!("*{}*", $tag), w = 80 - len)
)
}
}};
($f:expr, $name:expr) => {
$crate::header!($f, $name, $name)
};
}
#[macro_export]
macro_rules! description {
($f:expr, $desc:expr) => {
writeln!($f, "{}", textwrap::indent($desc, " "))
};
}