workflow_terminal/
macros.rs1use crate::terminal::Terminal;
2use std::sync::Arc;
3use workflow_log::style;
4
5#[inline(always)]
8pub fn tprint_impl<T>(term: T, args: &str)
9where
10 T: Into<Arc<Terminal>>,
11{
12 term.into().write(args);
13}
14
15#[inline(always)]
18pub fn tprintln_impl<T>(term: T, args: &str)
19where
20 T: Into<Arc<Terminal>>,
21{
22 term.into().writeln(args);
23}
24
25#[inline(always)]
28pub fn terrorln_impl<T>(term: T, args: &str)
29where
30 T: Into<Arc<Terminal>>,
31{
32 term.into()
33 .writeln(style(args.to_string()).red().to_string());
34}
35
36#[inline(always)]
39pub fn twarnln_impl<T>(term: T, args: &str)
40where
41 T: Into<Arc<Terminal>>,
42{
43 term.into()
44 .writeln(style(args.to_string()).yellow().to_string());
45}
46
47#[inline(always)]
50pub fn tpara_impl<T>(term: T, args: &str)
51where
52 T: Into<Arc<Terminal>>,
53{
54 term.into().para(args.to_string());
55}
56
57#[macro_export]
60macro_rules! twarnln {
61 ($target:expr_2021) => {
62 compile_error!("twarnln! macro requires at least two arguments");
63 };
64
65 ($dest:expr_2021, $($arg:tt)*) => {
66 $crate::twarnln_impl($dest.deref().clone(), &format_args!($($arg)*).to_string().as_str())
67 };
68}
69
70#[macro_export]
73macro_rules! terrorln {
74 ($target:expr_2021) => {
75 compile_error!("terrorln! macro requires at least two arguments");
76 };
77
78 ($dest:expr_2021, $($arg:tt)*) => {
79 $crate::terrorln_impl($dest.deref().clone(), &format_args!($($arg)*).to_string().as_str())
80 };
81}
82
83#[macro_export]
86macro_rules! tprintln {
87 ($dest:expr_2021) => {
88 $crate::tprintln_impl($dest.as_ref(), &"")
89 };
90
91 ($dest:expr_2021, $($arg:tt)*) => {
92 $crate::tprintln_impl($dest.deref().clone(), &format_args!($($arg)*).to_string().as_str())
93 };
94}
95
96#[macro_export]
99macro_rules! tprint {
100 ($dest:expr_2021) => {
101 $crate::tprint_impl($dest.as_ref(), &"")
102 };
103
104 ($dest:expr_2021, $($arg:tt)*) => {
105 $crate::tprint_impl($dest.deref().clone(), &format_args!($($arg)*).to_string().as_str())
106 };
107}
108
109#[macro_export]
112macro_rules! tpara {
113 ($target:expr_2021) => {
114 compile_error!("tpara! macro requires at least two arguments");
115 };
116
117 ($dest:expr_2021, $($arg:tt)*) => {
118 $crate::tpara_impl($dest.as_ref(), &format_args!($($arg)*).to_string().as_str())
119 };
120}