diff --git a/docs/configuration/advanced.md b/docs/configuration/advanced.md index b114dfd..cde4041 100644 --- a/docs/configuration/advanced.md +++ b/docs/configuration/advanced.md @@ -19,6 +19,7 @@ uda.taskwarrior-tui.task-report.show-info=true uda.taskwarrior-tui.task-report.looping=true uda.taskwarrior-tui.task-report.jump-on-task-add=true uda.taskwarrior-tui.task-report.prompt-on-delete=false +uda.taskwarrior-tui.task-report.prompt-on-done=false uda.taskwarrior-tui.style.context.active=black on rgb444 uda.taskwarrior-tui.style.calendar.title=black on rgb444 uda.taskwarrior-tui.task-report.next.filter=$(task show report.next.filter) diff --git a/src/app.rs b/src/app.rs index 9d54cfb..119aff0 100644 --- a/src/app.rs +++ b/src/app.rs @@ -163,6 +163,7 @@ pub enum AppMode { TaskContextMenu, TaskJump, TaskDeletePrompt, + TaskDonePrompt, Calendar, } @@ -173,7 +174,6 @@ pub struct TaskwarriorTuiApp { pub context_table_state: TableState, pub current_context_filter: String, pub current_context: String, - pub delete: LineBuffer, pub command: LineBuffer, pub filter: LineBuffer, pub modify: LineBuffer, @@ -246,7 +246,6 @@ impl TaskwarriorTuiApp { current_selection_id: None, current_context_filter: "".to_string(), current_context: "".to_string(), - delete: LineBuffer::with_capacity(MAX_LINE), command: LineBuffer::with_capacity(MAX_LINE), filter: LineBuffer::with_capacity(MAX_LINE), modify: LineBuffer::with_capacity(MAX_LINE), @@ -316,6 +315,7 @@ impl TaskwarriorTuiApp { | AppMode::TaskAdd | AppMode::TaskAnnotate | AppMode::TaskContextMenu + | AppMode::TaskDonePrompt | AppMode::TaskDeletePrompt | AppMode::TaskError | AppMode::TaskHelpPopup @@ -579,6 +579,29 @@ impl TaskwarriorTuiApp { ); self.draw_context_menu(f, 80, 50); } + AppMode::TaskDonePrompt => { + let label = if task_ids.len() > 1 { + format!("Done Tasks {}?", task_ids.join(",")) + } else { + format!("Done Task {}?", task_ids.join(",")) + }; + let x = match self.keyconfig.done { + Key::Char(c) => c.to_string(), + _ => "Enter".to_string(), + }; + let q = match self.keyconfig.quit { + Key::Char(c) => c.to_string(), + _ => "Esc".to_string(), + }; + self.draw_command( + f, + rects[1], + &format!("Press <{}> to confirm or <{}> to abort.", x, q), + Span::styled(label, Style::default().add_modifier(Modifier::BOLD)), + 0, + false, + ); + } AppMode::TaskDeletePrompt => { let label = if task_ids.len() > 1 { format!("Delete Tasks {}?", task_ids.join(",")) @@ -1477,7 +1500,7 @@ impl TaskwarriorTuiApp { let shell = self.command.as_str(); - match shlex::split(&shell) { + match shlex::split(shell) { Some(cmd) => { // first argument must be a binary let mut command = Command::new(&cmd[0]); @@ -1509,7 +1532,7 @@ impl TaskwarriorTuiApp { let shell = self.command.as_str(); - match shlex::split(&shell) { + match shlex::split(shell) { Some(cmd) => { for s in cmd { command.arg(&s); @@ -1638,7 +1661,7 @@ impl TaskwarriorTuiApp { let shell = self.modify.as_str(); - let r = match shlex::split(&shell) { + let r = match shlex::split(shell) { Some(cmd) => { for s in cmd { command.arg(&s); @@ -1689,7 +1712,7 @@ impl TaskwarriorTuiApp { let shell = self.command.as_str(); - let r = match shlex::split(&shell) { + let r = match shlex::split(shell) { Some(cmd) => { for s in cmd { command.arg(&s); @@ -1731,7 +1754,7 @@ impl TaskwarriorTuiApp { let shell = self.command.as_str(); - match shlex::split(&shell) { + match shlex::split(shell) { Some(cmd) => { for s in cmd { command.arg(&s); @@ -2148,11 +2171,18 @@ impl TaskwarriorTuiApp { } else if input == Key::Ctrl('y') { self.task_details_scroll_up(); } else if input == self.keyconfig.done { - match self.task_done() { - Ok(_) => self.update(true)?, - Err(e) => { - self.mode = AppMode::TaskError; - self.error = e; + if self.config.uda_task_report_prompt_on_done { + self.mode = AppMode::TaskDonePrompt; + if self.task_current().is_none() { + self.mode = AppMode::TaskReport; + } + } else { + match self.task_done() { + Ok(_) => self.update(true)?, + Err(e) => { + self.mode = AppMode::TaskError; + self.error = e; + } } } } else if input == self.keyconfig.delete { @@ -2803,6 +2833,24 @@ impl TaskwarriorTuiApp { self.dirty = true; } }, + AppMode::TaskDonePrompt => { + if input == self.keyconfig.done || input == Key::Char('\n') { + match self.task_done() { + Ok(_) => { + self.mode = AppMode::TaskReport; + self.update(true)?; + } + Err(e) => { + self.mode = AppMode::TaskError; + self.error = e; + } + } + } else if input == self.keyconfig.quit || input == Key::Esc { + self.mode = AppMode::TaskReport; + } else { + handle_movement(&mut self.command, input); + } + } AppMode::TaskDeletePrompt => { if input == self.keyconfig.delete || input == Key::Char('\n') { match self.task_delete() { @@ -2816,7 +2864,6 @@ impl TaskwarriorTuiApp { } } } else if input == self.keyconfig.quit || input == Key::Esc { - self.delete.update("", 0); self.mode = AppMode::TaskReport; } else { handle_movement(&mut self.command, input); diff --git a/src/config.rs b/src/config.rs index 8e507a3..8da6b28 100644 --- a/src/config.rs +++ b/src/config.rs @@ -66,6 +66,7 @@ pub struct Config { pub uda_background_process: String, pub uda_background_process_period: usize, pub uda_task_report_prompt_on_delete: bool, + pub uda_task_report_prompt_on_done: bool, } impl Config { @@ -111,6 +112,7 @@ impl Config { let uda_style_report_completion_pane = uda_style_report_completion_pane.unwrap_or_else(|| Style::default().bg(Color::Rgb(223, 223, 223))); 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); Ok(Self { enabled, @@ -144,6 +146,7 @@ impl Config { uda_background_process, uda_background_process_period, uda_task_report_prompt_on_delete, + uda_task_report_prompt_on_done, }) } @@ -186,7 +189,7 @@ impl Config { let attribute = i.next(); let line = i.collect::>().join(" "); let line = line.trim_start_matches(' '); - let tcolor = Self::get_tcolor(&line); + let tcolor = Self::get_tcolor(line); if let Some(attr) = attribute { color_collection.insert(attr.to_string(), tcolor); }; @@ -451,6 +454,13 @@ impl Config { .unwrap_or(true) } + fn get_uda_task_report_prompt_on_done(data: &str) -> bool { + Self::get_config("uda.taskwarrior-tui.task-report.prompt-on-done", 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() diff --git a/src/table.rs b/src/table.rs index 0ce69b5..c0b0c89 100644 --- a/src/table.rs +++ b/src/table.rs @@ -418,7 +418,7 @@ where let s = self.unmark_symbol.unwrap_or(" ").trim_end(); format!("{} ", s) } - TableMode::SingleSelection => iter::repeat(" ").take(highlight_symbol.width()).collect::(), + TableMode::SingleSelection => " ".repeat(highlight_symbol.width()), }; let mark_highlight_symbol = { diff --git a/src/task_report.rs b/src/task_report.rs index 67d282a..f2d02c3 100644 --- a/src/task_report.rs +++ b/src/task_report.rs @@ -159,7 +159,7 @@ impl TaskReportTable { } let mut item = vec![]; for name in &self.columns { - let s = self.get_string_attribute(name, &task, tasks); + let s = self.get_string_attribute(name, task, tasks); item.push(s); } self.tasks.push(item)