Command Line TodoList Tool#
Project address: https://github.com/MrTwoc/todo-rs
A console-based todo list implemented in Rust, mainly used for recording and checking events. Currently, it has basic CRUD functionality. Future plans include using [tabular output + emoji symbols] to beautify the output, 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], with [] as 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 is less than the previous length, the deletion was successful.
Query=>
Read json and then traverse.
Edit=>
Receives user input, checks if the command length < 3 or (command length - 1) % 2 == 0, it will prompt mismatch because the 0th and 1st 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.
Checks if the id is valid and exists, then retrieves the task by id, enters a for loop, defines two variables: field and parameter, enters match to match the field,
if matched, modifies it, then writes to the 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 task completion types, for example——
Every year | month | week | day | total 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 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.