mirror of
https://github.com/kdheepak/taskwarrior-tui.git
synced 2025-08-26 12:17:19 +02:00
Add error message support to task edit
This commit is contained in:
parent
b706f34b53
commit
33cf5497b6
2 changed files with 22 additions and 18 deletions
26
src/app.rs
26
src/app.rs
|
@ -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",
|
|
||||||
task_id
|
|
||||||
)[..],
|
|
||||||
);
|
|
||||||
if !output.status.success() {
|
if !output.status.success() {
|
||||||
// TODO: show error message here
|
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)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => Err(format!("Something went wrong. Cannot start `task edit` for task `{}`. Check documentation for more information", task_id))
|
||||||
println!("Vim failed to start");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
12
src/main.rs
12
src/main.rs
|
@ -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;
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue