From 2a08fb2f3328992dda0776ba9ff56eeafdaf762c Mon Sep 17 00:00:00 2001 From: Dheepak Krishnamurthy Date: Mon, 27 Jul 2020 21:37:31 -0600 Subject: [PATCH] Add edit feature --- src/app.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/app.rs b/src/app.rs index 08a574d..6335550 100644 --- a/src/app.rs +++ b/src/app.rs @@ -409,6 +409,36 @@ impl App { .expect("Cannot run `task undo`. Check documentation for more information"); } + pub fn task_edit(&self) { + if self.tasks.len() == 0 { + return + } + let selected = self.state.selected().unwrap_or_default(); + let task_id = self.tasks[selected].id().unwrap_or_default(); + let r = Command::new("task") + .arg("edit") + .arg(format!("{}", task_id)) + .spawn(); + + // TODO: fix vim hanging + match r { + Ok(mut child) => { + child + .wait() + .expect( + &format!( + "Cannot run `task edit` for task `{}`. Check documentation for more information", + task_id + )[..], + ); + println!("Opening task ..."); + } + _ => { + println!("Vim failed to start"); + } + } + } + pub fn handle_input(&mut self, event: Key) { match self.mode { AppMode::Report => match event { @@ -418,6 +448,7 @@ impl App { Key::Up | Key::Char('k') => self.previous(), Key::Char('d') => self.task_done(), Key::Char('u') => self.task_undo(), + Key::Char('e') => self.task_edit(), Key::Char('/') => { self.mode = AppMode::Filter; }