aboutsummaryrefslogtreecommitdiff
path: root/examples/full-todolist/src/todolist.rs
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/full-todolist/src/todolist.rs
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/full-todolist/src/todolist.rs')
-rw-r--r--examples/full-todolist/src/todolist.rs22
1 files changed, 14 insertions, 8 deletions
diff --git a/examples/full-todolist/src/todolist.rs b/examples/full-todolist/src/todolist.rs
index e447f5d..71338c3 100644
--- a/examples/full-todolist/src/todolist.rs
+++ b/examples/full-todolist/src/todolist.rs
@@ -1,10 +1,8 @@
//! Data structures, read and write logic for the todo list
-use mingling::{
- macros::{r_println, renderer},
- Groupped,
-};
+use mingling::{Groupped, RenderResult, macros::renderer};
use serde::{Deserialize, Serialize};
+use std::io::Write;
use std::{env::current_dir, path::PathBuf};
use crate::ResProgramFlags;
@@ -37,22 +35,30 @@ pub fn read_todo_list() -> ResTodoList {
serde_json::from_reader(reader).unwrap_or_default()
}
+/// Renders the todo list.
#[renderer]
-pub fn render_res_todo_list(todo_list: ResTodoList, program_flags: &ResProgramFlags) {
+pub fn render_res_todo_list(
+ todo_list: ResTodoList,
+ program_flags: &ResProgramFlags,
+) -> RenderResult {
+ let mut render_result = RenderResult::new();
let mut idx = 0;
- r_println!("TODO: ");
+ writeln!(render_result, "TODO: ").ok();
for item in &todo_list.items {
if item.completed && !program_flags.all {
idx += 1;
continue;
}
- r_println!(
+ writeln!(
+ render_result,
" {idx}. [{}] - \"{}\"",
if item.completed { "x" } else { " " },
item.item
- );
+ )
+ .ok();
idx += 1;
}
+ render_result
}
pub fn write_todo_list(todo_list: ResTodoList) {