From 95815041fe2817b4b6bdba6b4f332c90320af7bb Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Sat, 11 Jul 2026 15:15:12 +0800 Subject: 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. --- examples/example-repl-basic/src/main.rs | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'examples/example-repl-basic') diff --git a/examples/example-repl-basic/src/main.rs b/examples/example-repl-basic/src/main.rs index 8df8c22..d15319e 100644 --- a/examples/example-repl-basic/src/main.rs +++ b/examples/example-repl-basic/src/main.rs @@ -14,6 +14,7 @@ use mingling::{ setup::{BasicREPLOutputSetup, BasicREPLPromptSetup, BasicREPLReadlineSetup}, this, }; +use std::io::Write; use std::{env::current_dir, path::PathBuf}; // Resource to store the current directory @@ -136,10 +137,12 @@ fn handle_ls(_prev: EntryLs, current_dir: &ResCurrentDir) -> Next { /// Render ResultList data #[renderer] -fn render_list(list: ResultList) { +fn render_list(list: ResultList) -> RenderResult { + let mut render_result = RenderResult::new(); for item in list.inner { - r_println!("{}", item); + writeln!(render_result, "{}", item).ok(); } + render_result } // Handle exit command event @@ -161,15 +164,24 @@ fn handle_clear(_prev: EntryClear) { /// Handle path not found event #[renderer] -fn render_error_directory_not_exist(err: ErrorDirectoryNotExist) { - r_println!("Directory not found: {}", err.inner.display()) +fn render_error_directory_not_exist(err: ErrorDirectoryNotExist) -> RenderResult { + let mut render_result = RenderResult::new(); + writeln!( + render_result, + "Directory not found: {}", + err.inner.display() + ) + .ok(); + render_result } /// Handle dispatcher not found event /// Renders the error when a command is not found. #[renderer] -fn dispatcher_not_found(prev: ErrorDispatcherNotFound) { - r_println!("Command not found: \"{}\"", prev.join(", ")) +fn dispatcher_not_found(prev: ErrorDispatcherNotFound) -> RenderResult { + let mut render_result = RenderResult::new(); + writeln!(render_result, "Command not found: \"{}\"", prev.join(", ")).ok(); + render_result } gen_program!(); -- cgit