mirror of
https://github.com/kdheepak/taskwarrior-tui.git
synced 2025-08-27 15:47:19 +02:00
Add start stop functionality
This commit is contained in:
parent
c91a0f0630
commit
fb925e6182
2 changed files with 63 additions and 8 deletions
70
src/app.rs
70
src/app.rs
|
@ -434,6 +434,54 @@ impl App {
|
||||||
self.command = "".to_string();
|
self.command = "".to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn task_virtual_tags(& self) -> String {
|
||||||
|
let selected = self.state.selected().unwrap_or_default();
|
||||||
|
let task_id = self.tasks[selected].id().unwrap_or_default();
|
||||||
|
let output = Command::new("task")
|
||||||
|
.arg(format!("{}", task_id))
|
||||||
|
.output()
|
||||||
|
.expect(
|
||||||
|
&format!(
|
||||||
|
"Cannot run `task {}`. Check documentation for more information",
|
||||||
|
task_id
|
||||||
|
)[..],
|
||||||
|
);
|
||||||
|
let data = String::from_utf8(output.stdout).unwrap();
|
||||||
|
for line in data.split("\n") {
|
||||||
|
if line.starts_with("Virtual tags") {
|
||||||
|
let line = line.to_string();
|
||||||
|
let line = line.replace("Virtual tags", "");
|
||||||
|
return line;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"".to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn task_start_or_stop(&mut self) {
|
||||||
|
if self.tasks.len() == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let selected = self.state.selected().unwrap_or_default();
|
||||||
|
let task_id = self.tasks[selected].id().unwrap_or_default();
|
||||||
|
let mut command = "start";
|
||||||
|
for tag in self.task_virtual_tags().split(" ") {
|
||||||
|
if tag == "ACTIVE" {
|
||||||
|
command = "stop"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let output = Command::new("task")
|
||||||
|
.arg(command)
|
||||||
|
.arg(format!("{}", task_id))
|
||||||
|
.output()
|
||||||
|
.expect(
|
||||||
|
&format!(
|
||||||
|
"Cannot run `task done` for task `{}`. Check documentation for more information",
|
||||||
|
task_id
|
||||||
|
)[..],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn task_done(&mut self) {
|
pub fn task_done(&mut self) {
|
||||||
if self.tasks.len() == 0 {
|
if self.tasks.len() == 0 {
|
||||||
return
|
return
|
||||||
|
@ -511,19 +559,25 @@ mod tests {
|
||||||
let mut app = App::new();
|
let mut app = App::new();
|
||||||
app.update();
|
app.update();
|
||||||
|
|
||||||
println!("{:?}", app.tasks);
|
//println!("{:?}", app.tasks);
|
||||||
|
|
||||||
println!("{:?}", app.task_report_columns);
|
//println!("{:?}", app.task_report_columns);
|
||||||
println!("{:?}", app.task_report_labels);
|
//println!("{:?}", app.task_report_labels);
|
||||||
|
|
||||||
let (t, h, c) = app.task_report();
|
let (t, h, c) = app.task_report();
|
||||||
println!("{:?}", t);
|
|
||||||
println!("{:?}", t);
|
|
||||||
println!("{:?}", t);
|
|
||||||
app.next();
|
app.next();
|
||||||
app.next();
|
app.next();
|
||||||
app.next();
|
let selected = app.state.selected().unwrap_or_default();
|
||||||
app.task_edit();
|
let task_id = app.tasks[selected].id().unwrap_or_default();
|
||||||
|
let mut command = "start";
|
||||||
|
for tag in app.tasks[selected].tags().unwrap_or(&vec![]) {
|
||||||
|
if tag == "ACTIVE" {
|
||||||
|
command = "stop"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
println!("{:?}", app.tasks[selected]);
|
||||||
|
println!("{:?}", app.tasks[selected].tags().unwrap_or(&vec![]));
|
||||||
|
println!("{}", app.task_virtual_tags());
|
||||||
// if let Ok(tasks) = import(stdin()) {
|
// if let Ok(tasks) = import(stdin()) {
|
||||||
// for task in tasks {
|
// for task in tasks {
|
||||||
// println!("Task: {}, entered {:?} is {} -> {}",
|
// println!("Task: {}, entered {:?} is {} -> {}",
|
||||||
|
|
|
@ -55,6 +55,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
Key::Down | Key::Char('j') => app.next(),
|
Key::Down | Key::Char('j') => app.next(),
|
||||||
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('s') => app.task_start_or_stop(),
|
||||||
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