Add unmark mark highlight symbol

This commit is contained in:
Dheepak Krishnamurthy 2021-04-30 09:11:41 -06:00
parent 39176c44d5
commit c132454846
3 changed files with 50 additions and 4 deletions

View file

@ -12,6 +12,8 @@ uda.taskwarrior-tui.selection.dim=no
uda.taskwarrior-tui.selection.blink=no
uda.taskwarrior-tui.mark.indicator=✔
uda.taskwarrior-tui.unmark.indicator=
uda.taskwarrior-tui.mark-selection.indicator=⦿
uda.taskwarrior-tui.unmark-selection.indicator=⦾
uda.taskwarrior-tui.calendar.months-per-row=4
uda.taskwarrior-tui.task-report.show-info=true
uda.taskwarrior-tui.task-report.looping=true

View file

@ -417,6 +417,22 @@ impl Config {
}
}
fn get_uda_mark_highlight_indicator(data: &str) -> String {
let indicator = Self::get_config("uda.taskwarrior-tui.mark-selection.indicator", data);
match indicator {
None => "⦿ ".to_string(),
Some(indicator) => format!("{} ", indicator),
}
}
fn get_uda_unmark_highlight_indicator(data: &str) -> String {
let indicator = Self::get_config("uda.taskwarrior-tui.unmark-selection.indicator", data);
match indicator {
None => "".to_string(),
Some(indicator) => format!("{} ", indicator),
}
}
fn get_uda_selection_bold(data: &str) -> bool {
Self::get_config("uda.taskwarrior-tui.selection.bold", data)
.unwrap_or_default()

View file

@ -156,6 +156,10 @@ pub struct Table<'a, H, R> {
mark_symbol: Option<&'a str>,
/// Symbol in front of the unmarked row
unmark_symbol: Option<&'a str>,
/// Symbol in front of the marked and selected row
mark_highlight_symbol: Option<&'a str>,
/// Symbol in front of the unmarked and selected row
unmark_highlight_symbol: Option<&'a str>,
/// Data to display in each row
rows: R,
}
@ -178,6 +182,8 @@ where
highlight_symbol: None,
mark_symbol: None,
unmark_symbol: None,
mark_highlight_symbol: None,
unmark_highlight_symbol: None,
rows: R::default(),
}
}
@ -202,6 +208,8 @@ where
highlight_symbol: None,
mark_symbol: None,
unmark_symbol: None,
mark_highlight_symbol: None,
unmark_highlight_symbol: None,
rows,
}
}
@ -259,6 +267,16 @@ where
self
}
pub fn mark_highlight_symbol(mut self, mark_highlight_symbol: &'a str) -> Table<'a, H, R> {
self.mark_highlight_symbol = Some(mark_highlight_symbol);
self
}
pub fn unmark_highlight_symbol(mut self, unmark_highlight_symbol: &'a str) -> Table<'a, H, R> {
self.unmark_highlight_symbol = Some(unmark_highlight_symbol);
self
}
pub fn highlight_symbol(mut self, highlight_symbol: &'a str) -> Table<'a, H, R> {
self.highlight_symbol = Some(highlight_symbol);
self
@ -389,7 +407,7 @@ where
let mark_symbol = match state.mode {
TableMode::MultipleSelection => {
let s = self.mark_symbol.unwrap_or("").trim_end();
let s = self.mark_symbol.unwrap_or("").trim_end();
format!("{} ", s)
}
TableMode::SingleSelection => self.highlight_symbol.unwrap_or("").to_string(),
@ -397,12 +415,22 @@ where
let blank_symbol = match state.mode {
TableMode::MultipleSelection => {
let s = self.unmark_symbol.unwrap_or("").trim_end();
let s = self.unmark_symbol.unwrap_or(" ").trim_end();
format!("{} ", s)
}
TableMode::SingleSelection => iter::repeat(" ").take(highlight_symbol.width()).collect::<String>(),
};
let mark_highlight_symbol = {
let s = self.mark_highlight_symbol.unwrap_or("⦿").trim_end();
format!("{} ", s)
};
let unmark_highlight_symbol = {
let s = self.unmark_highlight_symbol.unwrap_or("").trim_end();
format!("{} ", s)
};
// Draw rows
let default_style = Style::default();
if y < table_area.bottom() {
@ -428,9 +456,9 @@ where
match state.mode {
TableMode::MultipleSelection => {
if state.marked.contains(&(i + state.offset)) {
(d, highlight_style, mark_symbol.to_string())
(d, highlight_style, mark_highlight_symbol.to_string())
} else {
(d, highlight_style, blank_symbol.to_string())
(d, highlight_style, unmark_highlight_symbol.to_string())
}
}
TableMode::SingleSelection => (d, highlight_style, highlight_symbol.to_string()),