From ae6e015069665657a0294a61d03c4c933f334405 Mon Sep 17 00:00:00 2001 From: Dheepak Krishnamurthy Date: Tue, 3 Nov 2020 12:32:17 -0700 Subject: [PATCH] Add configuration to disable looping --- README.md | 3 +++ src/app.rs | 24 ++++++++++++++++++++---- src/config.rs | 47 +++++++++++++++++++++++++++++------------------ 3 files changed, 52 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index d32c612..82fb836 100644 --- a/README.md +++ b/README.md @@ -183,6 +183,9 @@ uda.taskwarrior-tui.selection.dim=no uda.taskwarrior-tui.selection.blink=no uda.taskwarrior-tui.calendar.months-per-row=4 uda.taskwarrior-tui.task-report.show-detail=true +uda.taskwarrior-tui.task-report.looping=true +uda.taskwarrior-tui.style.context.active=black on rgb444 +uda.taskwarrior-tui.style.calendar.title=black on rgb444 ``` diff --git a/src/app.rs b/src/app.rs index 2be535a..b4ddd9b 100644 --- a/src/app.rs +++ b/src/app.rs @@ -686,7 +686,11 @@ impl TTApp { let i = match self.task_table_state.selected() { Some(i) => { if i >= self.tasks.lock().unwrap().len() - 1 { - 0 + if self.config.uda_task_report_looping { + 0 + } else { + i + } } else { i + 1 } @@ -703,7 +707,11 @@ impl TTApp { let i = match self.task_table_state.selected() { Some(i) => { if i == 0 { - self.tasks.lock().unwrap().len() - 1 + if self.config.uda_task_report_looping { + self.tasks.lock().unwrap().len() - 1 + } else { + 0 + } } else { i - 1 } @@ -720,7 +728,11 @@ impl TTApp { let i = match self.task_table_state.selected() { Some(i) => { if i >= self.tasks.lock().unwrap().len() - 1 { - 0 + if self.config.uda_task_report_looping { + 0 + } else { + i + } } else { i.checked_add(self.task_report_height as usize) .unwrap_or(self.tasks.lock().unwrap().len()) @@ -738,7 +750,11 @@ impl TTApp { let i = match self.task_table_state.selected() { Some(i) => { if i == 0 { - self.tasks.lock().unwrap().len() - 1 + if self.config.uda_task_report_looping { + self.tasks.lock().unwrap().len() - 1 + } else { + 0 + } } else { i.checked_sub(self.task_report_height as usize).unwrap_or(0) } diff --git a/src/config.rs b/src/config.rs index a91500b..25b2a68 100644 --- a/src/config.rs +++ b/src/config.rs @@ -33,24 +33,6 @@ impl TColor { } } -#[derive(Debug)] -pub struct Config { - pub enabled: bool, - pub color: HashMap, - pub obfuscate: bool, - pub print_empty_columns: bool, - pub rule_precedence_color: Vec, - pub uda_task_report_show_info: bool, - pub uda_selection_indicator: String, - pub uda_selection_bold: bool, - pub uda_selection_italic: bool, - pub uda_selection_dim: bool, - pub uda_selection_blink: bool, - pub uda_calendar_months_per_row: usize, - pub uda_style_context_active: TColor, - pub uda_style_calendar_title: TColor, -} - trait TaskWarriorBool { fn get_bool(&self) -> Option; } @@ -79,6 +61,26 @@ impl TaskWarriorBool for str { } } + +#[derive(Debug)] +pub struct Config { + pub enabled: bool, + pub color: HashMap, + pub obfuscate: bool, + pub print_empty_columns: bool, + pub rule_precedence_color: Vec, + pub uda_task_report_show_info: bool, + pub uda_task_report_looping: bool, + pub uda_selection_indicator: String, + pub uda_selection_bold: bool, + pub uda_selection_italic: bool, + pub uda_selection_dim: bool, + pub uda_selection_blink: bool, + pub uda_calendar_months_per_row: usize, + pub uda_style_context_active: TColor, + pub uda_style_calendar_title: TColor, +} + impl Config { pub fn default() -> Result> { let bool_collection = Self::get_bool_collection(); @@ -89,6 +91,7 @@ impl Config { color: Self::get_color_collection()?, rule_precedence_color: Self::get_rule_precedence_color(), uda_task_report_show_info: Self::get_uda_task_report_show_info(), + uda_task_report_looping: Self::get_uda_task_report_looping(), uda_selection_indicator: Self::get_uda_selection_indicator(), uda_selection_bold: Self::get_uda_selection_bold(), uda_selection_italic: Self::get_uda_selection_italic(), @@ -318,6 +321,14 @@ impl Config { } } + fn get_uda_task_report_looping() -> bool { + let s = Self::get_config("uda.taskwarrior-tui.task-report.looping"); + match s.get_bool() { + Some(b) => b, + None => true, + } + } + fn get_uda_selection_indicator() -> String { let indicator = Self::get_config("uda.taskwarrior-tui.selection.indicator"); if indicator.is_empty() {