mirror of
https://github.com/kdheepak/taskwarrior-tui.git
synced 2025-08-26 12:17:19 +02:00
Change start or stop to support errors
This commit is contained in:
parent
e71c59e8b3
commit
ca1444865a
2 changed files with 44 additions and 41 deletions
77
src/app.rs
77
src/app.rs
|
@ -266,20 +266,19 @@ impl App {
|
||||||
let task_id = self.tasks[selected].id().unwrap_or_default();
|
let task_id = self.tasks[selected].id().unwrap_or_default();
|
||||||
let output = Command::new("task")
|
let output = Command::new("task")
|
||||||
.arg(format!("{}", task_id))
|
.arg(format!("{}", task_id))
|
||||||
.output()
|
.output();
|
||||||
.expect(
|
match output {
|
||||||
&format!(
|
Ok(output) => {
|
||||||
"Unable to show details for `task {}`. Check documentation for more information",
|
let data = String::from_utf8(output.stdout).unwrap();
|
||||||
task_id
|
let p = Paragraph::new(Text::from(&data[..])).block(
|
||||||
)[..],
|
Block::default()
|
||||||
);
|
.borders(Borders::ALL)
|
||||||
let data = String::from_utf8(output.stdout).unwrap();
|
.title(format!("Task {}", task_id)),
|
||||||
let p = Paragraph::new(Text::from(&data[..])).block(
|
);
|
||||||
Block::default()
|
f.render_widget(p, rect);
|
||||||
.borders(Borders::ALL)
|
},
|
||||||
.title(format!("Task {}", task_id)),
|
Err(_) => (),
|
||||||
);
|
}
|
||||||
f.render_widget(p, rect);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_task_report(&mut self, f: &mut Frame<impl Backend>, rect: Rect) {
|
fn draw_task_report(&mut self, f: &mut Frame<impl Backend>, rect: Rect) {
|
||||||
|
@ -593,37 +592,37 @@ impl App {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn task_virtual_tags(& self) -> String {
|
pub fn task_virtual_tags(& self) -> Result<String, String> {
|
||||||
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();
|
||||||
let output = Command::new("task")
|
let output = Command::new("task")
|
||||||
.arg(format!("{}", task_id))
|
.arg(format!("{}", task_id))
|
||||||
.output()
|
.output();
|
||||||
.expect(
|
|
||||||
&format!(
|
match output {
|
||||||
"Cannot run `task {}`. Check documentation for more information",
|
Ok(output) => {
|
||||||
task_id
|
let data = String::from_utf8(output.stdout).unwrap();
|
||||||
)[..],
|
for line in data.split("\n") {
|
||||||
);
|
if line.starts_with("Virtual tags") {
|
||||||
let data = String::from_utf8(output.stdout).unwrap();
|
let line = line.to_string();
|
||||||
for line in data.split("\n") {
|
let line = line.replace("Virtual tags", "");
|
||||||
if line.starts_with("Virtual tags") {
|
return Ok(line);
|
||||||
let line = line.to_string();
|
}
|
||||||
let line = line.replace("Virtual tags", "");
|
}
|
||||||
return line;
|
return Err(format!("Cannot find any tags for `task {}`. Check documentation for more information", task_id))
|
||||||
}
|
},
|
||||||
|
Err(_) => Err(format!("Cannot run `task {}`. Check documentation for more information", task_id))
|
||||||
}
|
}
|
||||||
"".to_string()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn task_start_or_stop(&mut self) {
|
pub fn task_start_or_stop(&mut 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();
|
||||||
let mut command = "start";
|
let mut command = "start";
|
||||||
for tag in self.task_virtual_tags().split(" ") {
|
for tag in self.task_virtual_tags()?.split(" ") {
|
||||||
if tag == "ACTIVE" {
|
if tag == "ACTIVE" {
|
||||||
command = "stop"
|
command = "stop"
|
||||||
}
|
}
|
||||||
|
@ -632,13 +631,11 @@ impl App {
|
||||||
let output = Command::new("task")
|
let output = Command::new("task")
|
||||||
.arg(command)
|
.arg(command)
|
||||||
.arg(format!("{}", task_id))
|
.arg(format!("{}", task_id))
|
||||||
.output()
|
.output();
|
||||||
.expect(
|
match output {
|
||||||
&format!(
|
Ok(_) => Ok(()),
|
||||||
"Cannot run `task done` for task `{}`. Check documentation for more information",
|
Err(_) => Err(format!("Cannot run `task done` for task `{}`. Check documentation for more information", task_id)),
|
||||||
task_id
|
}
|
||||||
)[..],
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn task_delete(&self) {
|
pub fn task_delete(&self) {
|
||||||
|
|
|
@ -56,7 +56,13 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
Key::Up | Key::Char('k') => app.previous(),
|
Key::Up | Key::Char('k') => app.previous(),
|
||||||
Key::Char('d') => app.task_done(),
|
Key::Char('d') => app.task_done(),
|
||||||
Key::Char('x') => app.task_delete(),
|
Key::Char('x') => app.task_delete(),
|
||||||
Key::Char('s') => app.task_start_or_stop(),
|
Key::Char('s') => match app.task_start_or_stop() {
|
||||||
|
Ok(_) => (),
|
||||||
|
Err(e) => {
|
||||||
|
app.mode = AppMode::TaskError;
|
||||||
|
app.error = e;
|
||||||
|
}
|
||||||
|
},
|
||||||
Key::Char('u') => app.task_undo(),
|
Key::Char('u') => app.task_undo(),
|
||||||
Key::Char('e') => {
|
Key::Char('e') => {
|
||||||
events.pause_event_loop(&mut terminal);
|
events.pause_event_loop(&mut terminal);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue