From 0c90086833324cfbf94801cf023bb377071da027 Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Thu, 25 Jul 2024 10:50:53 +0300 Subject: [PATCH] feat: text notes as descriptions --- README.md | 8 +++++--- src/main.rs | 4 ++++ src/tasks.rs | 20 +++++++++++++++++--- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 35c6f6e..dfba105 100644 --- a/README.md +++ b/README.md @@ -32,9 +32,11 @@ TASK add syntax: `NAME: TAG1 TAG2` Dots can be repeated to move to parent tasks - `:[IND][COL]` - add / remove property column COL to IND or end -- `>` - Complete active task and move to parent -- `<` - Close active task and move to parent -- TBI: `-TEXT` - add text note (comment / description) +- `>[TEXT]` - Complete active task and move to parent, with optional state description +- `<[TEXT]` - Close active task and move to parent, with optional state description +- `-TEXT` - add text note (comment / description) + +State descriptions can be used for example for Kanban columns. ### Columns diff --git a/src/main.rs b/src/main.rs index 3dbf8fa..a42dc52 100644 --- a/src/main.rs +++ b/src/main.rs @@ -193,6 +193,10 @@ async fn main() { } } }, + + Some('-') => { + tasks.add_note(&input[1..]) + } Some('>') | Some('<') => { tasks.update_state(&input[1..], |_| { diff --git a/src/tasks.rs b/src/tasks.rs index 822cb77..212afca 100644 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -246,9 +246,23 @@ impl Tasks { where F: FnOnce(&Task) -> Option, { - self.position.and_then(|id| { - self.update_state_for(&id, comment, f) - }) + self.position + .and_then(|id| self.update_state_for(&id, comment, f)) + } + + pub(crate) fn add_note(&mut self, note: &str) { + match self.position { + None => eprintln!("Cannot add note '{}' without active task", note), + Some(id) => { + self.sender + .submit(EventBuilder::text_note(note, vec![])) + .map(|e| { + self.tasks.get_mut(&id).map(|t| { + t.props.insert(e.clone()); + }); + }); + } + } } }