Skip to main content

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