diff --git a/src/app.rs b/src/app.rs index 485bcab..56c0397 100644 --- a/src/app.rs +++ b/src/app.rs @@ -90,6 +90,7 @@ pub enum AppMode { Report, Filter, AddTask, + LogTask, } pub struct App { @@ -145,6 +146,16 @@ impl App { ); self.draw_command(f, rects[2], &self.filter[..], "Filter"); }, + AppMode::LogTask => { + f.set_cursor( + // Put cursor past the end of the input text + rects[2].x + self.command.width() as u16 + 1, + // Move one line down, from the border to the input line + rects[2].y + 1, + ); + f.render_widget(Clear, rects[2]); + self.draw_command(f, rects[2], &self.command[..], "Log Task"); + }, AppMode::AddTask => { f.set_cursor( // Put cursor past the end of the input text @@ -420,6 +431,20 @@ impl App { self.update(); } + pub fn task_log(&mut self) { + if self.tasks.len() == 0 { + return + } + + let output = Command::new("task") + .arg("log") + .arg(format!("{}", self.command)) + .output() + .expect("Cannot run `task log`. Check documentation for more information"); + + self.command = "".to_string(); + } + pub fn task_add(&mut self) { if self.tasks.len() == 0 { return diff --git a/src/main.rs b/src/main.rs index 2ab1fe5..08a7464 100644 --- a/src/main.rs +++ b/src/main.rs @@ -63,6 +63,9 @@ fn main() -> Result<(), Box> { app.task_edit(); events.resume_event_loop(&mut terminal); }, + Key::Char('l') => { + app.mode = AppMode::LogTask; + } Key::Char('a') => { app.mode = AppMode::AddTask; } @@ -71,6 +74,23 @@ fn main() -> Result<(), Box> { } _ => {} }, + AppMode::LogTask => match input { + Key::Char('\n') => { + app.task_log(); + app.mode = AppMode::Report; + } + Key::Esc => { + app.command = "".to_string(); + app.mode = AppMode::Report; + } + Key::Char(c) => { + app.command.push(c); + } + Key::Backspace => { + app.command.pop(); + } + _ => {} + }, AppMode::AddTask => match input { Key::Char('\n') => { app.task_add();