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

View file

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