mirror of
https://github.com/kdheepak/taskwarrior-tui.git
synced 2025-08-26 03:07:18 +02:00
Move task_id before command where ever possible
This commit is contained in:
parent
c27e70cd5b
commit
39febd7b29
2 changed files with 95 additions and 24 deletions
28
src/app.rs
28
src/app.rs
|
@ -100,6 +100,7 @@ pub enum AppMode {
|
||||||
pub struct App {
|
pub struct App {
|
||||||
pub should_quit: bool,
|
pub should_quit: bool,
|
||||||
pub state: TableState,
|
pub state: TableState,
|
||||||
|
pub cursor_location: usize,
|
||||||
pub filter: String,
|
pub filter: String,
|
||||||
pub command: String,
|
pub command: String,
|
||||||
pub error: String,
|
pub error: String,
|
||||||
|
@ -119,6 +120,7 @@ impl App {
|
||||||
task_report_labels: vec![],
|
task_report_labels: vec![],
|
||||||
task_report_columns: vec![],
|
task_report_columns: vec![],
|
||||||
filter: "status:pending ".to_string(),
|
filter: "status:pending ".to_string(),
|
||||||
|
cursor_location: 0,
|
||||||
command: "".to_string(),
|
command: "".to_string(),
|
||||||
modify: "".to_string(),
|
modify: "".to_string(),
|
||||||
error: "".to_string(),
|
error: "".to_string(),
|
||||||
|
@ -159,16 +161,14 @@ impl App {
|
||||||
AppMode::Filter => {
|
AppMode::Filter => {
|
||||||
f.render_widget(Clear, rects[1]);
|
f.render_widget(Clear, rects[1]);
|
||||||
f.set_cursor(
|
f.set_cursor(
|
||||||
rects[1].x + self.filter.width() as u16 + 1,
|
rects[1].x + self.cursor_location as u16 + 1,
|
||||||
rects[1].y + 1,
|
rects[1].y + 1,
|
||||||
);
|
);
|
||||||
self.draw_command(f, rects[1], &self.filter[..], "Filter Tasks");
|
self.draw_command(f, rects[1], &self.filter[..], "Filter Tasks");
|
||||||
},
|
},
|
||||||
AppMode::ModifyTask => {
|
AppMode::ModifyTask => {
|
||||||
f.set_cursor(
|
f.set_cursor(
|
||||||
// Put cursor past the end of the input text
|
rects[1].x + self.cursor_location as u16 + 1,
|
||||||
rects[1].x + self.modify.width() as u16 + 1,
|
|
||||||
// Move one line down, from the border to the input line
|
|
||||||
rects[1].y + 1,
|
rects[1].y + 1,
|
||||||
);
|
);
|
||||||
f.render_widget(Clear, rects[1]);
|
f.render_widget(Clear, rects[1]);
|
||||||
|
@ -176,9 +176,7 @@ impl App {
|
||||||
},
|
},
|
||||||
AppMode::LogTask => {
|
AppMode::LogTask => {
|
||||||
f.set_cursor(
|
f.set_cursor(
|
||||||
// Put cursor past the end of the input text
|
rects[1].x + self.cursor_location as u16 + 1,
|
||||||
rects[1].x + self.command.width() as u16 + 1,
|
|
||||||
// Move one line down, from the border to the input line
|
|
||||||
rects[1].y + 1,
|
rects[1].y + 1,
|
||||||
);
|
);
|
||||||
f.render_widget(Clear, rects[1]);
|
f.render_widget(Clear, rects[1]);
|
||||||
|
@ -186,9 +184,7 @@ impl App {
|
||||||
},
|
},
|
||||||
AppMode::AddTask => {
|
AppMode::AddTask => {
|
||||||
f.set_cursor(
|
f.set_cursor(
|
||||||
// Put cursor past the end of the input text
|
rects[1].x + self.cursor_location as u16 + 1,
|
||||||
rects[1].x + self.command.width() as u16 + 1,
|
|
||||||
// Move one line down, from the border to the input line
|
|
||||||
rects[1].y + 1,
|
rects[1].y + 1,
|
||||||
);
|
);
|
||||||
f.render_widget(Clear, rects[1]);
|
f.render_widget(Clear, rects[1]);
|
||||||
|
@ -544,8 +540,8 @@ impl App {
|
||||||
let task_id = self.tasks[selected].id().unwrap_or_default();
|
let task_id = self.tasks[selected].id().unwrap_or_default();
|
||||||
let mut command = Command::new("task");
|
let mut command = Command::new("task");
|
||||||
command
|
command
|
||||||
.arg("modify")
|
.arg(format!("{}", task_id))
|
||||||
.arg(format!("{}", task_id));
|
.arg("modify");
|
||||||
|
|
||||||
match shlex::split(&self.modify) {
|
match shlex::split(&self.modify) {
|
||||||
Some(cmd) => {
|
Some(cmd) => {
|
||||||
|
@ -629,8 +625,8 @@ impl App {
|
||||||
}
|
}
|
||||||
|
|
||||||
let output = Command::new("task")
|
let output = Command::new("task")
|
||||||
.arg(command)
|
|
||||||
.arg(format!("{}", task_id))
|
.arg(format!("{}", task_id))
|
||||||
|
.arg(command)
|
||||||
.output();
|
.output();
|
||||||
match output {
|
match output {
|
||||||
Ok(_) => Ok(()),
|
Ok(_) => Ok(()),
|
||||||
|
@ -647,8 +643,8 @@ impl App {
|
||||||
|
|
||||||
let output = Command::new("task")
|
let output = Command::new("task")
|
||||||
.arg("rc.confirmation=off")
|
.arg("rc.confirmation=off")
|
||||||
.arg("delete")
|
|
||||||
.arg(format!("{}", task_id))
|
.arg(format!("{}", task_id))
|
||||||
|
.arg("delete")
|
||||||
.output();
|
.output();
|
||||||
match output {
|
match output {
|
||||||
Ok(_) => Ok(()),
|
Ok(_) => Ok(()),
|
||||||
|
@ -663,8 +659,8 @@ impl App {
|
||||||
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("done")
|
|
||||||
.arg(format!("{}", task_id))
|
.arg(format!("{}", task_id))
|
||||||
|
.arg("done")
|
||||||
.output();
|
.output();
|
||||||
match output {
|
match output {
|
||||||
Ok(_) => Ok(()),
|
Ok(_) => Ok(()),
|
||||||
|
@ -694,8 +690,8 @@ impl App {
|
||||||
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 r = Command::new("task")
|
let r = Command::new("task")
|
||||||
.arg("edit")
|
|
||||||
.arg(format!("{}", task_id))
|
.arg(format!("{}", task_id))
|
||||||
|
.arg("edit")
|
||||||
.spawn();
|
.spawn();
|
||||||
|
|
||||||
match r {
|
match r {
|
||||||
|
|
91
src/main.rs
91
src/main.rs
|
@ -100,18 +100,21 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
Some(t) => app.modify = t.description().to_string(),
|
Some(t) => app.modify = t.description().to_string(),
|
||||||
None => app.modify = "".to_string(),
|
None => app.modify = "".to_string(),
|
||||||
}
|
}
|
||||||
|
app.cursor_location = app.modify.len();
|
||||||
}
|
}
|
||||||
Key::Char('l') => {
|
Key::Char('l') => {
|
||||||
app.mode = AppMode::LogTask;
|
app.mode = AppMode::LogTask;
|
||||||
}
|
}
|
||||||
Key::Char('a') => {
|
Key::Char('a') => {
|
||||||
app.mode = AppMode::AddTask;
|
app.mode = AppMode::AddTask;
|
||||||
|
app.cursor_location = app.command.len();
|
||||||
}
|
}
|
||||||
Key::Char('?') => {
|
Key::Char('?') => {
|
||||||
app.mode = AppMode::HelpPopup;
|
app.mode = AppMode::HelpPopup;
|
||||||
}
|
}
|
||||||
Key::Char('/') => {
|
Key::Char('/') => {
|
||||||
app.mode = AppMode::Filter;
|
app.mode = AppMode::Filter;
|
||||||
|
app.cursor_location = app.filter.len();
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
},
|
},
|
||||||
|
@ -135,11 +138,29 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
app.modify = "".to_string();
|
app.modify = "".to_string();
|
||||||
app.mode = AppMode::Report;
|
app.mode = AppMode::Report;
|
||||||
}
|
}
|
||||||
|
Key::Right => {
|
||||||
|
if app.cursor_location < app.modify.len() {
|
||||||
|
app.cursor_location += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Key::Left => {
|
||||||
|
if app.cursor_location > 0 {
|
||||||
|
app.cursor_location -= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
Key::Char(c) => {
|
Key::Char(c) => {
|
||||||
app.modify.push(c);
|
if app.cursor_location < app.modify.len() {
|
||||||
|
app.modify.insert(app.cursor_location, c);
|
||||||
|
} else {
|
||||||
|
app.modify.push(c);
|
||||||
|
}
|
||||||
|
app.cursor_location += 1;
|
||||||
}
|
}
|
||||||
Key::Backspace => {
|
Key::Backspace => {
|
||||||
app.modify.pop();
|
if app.cursor_location > 0 {
|
||||||
|
app.cursor_location -= 1;
|
||||||
|
app.modify.remove(app.cursor_location);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
},
|
},
|
||||||
|
@ -157,11 +178,29 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
app.command = "".to_string();
|
app.command = "".to_string();
|
||||||
app.mode = AppMode::Report;
|
app.mode = AppMode::Report;
|
||||||
}
|
}
|
||||||
|
Key::Right => {
|
||||||
|
if app.cursor_location < app.command.len() {
|
||||||
|
app.cursor_location += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Key::Left => {
|
||||||
|
if app.cursor_location > 0 {
|
||||||
|
app.cursor_location -= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
Key::Char(c) => {
|
Key::Char(c) => {
|
||||||
app.command.push(c);
|
if app.cursor_location < app.command.len() {
|
||||||
|
app.command.insert(app.cursor_location, c);
|
||||||
|
} else {
|
||||||
|
app.command.push(c);
|
||||||
|
}
|
||||||
|
app.cursor_location += 1;
|
||||||
}
|
}
|
||||||
Key::Backspace => {
|
Key::Backspace => {
|
||||||
app.command.pop();
|
if app.cursor_location > 0 {
|
||||||
|
app.cursor_location -= 1;
|
||||||
|
app.command.remove(app.cursor_location);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
},
|
},
|
||||||
|
@ -179,11 +218,29 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
app.command = "".to_string();
|
app.command = "".to_string();
|
||||||
app.mode = AppMode::Report;
|
app.mode = AppMode::Report;
|
||||||
}
|
}
|
||||||
|
Key::Right => {
|
||||||
|
if app.cursor_location < app.command.len() {
|
||||||
|
app.cursor_location += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Key::Left => {
|
||||||
|
if app.cursor_location > 0 {
|
||||||
|
app.cursor_location -= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
Key::Char(c) => {
|
Key::Char(c) => {
|
||||||
app.command.push(c);
|
if app.cursor_location < app.command.len() {
|
||||||
|
app.command.insert(app.cursor_location, c);
|
||||||
|
} else {
|
||||||
|
app.command.push(c);
|
||||||
|
}
|
||||||
|
app.cursor_location += 1;
|
||||||
}
|
}
|
||||||
Key::Backspace => {
|
Key::Backspace => {
|
||||||
app.command.pop();
|
if app.cursor_location > 0 {
|
||||||
|
app.cursor_location -= 1;
|
||||||
|
app.command.remove(app.cursor_location);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
},
|
},
|
||||||
|
@ -191,11 +248,29 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
Key::Char('\n') | Key::Esc => {
|
Key::Char('\n') | Key::Esc => {
|
||||||
app.mode = AppMode::Report;
|
app.mode = AppMode::Report;
|
||||||
}
|
}
|
||||||
|
Key::Right => {
|
||||||
|
if app.cursor_location < app.filter.len() {
|
||||||
|
app.cursor_location += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Key::Left => {
|
||||||
|
if app.cursor_location > 0 {
|
||||||
|
app.cursor_location -= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
Key::Char(c) => {
|
Key::Char(c) => {
|
||||||
app.filter.push(c);
|
if app.cursor_location < app.filter.len() {
|
||||||
|
app.filter.insert(app.cursor_location, c);
|
||||||
|
} else {
|
||||||
|
app.filter.push(c);
|
||||||
|
}
|
||||||
|
app.cursor_location += 1;
|
||||||
}
|
}
|
||||||
Key::Backspace => {
|
Key::Backspace => {
|
||||||
app.filter.pop();
|
if app.cursor_location > 0 {
|
||||||
|
app.cursor_location -= 1;
|
||||||
|
app.filter.remove(app.cursor_location);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue