Add error message support to task edit

This commit is contained in:
Dheepak Krishnamurthy 2020-07-30 16:04:31 -06:00
parent b706f34b53
commit 33cf5497b6
2 changed files with 22 additions and 18 deletions

View file

@ -687,9 +687,9 @@ impl App {
} }
} }
pub fn task_edit(&self) { pub fn task_edit(&self) -> Result<(), String> {
if self.tasks.len() == 0 { if self.tasks.len() == 0 {
return return Ok(());
} }
let selected = self.state.selected().unwrap_or_default(); let selected = self.state.selected().unwrap_or_default();
let task_id = self.tasks[selected].id().unwrap_or_default(); let task_id = self.tasks[selected].id().unwrap_or_default();
@ -698,24 +698,22 @@ impl App {
.arg(format!("{}", task_id)) .arg(format!("{}", task_id))
.spawn(); .spawn();
// TODO: fix vim hanging
match r { match r {
Ok(child) => { Ok(child) => {
let output = child let output = child
.wait_with_output() .wait_with_output();
.expect( match output {
&format!( Ok(output) => {
"Cannot run `task edit` for task `{}`. Check documentation for more information", if !output.status.success() {
task_id return Err(format!("Something went wrong. Cannot run `task edit` for task `{}`. Check documentation for more information", task_id));
)[..], } else {
); return Ok(());
if !output.status.success() { }
// TODO: show error message here },
Err(_) => Err(format!("Something went wrong. Cannot run `task edit` for task `{}`. Check documentation for more information", task_id)),
} }
} }
_ => { _ => Err(format!("Something went wrong. Cannot start `task edit` for task `{}`. Check documentation for more information", task_id))
println!("Vim failed to start");
}
} }
} }

View file

@ -84,8 +84,15 @@ fn main() -> Result<(), Box<dyn Error>> {
}, },
Key::Char('e') => { Key::Char('e') => {
events.pause_event_loop(&mut terminal); events.pause_event_loop(&mut terminal);
app.task_edit(); let r = app.task_edit();
events.resume_event_loop(&mut terminal); events.resume_event_loop(&mut terminal);
match r {
Ok(_) => (),
Err(e) => {
app.mode = AppMode::TaskError;
app.error = e;
}
}
}, },
Key::Char('m') => { Key::Char('m') => {
app.mode = AppMode::ModifyTask; app.mode = AppMode::ModifyTask;
@ -193,10 +200,9 @@ fn main() -> Result<(), Box<dyn Error>> {
_ => {} _ => {}
}, },
AppMode::TaskError => match input { AppMode::TaskError => match input {
Key::Esc => { _ => {
app.mode = AppMode::Report; app.mode = AppMode::Report;
} }
_ => {}
}, },
} }
} }