Skip to main content

intelli_shell/utils/
mod.rs

1/// Macro to format an error message with theme's error style.
2///
3/// # Examples
4/// ```rust
5/// # use intelli_shell::format_error;
6/// # use intelli_shell::config::Theme;
7/// # let theme = Theme::default();
8/// let msg = format_error!(theme, "Invalid value");
9/// let msg = format_error!(theme, "Invalid value: {}", 42);
10/// ```
11#[macro_export]
12macro_rules! format_error {
13    ($theme:expr, $($arg:tt)*) => {
14        format!("{}{}", $theme.error.apply("[Error] "), format!($($arg)*))
15    }
16}
17
18/// Macro to format an information message with theme's style.
19///
20/// # Examples
21/// ```rust
22/// # use intelli_shell::format_msg;
23/// # use intelli_shell::config::Theme;
24/// # let theme = Theme::default();
25/// let msg = format_msg!(theme, "Succesful operation");
26/// ```
27#[macro_export]
28macro_rules! format_msg {
29    ($theme:expr, $($arg:tt)*) => {
30        format!("{}{}", $theme.accent.apply("-> "), format!($($arg)*))
31    }
32}
33
34/// Declares a `mod` and uses it
35#[macro_export]
36macro_rules! using {
37    ($($v:vis $p:ident),* $(,)?) => {
38        $(
39            mod $p;
40            $v use self::$p::*;
41        )*
42    }
43}
44
45/// Extension trait to provide a consistent "tag" string representation for versions.
46pub trait VersionExt {
47    /// Returns a string representation of the version in the format "vX.Y.Z"
48    fn to_tag(&self) -> String;
49}
50
51impl VersionExt for semver::Version {
52    fn to_tag(&self) -> String {
53        format!("v{self}")
54    }
55}
56
57using! {
58    pub process,
59    pub string,
60    pub tags,
61    pub fuzzy,
62    pub variable,
63    pub widget,
64    pub history,
65    pub completion,
66    pub import_export,
67    pub installation,
68    pub markdown,
69}