Command Line TodoList Tool#
Project address: https://github.com/MrTwoc/todo-rs
A console-based todo list implemented in Rust, mainly used for recording events & clocking in. Currently, it has basic CRUD functionality implemented. Future plans include using [tabular output + emoji symbols] to beautify the output results, for example:
✅🟢【Completed】 🟡⏸️【Pending】
Logic Processing#
Add=>
command_add()=> receives user input, checks if the first parameter is add, then checks the parameter length; if parameters <3, it prompts insufficient parameters,
then calls Target::add()=> method to receive four parameters, including <task name><due date>[description][group], where [] are optional parameters,
so you only need to input the task name and date to add a task, other parameters will be set to default values.
Before adding, it will first traverse all task IDs in the file, then +1 for the new task, and then write to json.
Delete=>
Read the json file, define a variable to store the length, call the .retain method, which works=>
Traverse each element in the tasks vector
For each element, execute the closure |task| task.id != Some(id)
Retain elements that return true from the closure, remove elements that return false.
Then compare the length before and after deletion; if it's less than the previous length, the deletion was successful.
Query=>
Read json and then traverse.
Edit=>
Receive user input, check if the command length <3 or (command length - 1) % 2 == 0, it will prompt mismatch because index 0 and 1 are edit and task ID,
2 is the field name, and 2+1 is the modification content, so it can match like this, then enter Target::edit()=> method.
Check if the id is valid and exists, then retrieve the task by id, enter a for loop, define two variables for field and parameters, enter match to match the field,
if matched, modify it, then write to json file.
// Get mutable task reference
let task = &mut tasks[task_index];
// Parse and apply field updates (starting from index 1, every two parameters form a group)
for i in (2..args.len()).step_by(2) {
let field = args[i];
let value = args[i + 1];
// Task status can be modified separately
match field {
"name" => task.target_name = value.to_string(),
"deadline" => task.deadline = value.to_string(),
"description" => task.description = Some(value.to_string()),
"group" => task.group = Some(value.to_string()),
_ => eprintln!("Unsupported field: {}", field),
}
}
Project TODO#
- Add completion types for tasks, such as——
Every year | month | week | day | accumulate X times | complete before a specified date. - The application can run in the desktop tray or in the background.
- Multiple windows, for example, viewing task details for a specified group will display in a new window.
- Keyword search, allowing tasks to be searched by keywords.
- Batch operations: input a command once to edit multiple tasks, such as completing tasks in bulk.
- Operation records, completion records: record each successfully executed command by the user, as well as record the task completion time in timestamp format, and allow viewing records within the application.
- Performance optimization: Currently, memory usage is around 12MB, which seems a bit high; plans to reduce resource usage as much as possible.
- ⏸️ Task calendar: can output the calendar for the current month.