aboutsummaryrefslogtreecommitdiff
path: root/mingling_macros
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-07-11 15:15:12 +0800
committer魏曹先生 <1992414357@qq.com>2026-07-11 15:21:40 +0800
commit95815041fe2817b4b6bdba6b4f332c90320af7bb (patch)
tree224f3479eca9e44caa247132ecab42f8825b167c /mingling_macros
parent356879cfd6149bdb235b4e02c0f351a4d2246202 (diff)
refactor(examples): migrate renderers to return RenderResult and add
std::io::Write import Replace r_println!/r_print! macro usage across all example renderers with explicit RenderResult construction using std::io::Write, enabling more flexible output handling and reducing reliance on macro-side effects.
Diffstat (limited to 'mingling_macros')
-rw-r--r--mingling_macros/src/dispatcher_clap.rs10
1 files changed, 6 insertions, 4 deletions
diff --git a/mingling_macros/src/dispatcher_clap.rs b/mingling_macros/src/dispatcher_clap.rs
index 5f06fb4..b89dbad 100644
--- a/mingling_macros/src/dispatcher_clap.rs
+++ b/mingling_macros/src/dispatcher_clap.rs
@@ -1,9 +1,8 @@
use proc_macro::TokenStream;
use quote::quote;
use syn::{
- Ident, ItemStruct, LitBool, LitStr, Token,
parse::{Parse, ParseStream},
- parse_macro_input,
+ parse_macro_input, Ident, ItemStruct, LitBool, LitStr, Token,
};
/// Parsed key-value options after the first positional arguments
@@ -144,7 +143,7 @@ pub fn dispatcher_clap_attr(attr: TokenStream, item: TokenStream) -> TokenStream
Some(quote! {
#[allow(non_snake_case)]
#[::mingling::macros::help]
- pub fn #help_fn_name(_prev: #struct_name) {
+ pub fn #help_fn_name(_prev: #struct_name) -> ::mingling::RenderResult {
use std::io::Write;
use clap::ColorChoice;
@@ -154,11 +153,14 @@ pub fn dispatcher_clap_attr(attr: TokenStream, item: TokenStream) -> TokenStream
let mut cmd = <#struct_name as ::clap::CommandFactory>::command()
.color(ColorChoice::Always);
let styled = cmd.render_help();
- write!(__renderer_inner_result, "{}", styled.ansi()).unwrap();
+ let mut result = ::mingling::RenderResult::new();
+ let _ = write!(result, "{}", styled.ansi());
+ result
}
::mingling::ClapHelpPrintBehaviour::PrintDirectly => {
let mut command = <#struct_name as ::clap::CommandFactory>::command();
command.print_help().unwrap();
+ ::mingling::RenderResult::new()
}
}
}