feat: prompt on undo

This commit is contained in:
Dheepak Krishnamurthy 2023-08-25 00:49:53 -04:00
parent 499894487b
commit 73c7eee3b6
6 changed files with 95 additions and 21 deletions

View file

@ -1,13 +1,15 @@
# Advanced configuration # Advanced configuration
`taskwarrior-tui` parses the output of `task show` to get configuration data. `taskwarrior-tui` parses the output of `task show` to get configuration data. This allows
This allows `taskwarrior-tui` to use the same defaults as `taskwarrior` and configure additional options as required. `taskwarrior-tui` to use the same defaults as `taskwarrior` and configure additional options as
required.
## `taskrc` config file options: ## `taskrc` config file options:
Other `taskwarrior-tui` configuration options are possible using the user defined attribute feature of `taskwarrior`. Other `taskwarrior-tui` configuration options are possible using the user defined attribute feature
All `taskwarrior-tui` specific configuration options will begin with `uda.taskwarrior-tui.`. of `taskwarrior`. All `taskwarrior-tui` specific configuration options will begin with
The following is a full list of all the options available and their default values implemented by `taskwarrior-tui` if not defined in your `taskrc` file. `uda.taskwarrior-tui.`. The following is a full list of all the options available and their default
values implemented by `taskwarrior-tui` if not defined in your `taskrc` file.
```plaintext ```plaintext
uda.taskwarrior-tui.selection.indicator=• uda.taskwarrior-tui.selection.indicator=•
@ -24,6 +26,7 @@ uda.taskwarrior-tui.calendar.months-per-row=4
uda.taskwarrior-tui.task-report.show-info=true uda.taskwarrior-tui.task-report.show-info=true
uda.taskwarrior-tui.task-report.looping=true uda.taskwarrior-tui.task-report.looping=true
uda.taskwarrior-tui.task-report.jump-on-task-add=true uda.taskwarrior-tui.task-report.jump-on-task-add=true
uda.taskwarrior-tui.task-report.prompt-on-undo=false
uda.taskwarrior-tui.task-report.prompt-on-delete=false uda.taskwarrior-tui.task-report.prompt-on-delete=false
uda.taskwarrior-tui.task-report.prompt-on-done=false uda.taskwarrior-tui.task-report.prompt-on-done=false
uda.taskwarrior-tui.style.report.selection= uda.taskwarrior-tui.style.report.selection=
@ -42,16 +45,19 @@ uda.taskwarrior-tui.context-menu.select-on-move=false
uda.taskwarrior-tui.tabs.change-focus-rotate=false uda.taskwarrior-tui.tabs.change-focus-rotate=false
``` ```
The `uda.taskwarrior-tui.task-report.next.filter` variable defines the default view at program startup. Set this to any preconfigured report (`task reports`), or create your own report in taskwarrior and specify its name here. The `uda.taskwarrior-tui.task-report.next.filter` variable defines the default view at program
startup. Set this to any preconfigured report (`task reports`), or create your own report in
taskwarrior and specify its name here.
## commandline options: ## commandline options:
`-r`: specify a report to be shown, overrides `uda.taskwarrior-tui.task-report.next.filter` for this instance `-r`: specify a report to be shown, overrides `uda.taskwarrior-tui.task-report.next.filter` for this
instance
## Configure user defined shortcuts: ## Configure user defined shortcuts:
You can configure shortcuts to execute custom commands from your `taskwarrior`'s `taskrc` file (default: `~/.taskrc`). You can configure shortcuts to execute custom commands from your `taskwarrior`'s `taskrc` file
You can do this by mapping a shortcut to an executable file: (default: `~/.taskrc`). You can do this by mapping a shortcut to an executable file:
```plaintext ```plaintext
uda.taskwarrior-tui.shortcuts.1=~/.config/taskwarrior-tui/shortcut-scripts/add-personal-tag.sh uda.taskwarrior-tui.shortcuts.1=~/.config/taskwarrior-tui/shortcut-scripts/add-personal-tag.sh
@ -68,21 +74,22 @@ To make a file executable:
By default, keys `1`-`9` are available to run shortcuts. By default, keys `1`-`9` are available to run shortcuts.
When you hit the shortcut, the script will be executed with the `selected_tasks_uuid` as an argument: When you hit the shortcut, the script will be executed with the `selected_tasks_uuid` as an
argument:
```bash ```bash
~/.config/taskwarrior-tui/shortcut-scripts/add-personal-tag.sh $selected_tasks_uuid ~/.config/taskwarrior-tui/shortcut-scripts/add-personal-tag.sh $selected_tasks_uuid
``` ```
For example, you can add the `personal` tag to the currently selected task with the following script in `~/.config/taskwarrior-tui/shortcut-scripts/add-personal-tag.sh` : For example, you can add the `personal` tag to the currently selected task with the following script
in `~/.config/taskwarrior-tui/shortcut-scripts/add-personal-tag.sh` :
```plaintext ```plaintext
task rc.bulk=0 rc.confirmation=off rc.dependency.confirmation=off rc.recurrence.confirmation=off "$@" modify +personal task rc.bulk=0 rc.confirmation=off rc.dependency.confirmation=off rc.recurrence.confirmation=off "$@" modify +personal
``` ```
By default, shortcuts are linked to the `1-9` number row keys. By default, shortcuts are linked to the `1-9` number row keys. They can be customized as any other
They can be customized as any other keys through `uda.taskwarrior-tui.keyconfig.shortcut1=<key>`. keys through `uda.taskwarrior-tui.keyconfig.shortcut1=<key>`. For example:
For example:
```plaintext ```plaintext
uda.taskwarrior-tui.keyconfig.shortcut1=n uda.taskwarrior-tui.keyconfig.shortcut1=n
@ -99,4 +106,8 @@ uda.taskwarrior-tui.background_process=task sync
uda.taskwarrior-tui.background_process_period=60 uda.taskwarrior-tui.background_process_period=60
``` ```
This will run `task sync` every 60 seconds. If the `background_process` is an empty string (default), then no process will be run. Only if the `background_process` is defined and if the `background_process` runs successfully, it'll be run every `background_process_period` number of seconds (default: 60 seconds). However, if it fails even once it won't be run again till `taskwarrior-tui` is restarted. This will run `task sync` every 60 seconds. If the `background_process` is an empty string
(default), then no process will be run. Only if the `background_process` is defined and if the
`background_process` runs successfully, it'll be run every `background_process_period` number of
seconds (default: 60 seconds). However, if it fails even once it won't be run again till
`taskwarrior-tui` is restarted.

