mirror of
https://github.com/kdheepak/taskwarrior-tui.git
synced 2025-08-26 03:07:18 +02:00
Add shortcuts
This commit is contained in:
parent
a8556f3221
commit
078f117916
3 changed files with 155 additions and 0 deletions
123
src/app.rs
123
src/app.rs
|
@ -1083,6 +1083,49 @@ impl TTApp {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn task_shortcut(&mut self, s: usize) -> Result<(), String> {
|
||||
if self.tasks.lock().unwrap().is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
let selected = self.task_table_state.selected().unwrap_or_default();
|
||||
let task_id = self.tasks.lock().unwrap()[selected].id().unwrap_or_default();
|
||||
let task_uuid = *self.tasks.lock().unwrap()[selected].uuid();
|
||||
let shell = &self.config.uda_shortcuts[s];
|
||||
|
||||
if shell.is_empty() {
|
||||
return Err("Trying to run empty shortcut.".to_string());
|
||||
}
|
||||
|
||||
let shell = format!("{} {}", shell, task_uuid);
|
||||
match shlex::split(&shell) {
|
||||
Some(cmd) => {
|
||||
let mut command = Command::new(&cmd[0]);
|
||||
for s in cmd.iter().skip(1) {
|
||||
command.arg(&s);
|
||||
}
|
||||
let output = command.output();
|
||||
match output {
|
||||
Ok(o) => {
|
||||
if o.status.success() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(format!(
|
||||
"Unable to run shortcut {}. Failed with status code {}",
|
||||
s,
|
||||
o.status.code().unwrap()
|
||||
))
|
||||
}
|
||||
}
|
||||
Err(_) => Err(format!(
|
||||
"Cannot run `{}`. Check documentation for more information",
|
||||
shell,
|
||||
)),
|
||||
}
|
||||
}
|
||||
None => Err(format!("Unable to run `{}`. Cannot shlex split `{}`", shell, shell)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn task_modify(&mut self) -> Result<(), String> {
|
||||
if self.tasks.lock().unwrap().is_empty() {
|
||||
return Ok(());
|
||||
|
@ -1562,6 +1605,86 @@ impl TTApp {
|
|||
self.mode = AppMode::TaskHelpPopup;
|
||||
} else if input == self.keyconfig.filter {
|
||||
self.mode = AppMode::TaskFilter;
|
||||
} else if input == self.keyconfig.shortcut0 {
|
||||
match self.task_shortcut(0) {
|
||||
Ok(_) => self.update(true)?,
|
||||
Err(e) => {
|
||||
self.mode = AppMode::TaskError;
|
||||
self.error = e;
|
||||
}
|
||||
}
|
||||
} else if input == self.keyconfig.shortcut1 {
|
||||
match self.task_shortcut(1) {
|
||||
Ok(_) => self.update(true)?,
|
||||
Err(e) => {
|
||||
self.mode = AppMode::TaskError;
|
||||
self.error = e;
|
||||
}
|
||||
}
|
||||
} else if input == self.keyconfig.shortcut2 {
|
||||
match self.task_shortcut(2) {
|
||||
Ok(_) => self.update(true)?,
|
||||
Err(e) => {
|
||||
self.mode = AppMode::TaskError;
|
||||
self.error = e;
|
||||
}
|
||||
}
|
||||
} else if input == self.keyconfig.shortcut3 {
|
||||
match self.task_shortcut(3) {
|
||||
Ok(_) => self.update(true)?,
|
||||
Err(e) => {
|
||||
self.mode = AppMode::TaskError;
|
||||
self.error = e;
|
||||
}
|
||||
}
|
||||
} else if input == self.keyconfig.shortcut4 {
|
||||
match self.task_shortcut(4) {
|
||||
Ok(_) => self.update(true)?,
|
||||
Err(e) => {
|
||||
self.mode = AppMode::TaskError;
|
||||
self.error = e;
|
||||
}
|
||||
}
|
||||
} else if input == self.keyconfig.shortcut5 {
|
||||
match self.task_shortcut(5) {
|
||||
Ok(_) => self.update(true)?,
|
||||
Err(e) => {
|
||||
self.mode = AppMode::TaskError;
|
||||
self.error = e;
|
||||
}
|
||||
}
|
||||
} else if input == self.keyconfig.shortcut6 {
|
||||
match self.task_shortcut(6) {
|
||||
Ok(_) => self.update(true)?,
|
||||
Err(e) => {
|
||||
self.mode = AppMode::TaskError;
|
||||
self.error = e;
|
||||
}
|
||||
}
|
||||
} else if input == self.keyconfig.shortcut7 {
|
||||
match self.task_shortcut(7) {
|
||||
Ok(_) => self.update(true)?,
|
||||
Err(e) => {
|
||||
self.mode = AppMode::TaskError;
|
||||
self.error = e;
|
||||
}
|
||||
}
|
||||
} else if input == self.keyconfig.shortcut8 {
|
||||
match self.task_shortcut(8) {
|
||||
Ok(_) => self.update(true)?,
|
||||
Err(e) => {
|
||||
self.mode = AppMode::TaskError;
|
||||
self.error = e;
|
||||
}
|
||||
}
|
||||
} else if input == self.keyconfig.shortcut9 {
|
||||
match self.task_shortcut(9) {
|
||||
Ok(_) => self.update(true)?,
|
||||
Err(e) => {
|
||||
self.mode = AppMode::TaskError;
|
||||
self.error = e;
|
||||
}
|
||||
}
|
||||
} else if input == self.keyconfig.zoom {
|
||||
self.task_report_show_info = !self.task_report_show_info;
|
||||
} else if input == self.keyconfig.context_menu {
|
||||
|
|
|
@ -52,6 +52,7 @@ pub struct Config {
|
|||
pub uda_calendar_months_per_row: usize,
|
||||
pub uda_style_context_active: Style,
|
||||
pub uda_style_calendar_title: Style,
|
||||
pub uda_shortcuts: Vec<String>,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
|
@ -76,6 +77,7 @@ impl Config {
|
|||
uda_calendar_months_per_row: Self::get_uda_months_per_row(),
|
||||
uda_style_calendar_title: Self::get_uda_style("calendar.title").unwrap_or_default(),
|
||||
uda_style_context_active: Self::get_uda_style("context.active").unwrap_or_default(),
|
||||
uda_shortcuts: Self::get_uda_shortcuts(),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -83,6 +85,16 @@ impl Config {
|
|||
HashMap::new()
|
||||
}
|
||||
|
||||
fn get_uda_shortcuts() -> Vec<String> {
|
||||
let mut v = vec![];
|
||||
for s in 0..9 {
|
||||
let c = format!("uda.taskwarrior-tui.shortcuts.{}", s);
|
||||
let s = Self::get_config(&c);
|
||||
v.push(s);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
fn get_uda_style(config: &str) -> Option<Style> {
|
||||
let c = format!("uda.taskwarrior-tui.style.{}", config);
|
||||
let s = Self::get_config(&c);
|
||||
|
|
|
@ -31,6 +31,16 @@ pub struct KeyConfig {
|
|||
pub context_menu: Key,
|
||||
pub next_tab: Key,
|
||||
pub previous_tab: Key,
|
||||
pub shortcut0: Key,
|
||||
pub shortcut1: Key,
|
||||
pub shortcut2: Key,
|
||||
pub shortcut3: Key,
|
||||
pub shortcut4: Key,
|
||||
pub shortcut5: Key,
|
||||
pub shortcut6: Key,
|
||||
pub shortcut7: Key,
|
||||
pub shortcut8: Key,
|
||||
pub shortcut9: Key,
|
||||
}
|
||||
|
||||
impl Default for KeyConfig {
|
||||
|
@ -60,6 +70,16 @@ impl Default for KeyConfig {
|
|||
context_menu: Key::Char('c'),
|
||||
next_tab: Key::Char(']'),
|
||||
previous_tab: Key::Char('['),
|
||||
shortcut0: Key::Char('0'),
|
||||
shortcut1: Key::Char('1'),
|
||||
shortcut2: Key::Char('2'),
|
||||
shortcut3: Key::Char('3'),
|
||||
shortcut4: Key::Char('4'),
|
||||
shortcut5: Key::Char('5'),
|
||||
shortcut6: Key::Char('6'),
|
||||
shortcut7: Key::Char('7'),
|
||||
shortcut8: Key::Char('8'),
|
||||
shortcut9: Key::Char('9'),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue