From 8aa276beb88086b866be8a446289106be237348a Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Sun, 7 Jun 2026 15:18:24 +0800 Subject: Add hformat_cargo, hprintln_cargo macros and help rendering --- mling/src/cargo_style.rs | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'mling/src/cargo_style.rs') diff --git a/mling/src/cargo_style.rs b/mling/src/cargo_style.rs index f127cc9..c212094 100644 --- a/mling/src/cargo_style.rs +++ b/mling/src/cargo_style.rs @@ -54,6 +54,29 @@ macro_rules! eformat_cargo { }; } +/// Formats a help message in cargo-style format with a bright white "help" prefix. +/// +/// # Macros +/// +/// - `hformat_cargo!("prefix: {}", arg)` — format-style invocation +/// - `hformat_cargo!(expr)` — direct expression invocation +/// +/// # Examples +/// +/// ```ignore +/// hformat_cargo!("use --verbose for more info"); +/// // Output: "help: use --verbose for more info" (bright white "help") +/// ``` +#[macro_export] +macro_rules! hformat_cargo { + ($fmt:literal, $($arg:tt)*) => { + $crate::get_cargo_help_format(format!($fmt, $($arg)*)) + }; + ($cmd:expr) => { + $crate::get_cargo_help_format($cmd) + }; +} + /// Print a message in cargo-style format with a bold green prefix. /// /// # Macros @@ -98,6 +121,28 @@ macro_rules! eprintln_cargo { }; } +/// Print a help message in cargo-style format with a bright white "help" prefix. +/// +/// # Macros +/// +/// - `hprintln_cargo!("prefix: {}", arg)` — format-style invocation +/// - `hprintln_cargo!(expr)` — direct expression invocation +/// +/// # Examples +/// +/// ```ignore +/// hprintln_cargo!("use --verbose for more info"); +/// ``` +#[macro_export] +macro_rules! hprintln_cargo { + ($fmt:literal, $($arg:tt)*) => { + println!("{}", $crate::get_cargo_help_format(format!($fmt, $($arg)*))) + }; + ($cmd:expr) => { + println!("{}", $crate::get_cargo_help_format($cmd)) + }; +} + /// Format a message in cargo style format, with bold green prefix. /// /// The input string is split at the first `:`. The part before the colon becomes @@ -159,3 +204,18 @@ pub fn get_cargo_info_format(str: impl Into) -> String { pub fn get_cargo_error_format(str: impl Into) -> String { format!("{}: {}", "error".bold().bright_red(), str.into()) } + +/// Format a help message in cargo style format, with bright white "help" prefix. +/// +/// The input string is printed as the help content, prefixed by a bright white +/// `help:` label (not bold). +/// +/// # Examples +/// +/// ```ignore +/// get_cargo_help_format("use --verbose for more info"); +/// // returns "help: use --verbose for more info" +/// ``` +pub fn get_cargo_help_format(str: impl Into) -> String { + format!("{}: {}", "help".bright_white(), str.into()) +} -- cgit