workflow_terminal/
macros.rs

1use crate::terminal::Terminal;
2use std::sync::Arc;
3use workflow_log::style;
4
5#[inline(always)]
6pub fn tprint_impl<T>(term: T, args: &str)
7where
8    T: Into<Arc<Terminal>>,
9{
10    term.into().write(args);
11}
12
13#[inline(always)]
14pub fn tprintln_impl<T>(term: T, args: &str)
15where
16    T: Into<Arc<Terminal>>,
17{
18    term.into().writeln(args);
19}
20
21#[inline(always)]
22pub fn terrorln_impl<T>(term: T, args: &str)
23where
24    T: Into<Arc<Terminal>>,
25{
26    term.into()
27        .writeln(style(args.to_string()).red().to_string());
28}
29
30#[inline(always)]
31pub fn twarnln_impl<T>(term: T, args: &str)
32where
33    T: Into<Arc<Terminal>>,
34{
35    term.into()
36        .writeln(style(args.to_string()).yellow().to_string());
37}
38
39#[inline(always)]
40pub fn tpara_impl<T>(term: T, args: &str)
41where
42    T: Into<Arc<Terminal>>,
43{
44    term.into().para(args.to_string());
45}
46
47#[macro_export]
48macro_rules! twarnln {
49    ($target:expr) => {
50        compile_error!("twarnln! macro requires at least two arguments");
51    };
52
53    ($dest:expr, $($arg:tt)*) => {
54        $crate::twarnln_impl($dest.deref().clone(), &format_args!($($arg)*).to_string().as_str())
55    };
56}
57
58#[macro_export]
59macro_rules! terrorln {
60    ($target:expr) => {
61        compile_error!("terrorln! macro requires at least two arguments");
62    };
63
64    ($dest:expr, $($arg:tt)*) => {
65        $crate::terrorln_impl($dest.deref().clone(), &format_args!($($arg)*).to_string().as_str())
66    };
67}
68
69#[macro_export]
70macro_rules! tprintln {
71    ($dest:expr) => {
72        $crate::tprintln_impl($dest.as_ref(), &"")
73    };
74
75    ($dest:expr, $($arg:tt)*) => {
76        $crate::tprintln_impl($dest.deref().clone(), &format_args!($($arg)*).to_string().as_str())
77    };
78}
79
80#[macro_export]
81macro_rules! tprint {
82    ($dest:expr) => {
83        $crate::tprint_impl($dest.as_ref(), &"")
84    };
85
86    ($dest:expr, $($arg:tt)*) => {
87        $crate::tprint_impl($dest.deref().clone(), &format_args!($($arg)*).to_string().as_str())
88    };
89}
90
91#[macro_export]
92macro_rules! tpara {
93    ($target:expr) => {
94        compile_error!("tpara! macro requires at least two arguments");
95    };
96
97    ($dest:expr, $($arg:tt)*) => {
98        $crate::tpara_impl($dest.as_ref(), &format_args!($($arg)*).to_string().as_str())
99    };
100}