Make mark and unmark indicators configurable

This commit is contained in:
Dheepak Krishnamurthy 2021-03-25 16:18:29 -06:00
parent 34f6dcca34
commit 93b9807fbe
3 changed files with 42 additions and 1 deletions

View file

@ -798,6 +798,8 @@ impl TTApp {
)
.highlight_style(highlight_style)
.highlight_symbol(&self.config.uda_selection_indicator)
.mark_symbol(&self.config.uda_mark_indicator)
.unmark_symbol(&self.config.uda_unmark_indicator)
.widths(&constraints);
f.render_stateful_widget(t, rect, &mut self.task_table_state);

View file

@ -45,6 +45,8 @@ pub struct Config {
pub uda_task_report_show_info: bool,
pub uda_task_report_looping: bool,
pub uda_selection_indicator: String,
pub uda_mark_indicator: String,
pub uda_unmark_indicator: String,
pub uda_selection_bold: bool,
pub uda_selection_italic: bool,
pub uda_selection_dim: bool,
@ -70,6 +72,8 @@ impl Config {
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_mark_indicator: Self::get_uda_mark_indicator(),
uda_unmark_indicator: Self::get_uda_unmark_indicator(),
uda_selection_bold: Self::get_uda_selection_bold(),
uda_selection_italic: Self::get_uda_selection_italic(),
uda_selection_dim: Self::get_uda_selection_dim(),
@ -335,6 +339,24 @@ impl Config {
}
}
fn get_uda_mark_indicator() -> String {
let indicator = Self::get_config("uda.taskwarrior-tui.mark.indicator");
if indicator.is_empty() {
"".to_string()
} else {
format!("{} ", indicator)
}
}
fn get_uda_unmark_indicator() -> String {
let indicator = Self::get_config("uda.taskwarrior-tui.unmark.indicator");
if indicator.is_empty() {
"".to_string()
} else {
format!("{} ", indicator)
}
}
fn get_uda_selection_bold() -> bool {
Self::get_config("uda.taskwarrior-tui.selection.bold")
.get_bool()

View file

@ -154,6 +154,8 @@ pub struct Table<'a, H, R> {
highlight_symbol: Option<&'a str>,
/// Symbol in front of the marked row
mark_symbol: Option<&'a str>,
/// Symbol in front of the unmarked row
unmark_symbol: Option<&'a str>,
/// Data to display in each row
rows: R,
}
@ -175,6 +177,7 @@ where
highlight_style: Style::default(),
highlight_symbol: None,
mark_symbol: None,
unmark_symbol: None,
rows: R::default(),
}
}
@ -198,6 +201,7 @@ where
highlight_style: Style::default(),
highlight_symbol: None,
mark_symbol: None,
unmark_symbol: None,
rows,
}
}
@ -245,6 +249,16 @@ where
self
}
pub fn mark_symbol(mut self, mark_symbol: &'a str) -> Table<'a, H, R> {
self.mark_symbol = Some(mark_symbol);
self
}
pub fn unmark_symbol(mut self, unmark_symbol: &'a str) -> Table<'a, H, R> {
self.unmark_symbol = Some(unmark_symbol);
self
}
pub fn highlight_symbol(mut self, highlight_symbol: &'a str) -> Table<'a, H, R> {
self.highlight_symbol = Some(highlight_symbol);
self
@ -382,7 +396,10 @@ where
};
let blank_symbol = match state.mode {
TableMode::MultipleSelection => "".to_string(),
TableMode::MultipleSelection => {
let s = self.unmark_symbol.unwrap_or("").trim_end();
format!("{} ", s)
}
TableMode::SingleSelection => iter::repeat(" ").take(highlight_symbol.width()).collect::<String>(),
};