1use std::fmt;
4
5use log;
6
7const QSYM2_BANNER_LENGTH: usize = 103;
8
9macro_rules! qsym2_error {
11 ($fmt:expr $(, $($arg:tt)*)?) => {
12 log::error!($fmt, $($($arg)*)?);
13 log::error!(target: "qsym2-output", $fmt, $($($arg)*)?);
14 }
15}
16
17macro_rules! qsym2_warn {
19 ($fmt:expr $(, $($arg:tt)*)?) => { log::warn!(target: "qsym2-output", $fmt, $($($arg)*)?); }
20}
21
22macro_rules! qsym2_output {
24 ($fmt:expr $(, $($arg:tt)*)?) => { log::info!(target: "qsym2-output", $fmt, $($($arg)*)?); }
25}
26
27pub(crate) use {qsym2_error, qsym2_output, qsym2_warn};
28
29pub(crate) fn write_title(f: &mut fmt::Formatter<'_>, title: &str) -> fmt::Result {
31 let length = title.chars().count().max(QSYM2_BANNER_LENGTH - 6);
32 let bar = "─".repeat(length);
33 writeln!(f, "┌──{bar}──┐")?;
34 writeln!(f, "│§ {title:^length$} §│")?;
35 writeln!(f, "└──{bar}──┘")?;
36 Ok(())
37}
38
39pub(crate) fn log_title(title: &str) {
41 let length = title.chars().count().max(QSYM2_BANNER_LENGTH - 6);
42 let bar = "─".repeat(length);
43 qsym2_output!("┌──{bar}──┐");
44 qsym2_output!("│§ {title:^length$} §│");
45 qsym2_output!("└──{bar}──┘");
46}
47
48pub(crate) fn write_subtitle(f: &mut fmt::Formatter<'_>, subtitle: &str) -> fmt::Result {
50 let length = subtitle.chars().count();
51 let bar = "═".repeat(length);
52 writeln!(f, "{subtitle}")?;
53 writeln!(f, "{bar}")?;
54 Ok(())
55}
56
57pub(crate) fn log_subtitle(subtitle: &str) {
59 let length = subtitle.chars().count();
60 let bar = "═".repeat(length);
61 qsym2_output!("{}", subtitle);
62 qsym2_output!("{}", bar);
63}
64
65pub(crate) fn log_macsec_begin(sectitle: &str) {
67 let width = QSYM2_BANNER_LENGTH - 14;
68 let sectitle_space = sectitle.to_string() + " ";
69 qsym2_output!("❬❬❬❬❬ [Begin] {sectitle_space:❬<width$}");
70}
71
72pub(crate) fn log_macsec_end(sectitle: &str) {
74 let width = QSYM2_BANNER_LENGTH - 14;
75 let sectitle_space = sectitle.to_string() + " ";
76 qsym2_output!("❭❭❭❭❭ [ End ] {sectitle_space:❭<width$}");
77}
78
79pub(crate) fn log_micsec_begin(sectitle: &str) {
81 let width = QSYM2_BANNER_LENGTH - 14;
82 let sectitle_space = sectitle.to_string() + " ";
83 qsym2_output!("‹‹‹‹‹ [Begin] {sectitle_space:‹<width$}");
84}
85
86pub(crate) fn log_micsec_end(sectitle: &str) {
88 let width = QSYM2_BANNER_LENGTH - 14;
89 let sectitle_space = sectitle.to_string() + " ";
90 qsym2_output!("››››› [ End ] {sectitle_space:›<width$}");
91}
92
93pub(crate) fn nice_bool(b: bool) -> String {
95 if b {
96 "yes".to_string()
97 } else {
98 "no".to_string()
99 }
100}
101
102pub(crate) trait QSym2Output: fmt::Debug + fmt::Display {
104 fn log_output_display(&self) {
106 let lines = self.to_string();
107 lines.lines().for_each(|line| {
108 qsym2_output!("{line}");
109 })
110 }
111
112 fn log_output_debug(&self) {
114 let lines = format!("{self:?}");
115 lines.lines().for_each(|line| {
116 qsym2_output!("{line}");
117 })
118 }
119}
120
121impl<T> QSym2Output for T where T: fmt::Debug + fmt::Display {}