diff --git a/src/app.rs b/src/app.rs index ba4c9791..271e4d46 100644 --- a/src/app.rs +++ b/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::>().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?, diff --git a/src/keyconfig.rs b/src/keyconfig.rs index 8b8906b5..87680d34 100644 --- a/src/keyconfig.rs +++ b/src/keyconfig.rs @@ -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'),