Skip to content

Commit

Permalink
feat: shortcut to set priority are now hardcoded
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
katekorsaro committed Jan 16, 2024
1 parent 2baddb9 commit 9158d00
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
63 changes: 63 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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?,
Expand Down
8 changes: 8 additions & 0 deletions src/keyconfig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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'),
Expand Down

0 comments on commit 9158d00

Please sign in to comment.