View file

@ -1,4 +1,4 @@
.\" Automatically generated by Pandoc 2.19.2 .\" Automatically generated by Pandoc 3.1.6
.\" .\"
.\" Define V font for inline verbatim, using C font in formats .\" Define V font for inline verbatim, using C font in formats
.\" that render this, and otherwise B font. .\" that render this, and otherwise B font.

2
rust-toolchain.toml Normal file
View file

@ -0,0 +1,2 @@
[toolchain]
channel = "stable"

View file

@ -11,6 +11,7 @@ pub enum Action {
ContextMenu, ContextMenu,
Jump, Jump,
DeletePrompt, DeletePrompt,
UndoPrompt,
DonePrompt, DonePrompt,
Error, Error,
} }

View file

@ -867,6 +867,26 @@ impl TaskwarriorTui {
self.error.clone(), self.error.clone(),
); );
} }
Action::UndoPrompt => {
let label = "Run `task undo`?";
let k = match self.keyconfig.undo {
KeyCode::Char(c) => c.to_string(),
_ => "Enter".to_string(),
};
let q = match self.keyconfig.quit {
KeyCode::Char(c) => c.to_string(),
_ => "Esc".to_string(),
};
self.draw_command(
f,
rects[1],
&format!("Press <{}> to confirm or <{}> to abort.", k, q),
(Span::styled(label, Style::default().add_modifier(Modifier::BOLD)), None),
0,
false,
self.error.clone(),
);
}
} }
} }
@ -2583,6 +2603,12 @@ impl TaskwarriorTui {
} }
} }
} else if input == self.keyconfig.undo { } else if input == self.keyconfig.undo {
if self.config.uda_task_report_prompt_on_undo {
self.mode = Mode::Tasks(Action::UndoPrompt);
if self.task_current().is_none() {
self.mode = Mode::Tasks(Action::Report);
}
} else {
match self.task_undo() { match self.task_undo() {
Ok(_) => self.update(true).await?, Ok(_) => self.update(true).await?,
Err(e) => { Err(e) => {
@ -2590,6 +2616,7 @@ impl TaskwarriorTui {
self.mode = Mode::Tasks(Action::Error); self.mode = Mode::Tasks(Action::Error);
} }
} }
}
} else if input == self.keyconfig.modify { } else if input == self.keyconfig.modify {
self.mode = Mode::Tasks(Action::Modify); self.mode = Mode::Tasks(Action::Modify);
self.command_history.reset(); self.command_history.reset();
@ -3463,6 +3490,29 @@ impl TaskwarriorTui {
handle_movement(&mut self.command, input, &mut self.changes); handle_movement(&mut self.command, input, &mut self.changes);
} }
} }
Action::UndoPrompt => {
if input == self.keyconfig.undo || input == KeyCode::Char('\n') {
if self.error.is_some() {
self.previous_mode = Some(self.mode.clone());
self.mode = Mode::Tasks(Action::Error);
} else {
match self.task_undo() {
Ok(_) => {
self.mode = Mode::Tasks(Action::Report);
self.update(true).await?;
}
Err(e) => {
self.error = Some(e);
self.mode = Mode::Tasks(Action::Error);
}
}
}
} else if input == self.keyconfig.quit || input == KeyCode::Esc {
self.mode = Mode::Tasks(Action::Report);
} else {
handle_movement(&mut self.command, input, &mut self.changes);
}
}
Action::Error => { Action::Error => {
// since filter live updates, don't reset error status // since filter live updates, don't reset error status
// for other actions, resetting error to None is required otherwise user cannot // for other actions, resetting error to None is required otherwise user cannot

View file

@ -94,6 +94,7 @@ pub struct Config {
pub uda_background_process: String, pub uda_background_process: String,
pub uda_background_process_period: usize, pub uda_background_process_period: usize,
pub uda_quick_tag_name: String, pub uda_quick_tag_name: String,
pub uda_task_report_prompt_on_undo: bool,
pub uda_task_report_prompt_on_delete: bool, pub uda_task_report_prompt_on_delete: bool,
pub uda_task_report_prompt_on_done: bool, pub uda_task_report_prompt_on_done: bool,
pub uda_task_report_date_time_vague_more_precise: bool, pub uda_task_report_date_time_vague_more_precise: bool,
@ -169,6 +170,7 @@ impl Config {
uda_style_report_completion_pane.unwrap_or_else(|| Style::default().fg(Color::Black).bg(Color::Rgb(223, 223, 223))); uda_style_report_completion_pane.unwrap_or_else(|| Style::default().fg(Color::Black).bg(Color::Rgb(223, 223, 223)));
let uda_style_report_completion_pane_highlight = uda_style_report_completion_pane_highlight.unwrap_or(uda_style_report_completion_pane); let uda_style_report_completion_pane_highlight = uda_style_report_completion_pane_highlight.unwrap_or(uda_style_report_completion_pane);
let uda_quick_tag_name = Self::get_uda_quick_tag_name(data); let uda_quick_tag_name = Self::get_uda_quick_tag_name(data);
let uda_task_report_prompt_on_undo = Self::get_uda_task_report_prompt_on_undo(data);
let uda_task_report_prompt_on_delete = Self::get_uda_task_report_prompt_on_delete(data); let uda_task_report_prompt_on_delete = Self::get_uda_task_report_prompt_on_delete(data);
let uda_task_report_prompt_on_done = Self::get_uda_task_report_prompt_on_done(data); let uda_task_report_prompt_on_done = Self::get_uda_task_report_prompt_on_done(data);
let uda_context_menu_select_on_move = Self::get_uda_context_menu_select_on_move(data); let uda_context_menu_select_on_move = Self::get_uda_context_menu_select_on_move(data);
@ -222,6 +224,7 @@ impl Config {
uda_background_process, uda_background_process,
uda_background_process_period, uda_background_process_period,
uda_quick_tag_name, uda_quick_tag_name,
uda_task_report_prompt_on_undo,
uda_task_report_prompt_on_delete, uda_task_report_prompt_on_delete,
uda_task_report_prompt_on_done, uda_task_report_prompt_on_done,
uda_task_report_date_time_vague_more_precise, uda_task_report_date_time_vague_more_precise,
@ -597,6 +600,13 @@ impl Config {
.unwrap_or(false) .unwrap_or(false)
} }
fn get_uda_task_report_prompt_on_undo(data: &str) -> bool {
Self::get_config("uda.taskwarrior-tui.task-report.prompt-on-undo", data)
.unwrap_or_default()
.get_bool()
.unwrap_or(false)
}
fn get_uda_task_report_prompt_on_delete(data: &str) -> bool { fn get_uda_task_report_prompt_on_delete(data: &str) -> bool {
Self::get_config("uda.taskwarrior-tui.task-report.prompt-on-delete", data) Self::get_config("uda.taskwarrior-tui.task-report.prompt-on-delete", data)
.unwrap_or_default() .unwrap_or_default()