aboutsummaryrefslogtreecommitdiff
path: root/examples/example-repl-basic
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 /examples/example-repl-basic
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 'examples/example-repl-basic')
-rw-r--r--examples/example-repl-basic/src/main.rs24
1 files changed, 18 insertions, 6 deletions
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!();