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

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

View file

@ -867,6 +867,26 @@ impl TaskwarriorTui {
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,11 +2603,18 @@ impl TaskwarriorTui {
}
}
} else if input == self.keyconfig.undo {
match self.task_undo() {
Ok(_) => self.update(true).await?,
Err(e) => {
self.error = Some(e);
self.mode = Mode::Tasks(Action::Error);
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() {
Ok(_) => self.update(true).await?,
Err(e) => {
self.error = Some(e);
self.mode = Mode::Tasks(Action::Error);
}
}
}
} else if input == self.keyconfig.modify {
@ -3463,6 +3490,29 @@ impl TaskwarriorTui {
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 => {
// since filter live updates, don't reset error status
// 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_period: usize,
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_done: 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)));
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_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_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);
@ -222,6 +224,7 @@ impl Config {
uda_background_process,
uda_background_process_period,
uda_quick_tag_name,
uda_task_report_prompt_on_undo,
uda_task_report_prompt_on_delete,
uda_task_report_prompt_on_done,
uda_task_report_date_time_vague_more_precise,
@ -597,6 +600,13 @@ impl Config {
.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 {
Self::get_config("uda.taskwarrior-tui.task-report.prompt-on-delete", data)
.unwrap_or_default()