mirror of
https://github.com/kdheepak/taskwarrior-tui.git
synced 2025-08-23 20:16:41 +02:00
feat: shortcut to set priority are now hardcoded
By pressing H, M, L and N now the user has the possibility to set priority to selected task(s). No custom script is needed.
This commit is contained in:
parent
2baddb9bcd
commit
9158d004b0
2 changed files with 71 additions and 0 deletions
63
src/app.rs
63
src/app.rs
|
@ -2202,6 +2202,37 @@ impl TaskwarriorTui {
|
|||
r
|
||||
}
|
||||
|
||||
pub fn task_priority(&mut self, priority: &str) -> Result<(), String> {
|
||||
if self.tasks.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
let mut priority_arg = String::from("priority:");
|
||||
priority_arg.push_str(priority);
|
||||
let task_uuids = self.selected_task_uuids();
|
||||
let mut cmd = std::process::Command::new("task");
|
||||
cmd
|
||||
.arg("rc.bulk=0")
|
||||
.arg("rc.confirmation=off")
|
||||
.arg("rc.dependency.confirmation=off")
|
||||
.arg("rc.recurrence.confirmation=off")
|
||||
.arg("modify")
|
||||
.arg(&priority_arg);
|
||||
for task_uuid in &task_uuids {
|
||||
cmd.arg(task_uuid.to_string());
|
||||
}
|
||||
let output = cmd.output();
|
||||
let r = match output {
|
||||
Ok(_) => Ok(()),
|
||||
Err(_) => Err(format!(
|
||||
"Cannot run `task modify priority` for task `{}`. Check documentation for more information",
|
||||
task_uuids.iter().map(ToString::to_string).collect::<Vec<String>>().join(" ")
|
||||
)),
|
||||
};
|
||||
self.current_selection_uuid = None;
|
||||
self.current_selection_id = None;
|
||||
r
|
||||
}
|
||||
|
||||
pub fn task_undo(&mut self) -> Result<(), String> {
|
||||
let output = std::process::Command::new("task").arg("rc.confirmation=off").arg("undo").output();
|
||||
|
||||
|
@ -2697,6 +2728,38 @@ impl TaskwarriorTui {
|
|||
self.mode = Mode::Tasks(Action::Error);
|
||||
}
|
||||
}
|
||||
} else if input == self.keyconfig.priority_h {
|
||||
match self.task_priority("H") {
|
||||
Ok(_) => self.update(true).await?,
|
||||
Err(e) => {
|
||||
self.error = Some(e);
|
||||
self.mode = Mode::Tasks(Action::Error);
|
||||
}
|
||||
}
|
||||
} else if input == self.keyconfig.priority_m {
|
||||
match self.task_priority("M") {
|
||||
Ok(_) => self.update(true).await?,
|
||||
Err(e) => {
|
||||
self.error = Some(e);
|
||||
self.mode = Mode::Tasks(Action::Error);
|
||||
}
|
||||
}
|
||||
} else if input == self.keyconfig.priority_l {
|
||||
match self.task_priority("L") {
|
||||
Ok(_) => self.update(true).await?,
|
||||
Err(e) => {
|
||||
self.error = Some(e);
|
||||
self.mode = Mode::Tasks(Action::Error);
|
||||
}
|
||||
}
|
||||
} else if input == self.keyconfig.priority_n {
|
||||
match self.task_priority("") {
|
||||
Ok(_) => self.update(true).await?,
|
||||
Err(e) => {
|
||||
self.error = Some(e);
|
||||
self.mode = Mode::Tasks(Action::Error);
|
||||
}
|
||||
}
|
||||
} else if input == self.keyconfig.shortcut2 {
|
||||
match self.task_shortcut(2).await {
|
||||
Ok(_) => self.update(true).await?,
|
||||
|
|
|
@ -35,6 +35,10 @@ pub struct KeyConfig {
|
|||
pub context_menu: KeyCode,
|
||||
pub next_tab: KeyCode,
|
||||
pub previous_tab: KeyCode,
|
||||
pub priority_h: KeyCode,
|
||||
pub priority_m: KeyCode,
|
||||
pub priority_l: KeyCode,
|
||||
pub priority_n: KeyCode,
|
||||
pub shortcut0: KeyCode,
|
||||
pub shortcut1: KeyCode,
|
||||
pub shortcut2: KeyCode,
|
||||
|
@ -77,6 +81,10 @@ impl Default for KeyConfig {
|
|||
context_menu: KeyCode::Char('c'),
|
||||
next_tab: KeyCode::Char(']'),
|
||||
previous_tab: KeyCode::Char('['),
|
||||
priority_h: KeyCode::Char('H'),
|
||||
priority_m: KeyCode::Char('M'),
|
||||
priority_l: KeyCode::Char('L'),
|
||||
priority_n: KeyCode::Char('N'),
|
||||
shortcut0: KeyCode::Char('0'),
|
||||
shortcut1: KeyCode::Char('1'),
|
||||
shortcut2: KeyCode::Char('2'),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue