TODO Library

A collection of utilities to work with files in todo.txt format

Working with files

Load todo list

load(filename: &Path) -> Result<TaskVec, terr::TodoError>

Loads a list of todos from a given file path. Returns the list of loaded todos or an error. If the file does not exist the function returns empty list.

Save todo list

save(tasks: &TaskSlice, filename: &Path) -> Result<(), terr::TodoError>

Saves the todo list to a given file path. It may return an error if creating file or writing to it fails. The list is saved in two steps:

Archive completed todos

archive(tasks: &TaskSlice, filename: &Path) -> Result<(), terr::TodoError>

It works similar to save but appends task list to a given filename. It does not create a temporary file.

Filtering

filter(tasks: &todo::TaskSlice, c: &Conf) -> todo::IDVec

The function gets the list of all todos and filtering rules and returns the list of todo IDs(todo's ID is the order number of the todo in the original list) that matches the rules. If a rule works with strings(e.g, projects or regex), the rule is case-insensitive. Available rules (if a rule is None the rule is skipped):

Sorting

sort(ids: &mut todo::IDVec, todos: &todo::TaskSlice, c: &Conf)

Because sort is the function that should be called after filter, it wants a list of selected todo IDs that must be sorted, the whole todo list (IDs in ids are the order numbers of a todo in todos) and sorting rules. The function changes ids in-place and the sorting is always stable - it keeps the order of todos in the ids list for todos that are equal to each other. There are only two sorting rules:

Editing

Add a new todo

add(tasks: &mut TaskVec, c: &Conf) -> usize

The function gets a list of existing todos and a c with non-None field subject, then it parses subject and adds the result todo to the list and return the ID of the new todo. If adding fails - e.g, subject is empty or parsing returns an error - the function returns INVALID_ID.

Modify existing todos

Functions of this category gets a list of all todos, list of todo IDs that should be modified and optionally new values for properties. If list of IDs ids is None then the function modifies all todos. It returns the vector of boolean values with the length equal to the length of ids (or length of tasks if ids is None). If the result vector has true at some index it means that the todo from ids at the same index was modified.

Complete and undone todos

Mark a todo completed

done(tasks: &mut TaskVec, ids: Option<&IDVec>) -> ChangedVec

Makes all todos from ids list that are incomplete completed.

Special case: recurrent todos. They are not marked completed, their due date moves to the next date. If you need to mark recurrent todo completed you have to remove recurrence from the todo beforehand.

Remove completion mark from a todo

undone(tasks: &mut TaskVec, ids: Option<&IDVec>) -> ChangedVec

Removes completion mark from all todos from ids list that are done.

Special case: recurrent todos. They are not changed.

Changing a specific property

edit(tasks: &mut TaskVec, ids: Option<&IDVec>, c: &Conf) -> ChangedVec

The function modifies all todos in tasks which IDs are in ids list. Note: modifying a subject changes only the first todo in ids list because it does not make sense to make all todos the same.

What can be modified:

Time tracking support

To calculated time spent on a todo, two main funcntions are added:

Start and stop time tracking

start(tasks: &mut TaskVec, ids: Option<&IDVec>) -> ChangedVec

Makes todos active if they are incomplete and their is not yet running. All todos saves the timestamp when they were activated.

stop(tasks: &mut TaskVec, ids: Option<&IDVec>) -> ChangedVec

Stop timers for a given todos. Time taken by the todo is updated.

And two utility functions:

is_timer_on(task: &todo_txt::task::Extended) -> bool

Retunrs true if the given todo is active

spent_time(task: &todo_txt::task::Extended) -> chrono::Duration

Returns the total time spent on the given todo. For an inactive todo it returns the current value of todo's tag spent. For an active todo it returns sum of todo's tag spent and the time passed since the moment the todo was activated.