pistonite_cu/cli/progress/macros.rs
1/// Update a [progress bar](fn@crate::progress)
2///
3/// The macro takes 2 parts separated by comma `,`:
4/// - An expression for updating the progress:
5/// - Optional format args for updating the message.
6///
7/// The progress update expression can be one of:
8/// - `bar = i`: set the progress to `i`
9/// - `bar += i`: increment the steps by i
10/// - `bar`: don't update the progress
11///
12/// , where `bar` is an ident
13///
14/// The format args can be omitted to update the progress without
15/// updating the message
16///
17/// # Examples
18/// ```rust,no_run
19/// # use pistonite_cu as cu;
20/// let bar = cu::progress("10 steps").total(10).spawn();
21/// // update the current count and message
22/// let i = 1;
23/// cu::progress!(bar = i, "doing step {i}");
24/// // update the current count without changing message
25/// cu::progress!(bar += 2);
26/// // update the message without changing current step
27/// cu::progress!(bar, "doing the thing");
28/// ```
29#[macro_export]
30macro_rules! progress {
31 ($bar:ident, $($fmt_args:tt)*) => {
32 $bar.__inc(0u64, Some(format!($($fmt_args)*)))
33 };
34 ($bar:ident += $inc:expr) => {
35 $bar.__inc({ $inc } as u64, None)
36 };
37 ($bar:ident += $inc:expr, $($fmt_args:tt)*) => {
38 $bar.__inc({ $inc } as u64, Some(format!($($fmt_args)*)))
39 };
40 ($bar:ident = $x:expr) => {
41 $bar.__set({ $x } as u64, None)
42 };
43 ($bar:ident = $x:expr, $($fmt_args:tt)*) => {
44 $bar.__set({ $x } as u64, Some(format!($($fmt_args)*)))
45 };
46}