15 releases (3 stable)
|2.0.0||Feb 3, 2021|
|1.0.1||Dec 29, 2020|
|0.5.2||Dec 26, 2020|
|0.5.1||Aug 9, 2020|
|0.2.0||Dec 30, 2018|
#326 in Data structures
131 downloads per month
Used in ttdl
A collection of utilities to work with files in todo.txt format
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(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:
- a list is saved to a temporary file in the same directory with
- on success, it deleted the old file and renames temporary file to
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.
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):
range- selects one todo by its ID, or a few ones within ID range(inclusive), or a list of IDs;
all- selects only all done, only incomplete, or both;
pri- selects with any priority, without any priority, or with the same/higher/lower priority(inclusive);
use_regexis true, it does regular expression pattern matching, otherwise it search for a substring. Note: it searches for the
regexin subject, projects, and contexts;
projects- selects all todos that have any of
projects. This rule allows a caller to do very basic pattern matching:
*added to the beginning or to the end of a project means to look for a project which name ends or starts respectively with the word, Adding
*to both ends works like
regexbut checks only projects.
*in the middle of the word does not have any special meaning - use
regexin this case;
contexts- selects all todos that have any of
contexts. The rule can use
*in the same way
tags- selects all todos that have any of
tags. The rule can use
*in the same way
due- selects all todos with any due date, without due date, a todo with due date within range, or todos which are less than the number of days ahead;
rec- selects all recurrent todos or all without recurrent flag.
thr- selects all todos with any threshold date, without threshold date
tmr- selects all active todos - that have their timers running
created- selects all todos with any creation date, without creation date, a todo with creation date within range
finished- selects all todos with any finish date, without finish date, a todo with finish date within range
tags support special values:
none- filter todos that do not have any values (contexts=['none'] - todos without any context)
any- filter todos that have at least one value (project=['any'] - todos that belong to any project)
sort(ids: &mut todo::IDVec, todos: &todo::TaskSlice, c: &Conf)
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:
fields- is a comma(or colon) separated list of fields in order of importance for sorting. If the vector is empty the list remains unchanged. Supported field names(and their abbreviations):
priority- sort by priority (without priority are the last ones);
due- sort by due date (todos that do not have due date are at the bottom);
finished- sort by completion date (incomplete ones are at the bottom);
create- sort by creation date;
text- sort by todo's subjects;
done- order: incomplete, recurrent, and done todos;
proj- sort by project names, if todos have more than one project they are compared in order of appearance and shorter list of projects goes first;
ctx- sort by contexts, if todos have more than one context they are compared in order of appearance and shorter list of contexts goes first;
thr- sort by threshold date (todos that do not have threshold date are at the bottom);
rev- when it is
truethe sorted list is reversed before returning the result.
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
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
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.
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 in the future. If you need to mark recurrent todo completed you have to remove recurrence from the todo beforehand.
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.
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:
subject- set a new one
priority- set, remove, increase or decrease priority
due date- set or remove
thresold date- set or remove
recurrence- set or remove
projects- add, remove or replace
contexts- add, remove or replace
To calculated time spent on a todo, two main functions are added:
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.
is_timer_on(task: &todo_txt::task::Extended) -> bool
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.