feat: Add scrollbar customizations

This commit is contained in:
Dheepak Krishnamurthy 2022-03-21 22:06:47 -06:00
parent ba3a98e09f
commit b61eceadc0
3 changed files with 29 additions and 1 deletions

View file

@ -1182,6 +1182,8 @@ impl TaskwarriorTui {
let mut widget = Scrollbar::new(pos, tasks.iter().len());
widget.pos_style = self.config.uda_style_report_scrollbar;
widget.pos_symbol = self.config.uda_scrollbar_indicator.clone();
widget.area_style = self.config.uda_style_report_scrollbar_area;
widget.area_symbol = self.config.uda_scrollbar_area.clone();
f.render_widget(widget, rect);
}
}

View file

@ -6,6 +6,7 @@ use std::str;
use tui::{
style::{Color, Modifier, Style},
symbols::bar::FULL,
symbols::line::DOUBLE_VERTICAL,
};
trait TaskWarriorBool {
@ -62,7 +63,9 @@ pub struct Config {
pub uda_mark_indicator: String,
pub uda_unmark_indicator: String,
pub uda_scrollbar_indicator: String,
pub uda_scrollbar_area: String,
pub uda_style_report_scrollbar: Style,
pub uda_style_report_scrollbar_area: Style,
pub uda_selection_bold: bool,
pub uda_selection_italic: bool,
pub uda_selection_dim: bool,
@ -119,6 +122,7 @@ impl Config {
let uda_mark_indicator = Self::get_uda_mark_indicator(data);
let uda_unmark_indicator = Self::get_uda_unmark_indicator(data);
let uda_scrollbar_indicator = Self::get_uda_scrollbar_indicator(data);
let uda_scrollbar_area = Self::get_uda_scrollbar_area(data);
let uda_selection_bold = Self::get_uda_selection_bold(data);
let uda_selection_italic = Self::get_uda_selection_italic(data);
let uda_selection_dim = Self::get_uda_selection_dim(data);
@ -127,6 +131,7 @@ impl Config {
let uda_calendar_months_per_row = Self::get_uda_months_per_row(data);
let uda_style_report_selection = Self::get_uda_style("report.selection", data);
let uda_style_report_scrollbar = Self::get_uda_style("report.scrollbar", data);
let uda_style_report_scrollbar_area = Self::get_uda_style("report.scrollbar.area", data);
let uda_style_calendar_title = Self::get_uda_style("calendar.title", data);
let uda_style_calendar_today = Self::get_uda_style("calendar.today", data);
let uda_style_context_active = Self::get_uda_style("context.active", data);
@ -138,6 +143,7 @@ impl Config {
let uda_style_report_selection = uda_style_report_selection.unwrap_or_default();
let uda_style_report_scrollbar =
uda_style_report_scrollbar.unwrap_or_else(|| Style::default().fg(Color::Black));
let uda_style_report_scrollbar_area = uda_style_report_scrollbar_area.unwrap_or_default();
let uda_style_calendar_title = uda_style_calendar_title.unwrap_or_default();
let uda_style_calendar_today =
uda_style_calendar_today.unwrap_or_else(|| Style::default().add_modifier(Modifier::BOLD));
@ -177,6 +183,7 @@ impl Config {
uda_mark_indicator,
uda_unmark_indicator,
uda_scrollbar_indicator,
uda_scrollbar_area,
uda_selection_bold,
uda_selection_italic,
uda_selection_dim,
@ -190,6 +197,7 @@ impl Config {
uda_style_report_completion_pane,
uda_style_report_completion_pane_highlight,
uda_style_report_scrollbar,
uda_style_report_scrollbar_area,
uda_shortcuts,
uda_background_process,
uda_background_process_period,
@ -609,6 +617,20 @@ impl Config {
),
}
}
fn get_uda_scrollbar_area(data: &str) -> String {
let area = Self::get_config("uda.taskwarrior-tui.scrollbar.area", data);
match area {
None => DOUBLE_VERTICAL.to_string(),
Some(area) => format!(
"{}",
area.chars()
.next()
.unwrap_or_else(|| DOUBLE_VERTICAL.to_string().chars().next().unwrap())
),
}
}
fn get_uda_mark_highlight_indicator(data: &str) -> String {
let indicator = Self::get_config("uda.taskwarrior-tui.mark-selection.indicator", data);
match indicator {

View file

@ -13,6 +13,8 @@ pub struct Scrollbar {
pub len: u16,
pub pos_style: Style,
pub pos_symbol: String,
pub area_style: Style,
pub area_symbol: String,
}
impl Scrollbar {
@ -22,6 +24,8 @@ impl Scrollbar {
len: len as u16,
pos_style: Style::default(),
pos_symbol: FULL.to_string(),
area_style: Style::default(),
area_symbol: DOUBLE_VERTICAL.to_string(),
}
}
}
@ -45,7 +49,7 @@ impl Widget for Scrollbar {
let (top, height) = { (area.top() + 3, area.height.saturating_sub(4)) };
for y in top..(top + height) {
buf.set_string(right, y, DOUBLE_VERTICAL, Style::default());
buf.set_string(right, y, self.area_symbol.clone(), self.area_style);
}
let progress = self.pos as f64 / self.len as f64;