From f15e569627ca7d94b01eecee0a8b2b04dd75d58f Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Mon, 27 Jan 2020 17:33:35 +0200 Subject: [PATCH] ui/themes: add status.{bar,notification} and theme_default keys - theme_default replaces general for all default colors/attributes - add status.{bar,notification} support --- ui/src/components/mail/listing.rs | 3 +- .../components/mail/listing/conversations.rs | 14 ++++----- ui/src/components/utilities.rs | 29 ++++++++++++------- ui/src/conf/themes.rs | 25 +++++++++------- ui/src/terminal/cells.rs | 13 +++++++++ 5 files changed, 54 insertions(+), 30 deletions(-) diff --git a/ui/src/components/mail/listing.rs b/ui/src/components/mail/listing.rs index 50bd3370..2e58a9f5 100644 --- a/ui/src/components/mail/listing.rs +++ b/ui/src/components/mail/listing.rs @@ -46,6 +46,8 @@ pub struct DataColumns { #[derive(Debug, Default)] /// Save theme colors to avoid looking them up again and again from settings struct ColorCache { + theme_default: ThemeAttribute, + unseen: ThemeAttribute, highlighted: ThemeAttribute, even: ThemeAttribute, @@ -55,7 +57,6 @@ struct ColorCache { thread_snooze_flag: ThemeAttribute, /* Conversations */ - general: ThemeAttribute, subject: ThemeAttribute, from: ThemeAttribute, date: ThemeAttribute, diff --git a/ui/src/components/mail/listing/conversations.rs b/ui/src/components/mail/listing/conversations.rs index 328e44b7..5fe9b225 100644 --- a/ui/src/components/mail/listing/conversations.rs +++ b/ui/src/components/mail/listing/conversations.rs @@ -108,7 +108,7 @@ impl ListingTrait for ConversationsListing { let fg_color = if thread.unseen() > 0 { self.color_cache.unseen.fg } else { - self.color_cache.general.fg + self.color_cache.theme_default.fg }; let bg_color = if self.cursor_pos.2 == idx { self.color_cache.highlighted.bg @@ -117,7 +117,7 @@ impl ListingTrait for ConversationsListing { } else if thread.unseen() > 0 { self.color_cache.unseen.bg } else { - self.color_cache.general.bg + self.color_cache.theme_default.bg }; copy_area( @@ -554,7 +554,7 @@ impl ConversationsListing { }; self.color_cache = ColorCache { - general: crate::conf::value(context, "mail.listing.conversations"), + theme_default: crate::conf::value(context, "mail.listing.conversations"), subject: crate::conf::value(context, "mail.listing.conversations.subject"), from: crate::conf::value(context, "mail.listing.conversations.from"), date: crate::conf::value(context, "mail.listing.conversations.date"), @@ -706,12 +706,12 @@ impl ConversationsListing { let fg_color = if thread.unseen() > 0 { self.color_cache.unseen.fg } else { - self.color_cache.general.fg + self.color_cache.theme_default.fg }; let bg_color = if thread.unseen() > 0 { self.color_cache.unseen.bg } else { - self.color_cache.general.bg + self.color_cache.theme_default.bg }; /* draw flags */ let (x, _) = write_string_to_grid( @@ -884,12 +884,12 @@ impl ConversationsListing { let fg_color = if thread.unseen() > 0 { self.color_cache.unseen.fg } else { - self.color_cache.general.fg + self.color_cache.theme_default.fg }; let bg_color = if thread.unseen() > 0 { self.color_cache.unseen.bg } else { - self.color_cache.general.bg + self.color_cache.theme_default.bg }; let padding_fg = self.color_cache.padding.fg; let mut from_address_list = Vec::new(); diff --git a/ui/src/components/utilities.rs b/ui/src/components/utilities.rs index a450278c..f19891a1 100644 --- a/ui/src/components/utilities.rs +++ b/ui/src/components/utilities.rs @@ -764,16 +764,23 @@ impl StatusBar { } } fn draw_status_bar(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) { - clear_area(grid, area); + let attribute = crate::conf::value(context, "status.bar"); let (x, y) = write_string_to_grid( &self.status, grid, - Color::Byte(123), - Color::Byte(26), - Attr::Default, + attribute.fg, + attribute.bg, + attribute.attrs, area, None, ); + for c in grid.row_iter_from(x.., y) { + grid[c] + .set_ch(' ') + .set_fg(attribute.fg) + .set_bg(attribute.bg) + .set_attrs(attribute.attrs); + } let offset = self.status.find('|').unwrap_or_else(|| self.status.len()); if y < get_y(bottom_right!(area)) + 1 { for x in get_x(upper_left!(area)) @@ -785,15 +792,16 @@ impl StatusBar { grid[(x, y)].set_attrs(Attr::Bold); } } + let noto_colors = crate::conf::value(context, "status.notification"); if self.cur_notification.is_some() { let (t, n) = self.cur_notification.as_ref().unwrap(); if std::time::Instant::now().duration_since(*t) < std::time::Duration::new(5, 0) { write_string_to_grid( n, grid, - Color::Byte(219), - Color::Byte(88), - Attr::Default, + noto_colors.fg, + noto_colors.bg, + noto_colors.attrs, ( (std::cmp::max(x, width!(area).saturating_sub(n.len())), y), bottom_right!(area), @@ -809,9 +817,9 @@ impl StatusBar { write_string_to_grid( &n, grid, - Color::Byte(219), - Color::Byte(88), - Attr::Default, + noto_colors.fg, + noto_colors.bg, + noto_colors.attrs, ( (std::cmp::max(x, width!(area).saturating_sub(n.len())), y), bottom_right!(area), @@ -831,7 +839,6 @@ impl StatusBar { } } - change_colors(grid, area, Color::Byte(123), Color::Byte(26)); context.dirty_areas.push_back(area); } diff --git a/ui/src/conf/themes.rs b/ui/src/conf/themes.rs index cbfd51ed..2f113116 100644 --- a/ui/src/conf/themes.rs +++ b/ui/src/conf/themes.rs @@ -143,11 +143,12 @@ fn unlink_attrs<'k, 't: 'k>( } const DEFAULT_KEYS: &'static [&'static str] = &[ - "general", - "general.status_bar", - "general.tab_focused", - "general.tab_unfocused", - "general.tab_bar", + "theme_default", + "status.bar", + "status.notification", + "tab.focused", + "tab.unfocused", + "tab.bar", "mail.sidebar", "mail.sidebar_unread_count", "mail.sidebar_index", @@ -180,7 +181,7 @@ const DEFAULT_KEYS: &'static [&'static str] = &[ "mail.listing.thread_snooze_flag", ]; -#[derive(Debug, Clone, Default, Copy, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Eq, Clone, Default, Copy, Serialize, Deserialize)] pub struct ThemeAttribute { pub fg: Color, pub bg: Color, @@ -395,11 +396,13 @@ impl Default for Theme { dark.insert($key.into(), ThemeAttributeInner::default()); }; } - add!("general"); - add!("general.status_bar"); - add!("general.tab_focused"); - add!("general.tab_unfocused"); - add!("general.tab_bar"); + add!("theme_default"); + add!("status.bar", dark = { fg: Color::Byte(123), bg: Color::Byte(26) }, light = { fg: Color::Byte(123), bg: Color::Byte(26) }); + add!("status.notification", dark = { fg: Color::Byte(219), bg: Color::Byte(88) }, light = { fg: Color::Byte(219), bg: Color::Byte(88) }); + + add!("tab.focused"); + add!("tab.unfocused"); + add!("tab.bar"); /* Mail Sidebar */ diff --git a/ui/src/terminal/cells.rs b/ui/src/terminal/cells.rs index 9e7b9161..394441bb 100644 --- a/ui/src/terminal/cells.rs +++ b/ui/src/terminal/cells.rs @@ -366,6 +366,19 @@ impl CellBuffer { RowIterator { row, col: 0..0 } } } + + /// row_iter() but with `RangeFrom`. + /// See `RowIterator` documentation. + pub fn row_iter_from(&self, bounds: std::ops::RangeFrom, row: usize) -> RowIterator { + if row < self.rows { + RowIterator { + row, + col: std::cmp::min(self.cols.saturating_sub(1), bounds.start)..self.cols, + } + } else { + RowIterator { row, col: 0..0 } + } + } } impl Deref for CellBuffer {