use colored::Colorize;
#[macro_export]
macro_rules! format_cargo {
($fmt:literal, $($arg:tt)*) => {
$crate::utils::cargo_style::get_cargo_info_format(format!($fmt, $($arg)*))
};
($cmd:expr) => {
$crate::utils::cargo_style::get_cargo_info_format($cmd)
};
}
#[macro_export]
macro_rules! eformat_cargo {
($fmt:literal, $($arg:tt)*) => {
$crate::utils::cargo_style::get_cargo_error_format(format!($fmt, $($arg)*))
};
($cmd:expr) => {
$crate::utils::cargo_style::get_cargo_error_format($cmd)
};
}
#[macro_export]
macro_rules! hformat_cargo {
($fmt:literal, $($arg:tt)*) => {
$crate::utils::cargo_style::get_cargo_help_format(format!($fmt, $($arg)*))
};
($cmd:expr) => {
$crate::utils::cargo_style::get_cargo_help_format($cmd)
};
}
#[macro_export]
macro_rules! println_cargo {
($buf:ident, $fmt:literal, $($arg:tt)*) => {
::mingling::macros::r_println!($buf, "{}", $crate::utils::cargo_style::get_cargo_info_format(format!($fmt, $($arg)*)))
};
($buf:ident, $cmd:expr) => {
::mingling::macros::r_println!($buf, "{}", $crate::utils::cargo_style::get_cargo_info_format($cmd))
};
}
#[macro_export]
macro_rules! eprintln_cargo {
($buf:ident, $fmt:literal, $($arg:tt)*) => {
::mingling::macros::r_println!($buf, "{}", $crate::utils::cargo_style::get_cargo_error_format(format!($fmt, $($arg)*)))
};
($buf:ident, $cmd:expr) => {
::mingling::macros::r_println!($buf, "{}", $crate::utils::cargo_style::get_cargo_error_format($cmd))
};
}
#[macro_export]
macro_rules! hprintln_cargo {
($buf:ident, $fmt:literal, $($arg:tt)*) => {
::mingling::macros::r_println!($buf, "{}", $crate::utils::cargo_style::get_cargo_help_format(format!($fmt, $($arg)*)))
};
($buf:ident, $cmd:expr) => {
::mingling::macros::r_println!($buf, "{}", $crate::utils::cargo_style::get_cargo_help_format($cmd))
};
}
pub fn get_cargo_info_format(str: impl Into<String>) -> String {
let s = str.into();
let (prefix, content) = if let Some(pos) = s.find(':') {
(
s[..pos].trim().to_string(),
s[pos + 1..].trim_start().to_string(),
)
} else {
(String::new(), s.trim().to_string())
};
assert!(
prefix.len() <= 12,
"prefix length exceeds 12: '{}' has length {}",
prefix,
prefix.len()
);
let padding = " ".repeat(12 - prefix.len());
format!(
"{}{} {}",
padding,
prefix.bold().bright_green(),
content.trim()
)
}
pub fn get_cargo_error_format(str: impl Into<String>) -> String {
format!("{}: {}", "error".bold().bright_red(), str.into())
}
pub fn get_cargo_help_format(str: impl Into<String>) -> String {
format!("{}: {}", "help".bright_white(), str.into())
}