1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
use crate::style::chars;
use owo_colors::OwoColorize;
use std::fmt::Display;
#[doc(hidden)]
pub fn wr_intro(display: impl Display) {
println!("{} {}", *chars::BAR_START, display);
}
#[doc(hidden)]
pub fn wr_outro(display: impl Display) {
println!("{}", *chars::BAR);
println!("{} {}", *chars::BAR_END, display);
println!();
}
#[doc(hidden)]
pub fn wr_cancel(display: impl Display) {
println!("{}", *chars::BAR);
println!("{} {}", *chars::BAR_END, display.red());
println!();
}
#[doc(hidden)]
pub fn wr_info(display: impl Display) {
println!("{}", *chars::BAR);
println!("{} {}", (*chars::STEP_SUBMIT).cyan(), display);
}
/// Intro message.
///
/// Write a message to start a prompt session.
///
/// Can take either a [fmt](std::fmt) string like [`format!`], a type that implements [`Display`], or nothing.
///
/// # Examples
///
/// ```
/// use may_clack::intro;
///
/// // empty
/// intro!();
/// // fmt string
/// intro!("fmt {:?}", "string");
/// // impl Display
/// intro!("text");
/// intro!(4);
/// ```
#[macro_export]
macro_rules! intro {
() => {
$crate::misc::wr_intro("");
};
($arg:expr) => {
$crate::misc::wr_intro($arg);
};
($($arg:tt)*) => {
let text = format!($($arg)*);
$crate::misc::wr_intro(text);
}
}
/// Setup outro
///
/// Write a message to start a prompt session.
///
/// Can take either a [fmt](std::fmt) string like [`format!`], a type that implements [`Display`], or nothing.
///
/// # Examples
///
/// ```
/// use may_clack::outro;
///
/// // empty
/// outro!();
/// // fmt string
/// outro!("fmt {:?}", "string");
/// // impl Display
/// outro!("text");
/// outro!(4);
/// ```
#[macro_export]
macro_rules! outro {
() => {
$crate::misc::wr_outro("");
};
($arg:expr) => {
$crate::misc::wr_outro($arg);
};
($($arg:tt)*) => {
let text = format!($($arg)*);
$crate::misc::wr_outro(text);
};
}
/// Cancel message.
///
/// Write a message when cancelled.
///
/// Can take either a [fmt](std::fmt) string like [`format!`], a type that implements [`Display`], or nothing.
///
/// # Examples
///
/// ```
/// use may_clack::cancel;
///
/// // empty
/// cancel!();
/// // fmt string
/// cancel!("fmt {:?}", "string");
/// // impl Display
/// cancel!("text");
/// cancel!(4);
/// ```
#[macro_export]
macro_rules! cancel {
() => {
$crate::misc::wr_cancel("");
};
($arg:expr) => {
$crate::misc::wr_cancel($arg);
};
($($arg:tt)*) => {
let text = format!($($arg)*);
$crate::misc::wr_cancel(text);
}
}
/// Info message.
///
/// Write an info message while in a prompt session.
///
/// Can take either a [fmt](std::fmt) string like [`format!`], a type that implements [`Display`], or nothing.
///
/// # Examples
///
/// ```
/// use may_clack::{info, intro, outro};
///
/// intro!("intro");
/// // do stuff
/// info!("info");
/// // do stuff
/// outro!();
/// ```
///
/// ```
/// use may_clack::info;
///
/// // empty
/// info!();
/// // fmt string
/// info!("fmt {:?}", "string");
/// // impl Display
/// info!("text");
/// info!(4);
/// ```
#[macro_export]
macro_rules! info {
() => {
$crate::misc::wr_info("");
};
($arg:expr) => {
$crate::misc::wr_info($arg);
};
($($arg:tt)*) => {
let text = format!($($arg)*);
$crate::misc::wr_info(text);
}
}