diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-07-11 15:15:12 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-07-11 15:21:40 +0800 |
| commit | 95815041fe2817b4b6bdba6b4f332c90320af7bb (patch) | |
| tree | 224f3479eca9e44caa247132ecab42f8825b167c /examples/full-todolist/src/help.rs | |
| parent | 356879cfd6149bdb235b4e02c0f351a4d2246202 (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/full-todolist/src/help.rs')
| -rw-r--r-- | examples/full-todolist/src/help.rs | 99 |
1 files changed, 52 insertions, 47 deletions
diff --git a/examples/full-todolist/src/help.rs b/examples/full-todolist/src/help.rs index ab33176..2f8228a 100644 --- a/examples/full-todolist/src/help.rs +++ b/examples/full-todolist/src/help.rs @@ -1,15 +1,16 @@ //! This module provides help information for the `todolist` command line program -use mingling::macros::{help, r_println}; - use crate::{EntryAdd, EntryClean, EntryComplete, EntryList, ErrorDispatcherNotFound}; +use mingling::{RenderResult, macros::help}; +use std::io::Write; +/// Shows the global help message. #[help] -pub fn help_global(_p: ErrorDispatcherNotFound) { - r_println!( - "{}", - r" -Usage: todolist [command] [args] +pub fn help_global(_p: ErrorDispatcherNotFound) -> RenderResult { + let mut render_result = RenderResult::new(); + writeln!( + render_result, + r"Usage: todolist [command] [args] Commands: add -- Add a new task @@ -20,74 +21,78 @@ Commands: Args: -h, --help -- Show this help message -V, --version -- Show the version - -A, --all -- All tasks (Clean all / List all) - " - .trim() - ); + -A, --all -- All tasks (Clean all / List all)" + ) + .ok(); + render_result } +/// Shows help for the `add` command. #[help] -pub fn help_add(_p: EntryAdd) { - r_println!( - "{}", - r" -Usage: todolist add [task description] +pub fn help_add(_p: EntryAdd) -> RenderResult { + let mut render_result = RenderResult::new(); + writeln!( + render_result, + r"Usage: todolist add [task description] Add a new task to the todo list. Example: todolist add 'Buy groceries' - todolist add 'Finish Rust project' - " - .trim() - ); + todolist add 'Finish Rust project'" + ) + .ok(); + render_result } +/// Shows help for the `list` command. #[help] -pub fn help_list(_p: EntryList) { - r_println!( - "{}", - r" -Usage: todolist list +pub fn help_list(_p: EntryList) -> RenderResult { + let mut render_result = RenderResult::new(); + writeln!( + render_result, + r"Usage: todolist list List all tasks. Example: - todolist list - " - .trim() - ); + todolist list" + ) + .ok(); + render_result } +/// Shows help for the `complete` command. #[help] -pub fn help_complete(_p: EntryComplete) { - r_println!( - "{}", - r" -Usage: todolist complete [task_id] +pub fn help_complete(_p: EntryComplete) -> RenderResult { + let mut render_result = RenderResult::new(); + writeln!( + render_result, + r"Usage: todolist complete [task_id] Mark a task as complete by its ID. Example: todolist complete 1 - todolist complete 3 - " - .trim() - ); + todolist complete 3" + ) + .ok(); + render_result } +/// Shows help for the `clean` command. #[help] -pub fn help_clean(_p: EntryClean) { - r_println!( - "{}", - r" -Usage: todolist clean +pub fn help_clean(_p: EntryClean) -> RenderResult { + let mut render_result = RenderResult::new(); + writeln!( + render_result, + r"Usage: todolist clean Remove all completed tasks from the list. Example: - todolist clean - " - .trim() - ); + todolist clean" + ) + .ok(); + render_result } |
