Add log functionality

This commit is contained in:
Dheepak Krishnamurthy 2020-07-28 14:10:24 -06:00
parent acd512ab7d
commit 2e32659d22
2 changed files with 45 additions and 0 deletions

View file

@ -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

View file

@ -63,6 +63,9 @@ fn main() -> Result<(), Box<dyn Error>> {
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<dyn Error>> {
}
_ => {}
},
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();