mirror of
https://github.com/kdheepak/taskwarrior-tui.git
synced 2025-08-27 06:37:19 +02:00
Add modify functionality
This commit is contained in:
parent
2e32659d22
commit
65d128fcfb
2 changed files with 62 additions and 2 deletions
40
src/app.rs
40
src/app.rs
|
@ -91,6 +91,7 @@ pub enum AppMode {
|
||||||
Filter,
|
Filter,
|
||||||
AddTask,
|
AddTask,
|
||||||
LogTask,
|
LogTask,
|
||||||
|
ModifyTask,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct App {
|
pub struct App {
|
||||||
|
@ -98,6 +99,7 @@ pub struct App {
|
||||||
pub state: TableState,
|
pub state: TableState,
|
||||||
pub filter: String,
|
pub filter: String,
|
||||||
pub command: String,
|
pub command: String,
|
||||||
|
pub modify: String,
|
||||||
pub tasks: Vec<Task>,
|
pub tasks: Vec<Task>,
|
||||||
pub task_report_labels: Vec<String>,
|
pub task_report_labels: Vec<String>,
|
||||||
pub task_report_columns: Vec<String>,
|
pub task_report_columns: Vec<String>,
|
||||||
|
@ -114,6 +116,7 @@ impl App {
|
||||||
task_report_columns: vec![],
|
task_report_columns: vec![],
|
||||||
filter: "status:pending ".to_string(),
|
filter: "status:pending ".to_string(),
|
||||||
command: "".to_string(),
|
command: "".to_string(),
|
||||||
|
modify: "".to_string(),
|
||||||
mode: AppMode::Report,
|
mode: AppMode::Report,
|
||||||
};
|
};
|
||||||
app.update();
|
app.update();
|
||||||
|
@ -137,14 +140,24 @@ impl App {
|
||||||
self.draw_task_report(f, rects[0]);
|
self.draw_task_report(f, rects[0]);
|
||||||
self.draw_task_details(f, rects[1]);
|
self.draw_task_details(f, rects[1]);
|
||||||
match self.mode {
|
match self.mode {
|
||||||
AppMode::Report => self.draw_command(f, rects[2], &self.filter[..], "Filter"),
|
AppMode::Report => self.draw_command(f, rects[2], &self.filter[..], "Filter Tasks"),
|
||||||
AppMode::Filter => {
|
AppMode::Filter => {
|
||||||
f.render_widget(Clear, rects[2]);
|
f.render_widget(Clear, rects[2]);
|
||||||
f.set_cursor(
|
f.set_cursor(
|
||||||
rects[2].x + self.filter.width() as u16 + 1,
|
rects[2].x + self.filter.width() as u16 + 1,
|
||||||
rects[2].y + 1,
|
rects[2].y + 1,
|
||||||
);
|
);
|
||||||
self.draw_command(f, rects[2], &self.filter[..], "Filter");
|
self.draw_command(f, rects[2], &self.filter[..], "Filter Tasks");
|
||||||
|
},
|
||||||
|
AppMode::ModifyTask => {
|
||||||
|
f.set_cursor(
|
||||||
|
// Put cursor past the end of the input text
|
||||||
|
rects[2].x + self.modify.width() as u16 + 1,
|
||||||
|
// Move one line down, from the border to the input line
|
||||||
|
rects[2].y + 1,
|
||||||
|
);
|
||||||
|
f.render_widget(Clear, rects[2]);
|
||||||
|
self.draw_command(f, rects[2], &self.modify[..], "Modify Task");
|
||||||
},
|
},
|
||||||
AppMode::LogTask => {
|
AppMode::LogTask => {
|
||||||
f.set_cursor(
|
f.set_cursor(
|
||||||
|
@ -445,6 +458,22 @@ impl App {
|
||||||
self.command = "".to_string();
|
self.command = "".to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn task_modify(&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 output = Command::new("task")
|
||||||
|
.arg("modify")
|
||||||
|
.arg(format!("{}", task_id))
|
||||||
|
.arg(format!("{}", self.modify))
|
||||||
|
.output()
|
||||||
|
.expect("Cannot run `task modify`. Check documentation for more information");
|
||||||
|
|
||||||
|
self.modify = "".to_string();
|
||||||
|
}
|
||||||
|
|
||||||
pub fn task_add(&mut self) {
|
pub fn task_add(&mut self) {
|
||||||
if self.tasks.len() == 0 {
|
if self.tasks.len() == 0 {
|
||||||
return
|
return
|
||||||
|
@ -588,6 +617,13 @@ impl App {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn task_current(&self) -> Option<Task> {
|
||||||
|
if self.tasks.len() == 0 {
|
||||||
|
return None
|
||||||
|
}
|
||||||
|
let selected = self.state.selected().unwrap_or_default();
|
||||||
|
return Some(self.tasks[selected].clone());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
24
src/main.rs
24
src/main.rs
|
@ -63,6 +63,13 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
app.task_edit();
|
app.task_edit();
|
||||||
events.resume_event_loop(&mut terminal);
|
events.resume_event_loop(&mut terminal);
|
||||||
},
|
},
|
||||||
|
Key::Char('m') => {
|
||||||
|
app.mode = AppMode::ModifyTask;
|
||||||
|
match app.task_current() {
|
||||||
|
Some(t) => app.modify = t.description().to_string(),
|
||||||
|
None => app.modify = "".to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
Key::Char('l') => {
|
Key::Char('l') => {
|
||||||
app.mode = AppMode::LogTask;
|
app.mode = AppMode::LogTask;
|
||||||
}
|
}
|
||||||
|
@ -74,6 +81,23 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
},
|
},
|
||||||
|
AppMode::ModifyTask => match input {
|
||||||
|
Key::Char('\n') => {
|
||||||
|
app.task_modify();
|
||||||
|
app.mode = AppMode::Report;
|
||||||
|
}
|
||||||
|
Key::Esc => {
|
||||||
|
app.modify = "".to_string();
|
||||||
|
app.mode = AppMode::Report;
|
||||||
|
}
|
||||||
|
Key::Char(c) => {
|
||||||
|
app.modify.push(c);
|
||||||
|
}
|
||||||
|
Key::Backspace => {
|
||||||
|
app.modify.pop();
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
},
|
||||||
AppMode::LogTask => match input {
|
AppMode::LogTask => match input {
|
||||||
Key::Char('\n') => {
|
Key::Char('\n') => {
|
||||||
app.task_log();
|
app.task_log();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue