Add months_per_row to configuration

This commit is contained in:
Dheepak Krishnamurthy 2020-10-22 15:07:18 -06:00
parent 0f8647382b
commit 6333e500f7
3 changed files with 25 additions and 8 deletions

View file

@ -444,7 +444,8 @@ impl TTApp {
let c = Calendar::default() let c = Calendar::default()
.block(Block::default().title("Calendar").borders(Borders::ALL)) .block(Block::default().title("Calendar").borders(Borders::ALL))
.year(self.calendar_year) .year(self.calendar_year)
.date_style(dates_with_styles); .date_style(dates_with_styles)
.months_per_row(self.config.uda_calendar_months_per_row);
f.render_widget(c, rects[0]); f.render_widget(c, rects[0]);
} }

View file

@ -71,6 +71,11 @@ impl<'a> Calendar<'a> {
self.date_style = date_style; self.date_style = date_style;
self self
} }
pub fn months_per_row(mut self, months_per_row: usize) -> Self {
self.months_per_row = months_per_row;
self
}
} }
impl <'a> Widget for Calendar<'a> { impl <'a> Widget for Calendar<'a> {
@ -137,14 +142,15 @@ impl <'a> Widget for Calendar<'a> {
y += 1; y += 1;
let x = area.x; let x = area.x;
let s = format!("{year:^width$}", year = year, width = area.width as usize - 4); let s = format!("{year:^width$}", year = year, width = area.width as usize);
let mut year = 0; let mut year = 0;
let mut style = Style::default().add_modifier(Modifier::UNDERLINED); let style = Style::default().add_modifier(Modifier::UNDERLINED);
if self.year + year as i32 == today.year() { if self.year + year as i32 == today.year() {
style = style.add_modifier(Modifier::BOLD) buf.set_string(x, y, &s, style.add_modifier(Modifier::BOLD));
} else {
buf.set_string(x, y, &s, style);
} }
buf.set_string(x, y, &s, style);
let startx = (area.width - 3 * 7 * self.months_per_row as u16 - self.months_per_row as u16) / 2; let startx = (area.width - 3 * 7 * self.months_per_row as u16 - self.months_per_row as u16) / 2;
y += 2; y += 2;
@ -216,14 +222,14 @@ impl <'a> Widget for Calendar<'a> {
} }
} }
startm += self.months_per_row; startm += self.months_per_row;
y += 1; y += 2;
if y + 8 > area.height { if y + 8 > area.height {
break break
} else if startm >= 12 { } else if startm >= 12 {
startm = 0; startm = 0;
year += 1; year += 1;
let x = area.x; let x = area.x;
let s = format!("{year:^width$}", year = self.year as usize + year, width = area.width as usize - 4); let s = format!("{year:^width$}", year = self.year as usize + year, width = area.width as usize);
let mut style = Style::default().add_modifier(Modifier::UNDERLINED); let mut style = Style::default().add_modifier(Modifier::UNDERLINED);
if self.year + year as i32 == today.year() { if self.year + year as i32 == today.year() {
style = style.add_modifier(Modifier::BOLD) style = style.add_modifier(Modifier::BOLD)

View file

@ -38,6 +38,7 @@ pub struct TConfig {
pub uda_selection_italic: bool, pub uda_selection_italic: bool,
pub uda_selection_dim: bool, pub uda_selection_dim: bool,
pub uda_selection_blink: bool, pub uda_selection_blink: bool,
pub uda_calendar_months_per_row: usize,
} }
impl TConfig { impl TConfig {
@ -54,6 +55,7 @@ impl TConfig {
uda_selection_italic: Self::get_uda_selection_italic(), uda_selection_italic: Self::get_uda_selection_italic(),
uda_selection_dim: Self::get_uda_selection_dim(), uda_selection_dim: Self::get_uda_selection_dim(),
uda_selection_blink: Self::get_uda_selection_blink(), uda_selection_blink: Self::get_uda_selection_blink(),
uda_calendar_months_per_row: Self::get_uda_months_per_row(),
} }
} }
@ -241,7 +243,7 @@ impl TConfig {
return line.trim_start_matches(config).trim_start().trim_end().to_string(); return line.trim_start_matches(config).trim_start().trim_end().to_string();
} }
} }
"".to_string() "".to_string()
} }
fn get_rule_precedence_color() -> Vec<String> { fn get_rule_precedence_color() -> Vec<String> {
@ -294,6 +296,14 @@ impl TConfig {
} }
} }
fn get_uda_months_per_row() -> usize {
let s = Self::get_config("uda.taskwarrior-tui.calendar.months_per_row");
match s.parse::<usize>() {
Ok(i) => i,
Err(e) => 4,
}
}
fn get_uda_selection_blink() -> bool { fn get_uda_selection_blink() -> bool {
let s = Self::get_config("uda.taskwarrior-tui.selection.blink"); let s = Self::get_config("uda.taskwarrior-tui.selection.blink");
if s == "yes" { if s == "yes" {