diff --git a/src/app.rs b/src/app.rs index 20534ac..45b9d9d 100644 --- a/src/app.rs +++ b/src/app.rs @@ -2012,6 +2012,41 @@ impl TaskwarriorTui { Ok(()) } + pub fn task_tag_next(&mut self) -> Result<(), String> { + + let app = TaskwarriorTui::new("next").unwrap(); + if self.tasks.is_empty() { + return Ok(()); + } + + let task_uuids = self.selected_task_uuids(); + + for task_uuid in &task_uuids { + if let Some(task) = app.task_by_uuid(*task_uuid) { + let mut tag_to_set = "+next"; + for tag in task.tags().unwrap() { + if tag == "next" { + tag_to_set = "-next"; + } + } + + let output = Command::new("task").arg(task_uuid.to_string()).arg("modify").arg(tag_to_set).output(); + if output.is_err() { + return Err(format!("Error running `task modify {}` for task `{}`.", tag_to_set, task_uuid,)); + } + } + + } + + if task_uuids.len() == 1 { + if let Some(uuid) = task_uuids.get(0) { + self.current_selection_uuid = Some(*uuid); + } + } + + Ok(()) + } + pub fn task_delete(&mut self) -> Result<(), String> { if self.tasks.is_empty() { return Ok(()); @@ -2430,6 +2465,14 @@ impl TaskwarriorTui { self.error = e; } } + } else if input == self.keyconfig.tag_next { + match self.task_tag_next() { + Ok(_) => self.update(true)?, + Err(e) => { + self.mode = Mode::Tasks(Action::Error); + self.error = e; + } + } } else if input == self.keyconfig.edit { match self.task_edit() { Ok(_) => self.update(true)?, diff --git a/src/keyconfig.rs b/src/keyconfig.rs index 976fc68..cd8435e 100644 --- a/src/keyconfig.rs +++ b/src/keyconfig.rs @@ -19,6 +19,7 @@ pub struct KeyConfig { pub delete: Key, pub done: Key, pub start_stop: Key, + pub tag_next: Key, pub select: Key, pub select_all: Key, pub undo: Key, @@ -60,6 +61,7 @@ impl Default for KeyConfig { delete: Key::Char('x'), done: Key::Char('d'), start_stop: Key::Char('s'), + tag_next: Key::Char('n'), select: Key::Char('v'), select_all: Key::Char('V'), undo: Key::Char('u'), @@ -108,6 +110,7 @@ impl KeyConfig { let delete = Self::get_config("uda.taskwarrior-tui.keyconfig.delete", data); let done = Self::get_config("uda.taskwarrior-tui.keyconfig.done", data); let start_stop = Self::get_config("uda.taskwarrior-tui.keyconfig.start-stop", data); + let tag_next = Self::get_config("uda.taskwarrior-tui.keyconfig.tag-next", data); let select = Self::get_config("uda.taskwarrior-tui.keyconfig.select", data); let select_all = Self::get_config("uda.taskwarrior-tui.keyconfig.select-all", data); let undo = Self::get_config("uda.taskwarrior-tui.keyconfig.undo", data); @@ -134,6 +137,7 @@ impl KeyConfig { self.delete = delete.unwrap_or(self.delete); self.done = done.unwrap_or(self.done); self.start_stop = start_stop.unwrap_or(self.start_stop); + self.tag_next = tag_next.unwrap_or(self.tag_next); self.select = select.unwrap_or(self.select); self.select_all = select_all.unwrap_or(self.select_all); self.undo = undo.unwrap_or(self.undo); @@ -167,6 +171,7 @@ impl KeyConfig { &self.select, &self.select_all, &self.start_stop, + &self.tag_next, &self.undo, &self.edit, &self.modify,