may_clack/macros.rs
1/// Intro message.
2///
3/// Write a message to start a prompt session.
4///
5/// Can take either a [fmt](std::fmt) string like [`format!`], a type that implements [`std::fmt::Display`], or nothing.
6///
7/// # Examples
8///
9/// ```
10/// use may_clack::intro;
11///
12/// // empty
13/// intro!();
14/// // fmt string
15/// intro!("fmt {:?}", "string");
16/// // impl Display
17/// intro!("text");
18/// intro!(4);
19/// ```
20#[macro_export]
21macro_rules! intro {
22 () => {
23 println!("{}", *$crate::style::chars::BAR_START);
24 };
25 ($arg:expr) => {
26 $crate::intro!("{}", $arg);
27 };
28 ($($arg:tt)*) => {{
29 print!("{} ", *$crate::style::chars::BAR_START);
30 println!($($arg)*);
31 }}
32}
33
34/// Setup outro
35///
36/// Write a message to start a prompt session.
37///
38/// Can take either a [fmt](std::fmt) string like [`format!`], a type that implements [`std::fmt::Display`], or nothing.
39///
40/// # Examples
41///
42/// ```
43/// use may_clack::outro;
44///
45/// // empty
46/// outro!();
47/// // fmt string
48/// outro!("fmt {:?}", "string");
49/// // impl Display
50/// outro!("text");
51/// outro!(4);
52/// ```
53#[macro_export]
54macro_rules! outro {
55 () => {{
56 println!("{}", *$crate::style::chars::BAR);
57 println!("{}", *$crate::style::chars::BAR_END);
58 println!();
59 }};
60 ($arg:expr) => {
61 $crate::outro!("{}", $arg);
62 };
63 ($($arg:tt)*) => {{
64 println!("{}", *$crate::style::chars::BAR);
65 print!("{} ", *$crate::style::chars::BAR_END);
66 println!($($arg)*);
67 println!();
68 }};
69}
70
71/// Cancel message.
72///
73/// Write a message when cancelled.
74///
75/// Is the same as calling the [`outro!`] macro with `outro!("{}", message.red())`
76///
77/// # Examples
78///
79/// ```
80/// use may_clack::cancel;
81///
82/// cancel!("cancel");
83/// ```
84#[macro_export]
85macro_rules! cancel {
86 ($arg:expr) => {{
87 $crate::outro!("{}", $crate::owo_colors::OwoColorize::red(&$arg));
88 }};
89}
90
91/// Info message.
92///
93/// Write an info message while in a prompt session.
94///
95/// Can take either a [fmt](std::fmt) string like [`format!`], a type that implements [`std::fmt::Display`], or nothing.
96///
97/// # Examples
98///
99/// ```
100/// use may_clack::{info, intro, outro};
101///
102/// intro!("intro");
103/// // do stuff
104/// info!("info");
105/// // do stuff
106/// outro!();
107/// ```
108///
109/// ```
110/// use may_clack::info;
111///
112/// // empty
113/// info!();
114/// // fmt string
115/// info!("fmt {:?}", "string");
116/// // impl Display
117/// info!("text");
118/// info!(4);
119/// ```
120#[macro_export]
121macro_rules! info {
122 () => {{
123 println!("{}", *$crate::style::chars::BAR);
124 println!("{}", $crate::owo_colors::OwoColorize::cyan(&*$crate::style::chars::STEP_SUBMIT));
125 }};
126 ($arg:expr) => {
127 $crate::info!("{}", $arg);
128 };
129 ($($arg:tt)*) => {{
130 println!("{}", *$crate::style::chars::BAR);
131 print!("{} ", $crate::owo_colors::OwoColorize::cyan(&*$crate::style::chars::STEP_SUBMIT));
132 println!($($arg)*);
133 }}
134}
135
136/// Warn message.
137///
138/// Write a warning while in a prompt session.
139///
140/// Can take either a [fmt](std::fmt) string like [`format!`], a type that implements [`std::fmt::Display`], or nothing.
141///
142/// # Examples
143///
144/// ```
145/// use may_clack::{intro, outro, warn};
146///
147/// intro!("intro");
148/// // do stuff
149/// warn!("warn");
150/// // do stuff
151/// outro!();
152/// ```
153///
154/// ```
155/// use may_clack::warn;
156///
157/// // empty
158/// warn!();
159/// // fmt string
160/// warn!("fmt {:?}", "string");
161/// // impl Display
162/// warn!("text");
163/// warn!(4);
164/// ```
165#[macro_export]
166macro_rules! warn {
167 () => {{
168 println!("{}", *$crate::style::chars::BAR);
169 println!("{}", $crate::owo_colors::OwoColorize::yellow(&*$crate::style::chars::STEP_ERROR));
170 }};
171 ($arg:expr) => {
172 $crate::warn!("{}", $arg);
173 };
174 ($($arg:tt)*) => {{
175 println!("{}", *$crate::style::chars::BAR);
176 print!("{} ", $crate::owo_colors::OwoColorize::yellow(&*$crate::style::chars::STEP_ERROR));
177 println!($($arg)*);
178 }};
179}
180
181/// Error message.
182///
183/// Write an error while in a prompt session.
184///
185/// Can take either a [fmt](std::fmt) string like [`format!`], a type that implements [`std::fmt::Display`], or nothing.
186///
187/// # Examples
188///
189/// ```
190/// use may_clack::{err, intro, outro};
191///
192/// intro!("intro");
193/// // do stuff
194/// err!("err");
195/// // do stuff
196/// outro!();
197/// ```
198///
199/// ```
200/// use may_clack::err;
201///
202/// // empty
203/// err!();
204/// // fmt string
205/// err!("fmt {:?}", "string");
206/// // impl Display
207/// err!("text");
208/// err!(4);
209/// ```
210#[macro_export]
211macro_rules! err {
212 () => {{
213 println!("{}", *$crate::style::chars::BAR);
214 println!("{}", $crate::owo_colors::OwoColorize::red(&*$crate::style::chars::STEP_CANCEL));
215 }};
216 ($arg:expr) => {
217 $crate::err!("{}", $arg);
218 };
219 ($($arg:tt)*) => {{
220 println!("{}", *$crate::style::chars::BAR);
221 print!("{} ", $crate::owo_colors::OwoColorize::red(&*$crate::style::chars::STEP_CANCEL));
222 println!($($arg)*);
223 }};
224}