summaryrefslogtreecommitdiffstats
path: root/ui/src/components
diff options
context:
space:
mode:
Diffstat (limited to 'ui/src/components')
-rw-r--r--ui/src/components/mail/listing.rs80
-rw-r--r--ui/src/components/mail/listing/compact.rs69
-rw-r--r--ui/src/components/mail/listing/conversations.rs71
-rw-r--r--ui/src/components/mail/view.rs36
-rw-r--r--ui/src/components/mail/view/envelope.rs10
-rw-r--r--ui/src/components/mail/view/html.rs5
-rw-r--r--ui/src/components/utilities.rs14
7 files changed, 118 insertions, 167 deletions
diff --git a/ui/src/components/mail/listing.rs b/ui/src/components/mail/listing.rs
index e317fcab..24446e5d 100644
--- a/ui/src/components/mail/listing.rs
+++ b/ui/src/components/mail/listing.rs
@@ -46,29 +46,21 @@ pub struct DataColumns {
#[derive(Debug, Default)]
/// Save theme colors to avoid looking them up again and again from settings
struct ColorCache {
- unseen_fg: Color,
- unseen_bg: Color,
- highlighted_fg: Color,
- highlighted_bg: Color,
- even_fg: Color,
- even_bg: Color,
- odd_fg: Color,
- odd_bg: Color,
- selected_bg: Color,
- attachment_flag_fg: Color,
- thread_snooze_flag_fg: Color,
+ unseen: ThemeAttribute,
+ highlighted: ThemeAttribute,
+ even: ThemeAttribute,
+ odd: ThemeAttribute,
+ selected: ThemeAttribute,
+ attachment_flag: ThemeAttribute,
+ thread_snooze_flag: ThemeAttribute,
/* Conversations */
- fg: Color,
- bg: Color,
- subject_fg: Color,
- subject_bg: Color,
- from_fg: Color,
- from_bg: Color,
- date_fg: Color,
- date_bg: Color,
- padding: Color,
- unseen_padding: Color,
+ general: ThemeAttribute,
+ subject: ThemeAttribute,
+ from: ThemeAttribute,
+ date: ThemeAttribute,
+ padding: ThemeAttribute,
+ unseen_padding: ThemeAttribute,
}
#[derive(Debug)]
@@ -1067,37 +1059,39 @@ impl Listing {
) = if must_highlight_account {
if self.cursor_pos.1 == idx {
(
- crate::conf::color(context, "mail.sidebar_highlighted_fg"),
- crate::conf::color(context, "mail.sidebar_highlighted_bg"),
- crate::conf::color(context, "mail.sidebar_highlighted_index_fg"),
- crate::conf::color(context, "mail.sidebar_highlighted_index_bg"),
- crate::conf::color(context, "mail.sidebar_highlighted_unread_count_fg"),
- crate::conf::color(context, "mail.sidebar_highlighted_unread_count_bg"),
+ crate::conf::value(context, "mail.sidebar_highlighted").fg,
+ crate::conf::value(context, "mail.sidebar_highlighted").bg,
+ crate::conf::value(context, "mail.sidebar_highlighted_index").fg,
+ crate::conf::value(context, "mail.sidebar_highlighted_index").bg,
+ crate::conf::value(context, "mail.sidebar_highlighted_unread_count").fg,
+ crate::conf::value(context, "mail.sidebar_highlighted_unread_count").bg,
)
} else {
(
- crate::conf::color(context, "mail.sidebar_highlighted_account_fg"),
- crate::conf::color(context, "mail.sidebar_highlighted_account_bg"),
- crate::conf::color(context, "mail.sidebar_highlighted_account_index_fg"),
- crate::conf::color(context, "mail.sidebar_highlighted_account_index_bg"),
- crate::conf::color(
+ crate::conf::value(context, "mail.sidebar_highlighted_account").fg,
+ crate::conf::value(context, "mail.sidebar_highlighted_account").bg,
+ crate::conf::value(context, "mail.sidebar_highlighted_account_index").fg,
+ crate::conf::value(context, "mail.sidebar_highlighted_account_index").bg,
+ crate::conf::value(
context,
- "mail.sidebar_highlighted_account_unread_count_fg",
- ),
- crate::conf::color(
+ "mail.sidebar_highlighted_account_unread_count",
+ )
+ .fg,
+ crate::conf::value(
context,
- "mail.sidebar_highlighted_account_unread_count_bg",
- ),
+ "mail.sidebar_highlighted_account_unread_count",
+ )
+ .bg,
)
}
} else {
(
- crate::conf::color(context, "mail.sidebar_fg"),
- crate::conf::color(context, "mail.sidebar_bg"),
- crate::conf::color(context, "mail.sidebar_index_fg"),
- crate::conf::color(context, "mail.sidebar_index_bg"),
- crate::conf::color(context, "mail.sidebar_unread_count_fg"),
- crate::conf::color(context, "mail.sidebar_unread_count_bg"),
+ crate::conf::value(context, "mail.sidebar").fg,
+ crate::conf::value(context, "mail.sidebar").bg,
+ crate::conf::value(context, "mail.sidebar_index").fg,
+ crate::conf::value(context, "mail.sidebar_index").bg,
+ crate::conf::value(context, "mail.sidebar_unread_count").fg,
+ crate::conf::value(context, "mail.sidebar_unread_count").bg,
)
};
diff --git a/ui/src/components/mail/listing/compact.rs b/ui/src/components/mail/listing/compact.rs
index fd66d725..9fa5df4d 100644
--- a/ui/src/components/mail/listing/compact.rs
+++ b/ui/src/components/mail/listing/compact.rs
@@ -127,24 +127,24 @@ impl ListingTrait for CompactListing {
let thread = threads.thread_ref(thread_hash);
let fg_color = if thread.unseen() > 0 {
- self.color_cache.unseen_fg
+ self.color_cache.unseen.fg
} else if self.cursor_pos.2 == idx {
- self.color_cache.highlighted_fg
+ self.color_cache.highlighted.fg
} else if idx % 2 == 0 {
- self.color_cache.even_fg
+ self.color_cache.even.fg
} else {
- self.color_cache.odd_fg
+ self.color_cache.odd.fg
};
let bg_color = if self.cursor_pos.2 == idx {
- self.color_cache.highlighted_bg
+ self.color_cache.highlighted.bg
} else if self.selection[&thread_hash] {
- self.color_cache.selected_bg
+ self.color_cache.selected.bg
} else if thread.unseen() > 0 {
- self.color_cache.unseen_bg
+ self.color_cache.unseen.bg
} else if idx % 2 == 0 {
- self.color_cache.even_bg
+ self.color_cache.even.bg
} else {
- self.color_cache.odd_bg
+ self.color_cache.odd.bg
};
let (upper_left, bottom_right) = area;
@@ -348,7 +348,7 @@ impl ListingTrait for CompactListing {
let c = &self.data_columns.columns[0][(0, r + top_idx)];
if self.selection[&thread_hash] {
- (c.fg(), self.color_cache.selected_bg)
+ (c.fg(), self.color_cache.selected.bg)
} else {
(c.fg(), c.bg())
}
@@ -632,20 +632,13 @@ impl CompactListing {
};
self.color_cache = ColorCache {
- unseen_fg: crate::conf::color(context, "mail.listing.compact.unseen_fg"),
- unseen_bg: crate::conf::color(context, "mail.listing.compact.unseen_bg"),
- highlighted_fg: crate::conf::color(context, "mail.listing.compact.highlighted_fg"),
- highlighted_bg: crate::conf::color(context, "mail.listing.compact.highlighted_bg"),
- even_fg: crate::conf::color(context, "mail.listing.compact.even_fg"),
- even_bg: crate::conf::color(context, "mail.listing.compact.even_bg"),
- odd_fg: crate::conf::color(context, "mail.listing.compact.odd_fg"),
- odd_bg: crate::conf::color(context, "mail.listing.compact.odd_bg"),
- selected_bg: crate::conf::color(context, "mail.listing.compact.selected_bg"),
- attachment_flag_fg: crate::conf::color(context, "mail.listing.attachment_flag_fg"),
- thread_snooze_flag_fg: crate::conf::color(
- context,
- "mail.listing.thread_snooze_flag_fg",
- ),
+ unseen: crate::conf::value(context, "mail.listing.compact.unseen"),
+ highlighted: crate::conf::value(context, "mail.listing.compact.highlighted"),
+ even: crate::conf::value(context, "mail.listing.compact.even"),
+ odd: crate::conf::value(context, "mail.listing.compact.odd"),
+ selected: crate::conf::value(context, "mail.listing.compact.selected"),
+ attachment_flag: crate::conf::value(context, "mail.listing.attachment_flag"),
+ thread_snooze_flag: crate::conf::value(context, "mail.listing.thread_snooze_flag"),
..self.color_cache
};
@@ -821,11 +814,11 @@ impl CompactListing {
}
let thread = threads.thread_ref(thread);
let (fg_color, bg_color) = if thread.unseen() > 0 {
- (self.color_cache.unseen_fg, self.color_cache.unseen_bg)
+ (self.color_cache.unseen.fg, self.color_cache.unseen.bg)
} else if idx % 2 == 0 {
- (self.color_cache.even_fg, self.color_cache.even_bg)
+ (self.color_cache.even.fg, self.color_cache.even.bg)
} else {
- (self.color_cache.odd_fg, self.color_cache.odd_bg)
+ (self.color_cache.odd.fg, self.color_cache.odd.bg)
};
let (x, _) = write_string_to_grid(
&idx.to_string(),
@@ -917,17 +910,17 @@ impl CompactListing {
match (thread.snoozed(), thread.has_attachments()) {
(true, true) => {
self.data_columns.columns[3][(0, idx)]
- .set_fg(self.color_cache.attachment_flag_fg);
+ .set_fg(self.color_cache.attachment_flag.fg);
self.data_columns.columns[3][(2, idx)]
- .set_fg(self.color_cache.thread_snooze_flag_fg);
+ .set_fg(self.color_cache.thread_snooze_flag.fg);
}
(true, false) => {
self.data_columns.columns[3][(0, idx)]
- .set_fg(self.color_cache.thread_snooze_flag_fg);
+ .set_fg(self.color_cache.thread_snooze_flag.fg);
}
(false, true) => {
self.data_columns.columns[3][(0, idx)]
- .set_fg(self.color_cache.attachment_flag_fg);
+ .set_fg(self.color_cache.attachment_flag.fg);
}
(false, false) => {}
}
@@ -982,11 +975,11 @@ impl CompactListing {
}
let idx = self.order[&thread_hash];
let (fg_color, bg_color) = if thread.unseen() > 0 {
- (self.color_cache.unseen_fg, self.color_cache.unseen_bg)
+ (self.color_cache.unseen.fg, self.color_cache.unseen.bg)
} else if idx % 2 == 0 {
- (self.color_cache.even_fg, self.color_cache.even_bg)
+ (self.color_cache.even.fg, self.color_cache.even.bg)
} else {
- (self.color_cache.odd_fg, self.color_cache.odd_bg)
+ (self.color_cache.odd.fg, self.color_cache.odd.bg)
};
let envelope: EnvelopeRef = account.collection.get_env(env_hash);
let strings = self.make_entry_string(&envelope, context, threads, thread_hash);
@@ -1092,14 +1085,14 @@ impl CompactListing {
}
match (thread.snoozed(), thread.has_attachments()) {
(true, true) => {
- columns[3][(0, idx)].set_fg(self.color_cache.attachment_flag_fg);
- columns[3][(2, idx)].set_fg(self.color_cache.thread_snooze_flag_fg);
+ columns[3][(0, idx)].set_fg(self.color_cache.attachment_flag.fg);
+ columns[3][(2, idx)].set_fg(self.color_cache.thread_snooze_flag.fg);
}
(true, false) => {
- columns[3][(0, idx)].set_fg(self.color_cache.thread_snooze_flag_fg);
+ columns[3][(0, idx)].set_fg(self.color_cache.thread_snooze_flag.fg);
}
(false, true) => {
- columns[3][(0, idx)].set_fg(self.color_cache.attachment_flag_fg);
+ columns[3][(0, idx)].set_fg(self.color_cache.attachment_flag.fg);
}
(false, false) => {}
}
diff --git a/ui/src/components/mail/listing/conversations.rs b/ui/src/components/mail/listing/conversations.rs
index 8c3ddb4b..9cf1bd24 100644
--- a/ui/src/components/mail/listing/conversations.rs
+++ b/ui/src/components/mail/listing/conversations.rs
@@ -106,18 +106,18 @@ impl ListingTrait for ConversationsListing {
let thread = threads.thread_ref(thread_hash);
let fg_color = if thread.unseen() > 0 {
- self.color_cache.unseen_fg
+ self.color_cache.unseen.fg
} else {
- self.color_cache.fg
+ self.color_cache.general.fg
};
let bg_color = if self.cursor_pos.2 == idx {
- self.color_cache.highlighted_bg
+ self.color_cache.highlighted.bg
} else if self.selection[&thread_hash] {
- self.color_cache.selected_bg
+ self.color_cache.selected.bg
} else if thread.unseen() > 0 {
- self.color_cache.unseen_bg
+ self.color_cache.unseen.bg
} else {
- self.color_cache.bg
+ self.color_cache.general.bg
};
copy_area(
@@ -127,7 +127,7 @@ impl ListingTrait for ConversationsListing {
((0, 3 * idx), pos_dec(self.content.size(), (1, 1))),
);
- let padding_fg = self.color_cache.padding;
+ let padding_fg = self.color_cache.padding.fg;
let (upper_left, bottom_right) = area;
let width = self.content.size().0;
@@ -292,7 +292,7 @@ impl ListingTrait for ConversationsListing {
/* fill any remaining columns, if our view is wider than self.content */
let width = self.content.size().0;
- let padding_fg = self.color_cache.padding;
+ let padding_fg = self.color_cache.padding.fg;
if width < width!(area) {
let y_offset = get_y(upper_left);
@@ -554,34 +554,19 @@ impl ConversationsListing {
};
self.color_cache = ColorCache {
- fg: crate::conf::color(context, "mail.listing.conversations.fg"),
- bg: crate::conf::color(context, "mail.listing.conversations.bg"),
- subject_fg: crate::conf::color(context, "mail.listing.conversations.subject_fg"),
- subject_bg: crate::conf::color(context, "mail.listing.conversations.subject_bg"),
- from_fg: crate::conf::color(context, "mail.listing.conversations.from_fg"),
- from_bg: crate::conf::color(context, "mail.listing.conversations.from_bg"),
- date_fg: crate::conf::color(context, "mail.listing.conversations.date_fg"),
- date_bg: crate::conf::color(context, "mail.listing.conversations.date_bg"),
- padding: crate::conf::color(context, "mail.listing.conversations.padding"),
- unseen_fg: crate::conf::color(context, "mail.listing.conversations.unseen_fg"),
- unseen_bg: crate::conf::color(context, "mail.listing.conversations.unseen_bg"),
- unseen_padding: crate::conf::color(
+ general: 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"),
+ padding: crate::conf::value(context, "mail.listing.conversations.padding"),
+ unseen: crate::conf::value(context, "mail.listing.conversations.unseen"),
+ unseen_padding: crate::conf::value(
context,
"mail.listing.conversations.unseen_padding",
),
- highlighted_fg: crate::conf::color(
- context,
- "mail.listing.conversations.highlighted_fg",
- ),
- highlighted_bg: crate::conf::color(
- context,
- "mail.listing.conversations.highlighted_bg",
- ),
- attachment_flag_fg: crate::conf::color(context, "mail.listing.attachment_flag_fg"),
- thread_snooze_flag_fg: crate::conf::color(
- context,
- "mail.listing.thread_snooze_flag_fg",
- ),
+ highlighted: crate::conf::value(context, "mail.listing.conversations.highlighted"),
+ attachment_flag: crate::conf::value(context, "mail.listing.attachment_flag"),
+ thread_snooze_flag: crate::conf::value(context, "mail.listing.thread_snooze_flag"),
..self.color_cache
};
@@ -711,7 +696,7 @@ impl ConversationsListing {
self.content =
CellBuffer::new_with_context(width, 4 * rows.len(), Cell::with_char(' '), context);
- let padding_fg = self.color_cache.padding;
+ let padding_fg = self.color_cache.padding.fg;
for ((idx, (thread, root_env_hash)), strings) in rows {
if !context.accounts[self.cursor_pos.0].contains_key(root_env_hash) {
@@ -719,14 +704,14 @@ impl ConversationsListing {
}
let thread = threads.thread_ref(thread);
let fg_color = if thread.unseen() > 0 {
- self.color_cache.unseen_fg
+ self.color_cache.unseen.fg
} else {
- self.color_cache.fg
+ self.color_cache.general.fg
};
let bg_color = if thread.unseen() > 0 {
- self.color_cache.unseen_bg
+ self.color_cache.unseen.bg
} else {
- self.color_cache.bg
+ self.color_cache.general.bg
};
/* draw flags */
let (x, _) = write_string_to_grid(
@@ -891,16 +876,16 @@ impl ConversationsListing {
let env_hash = threads.thread_nodes()[&thread_node_hash].message().unwrap();
let fg_color = if thread.unseen() > 0 {
- self.color_cache.unseen_fg
+ self.color_cache.unseen.fg
} else {
- self.color_cache.fg
+ self.color_cache.general.fg
};
let bg_color = if thread.unseen() > 0 {
- self.color_cache.unseen_bg
+ self.color_cache.unseen.bg
} else {
- self.color_cache.bg
+ self.color_cache.general.bg
};
- let padding_fg = self.color_cache.padding;
+ let padding_fg = self.color_cache.padding.fg;
let mut from_address_list = Vec::new();
let mut from_address_set: std::collections::HashSet<Vec<u8>> =
std::collections::HashSet::new();
diff --git a/ui/src/components/mail/view.rs b/ui/src/components/mail/view.rs
index 78458c64..4dac91e8 100644
--- a/ui/src/components/mail/view.rs
+++ b/ui/src/components/mail/view.rs
@@ -371,8 +371,7 @@ impl Component for MailView {
let account = &context.accounts[self.coordinates.0];
let envelope: EnvelopeRef = account.collection.get_env(self.coordinates.2);
- let headers_fg = crate::conf::color(context, "mail.view.headers_fg");
- let headers_bg = crate::conf::color(context, "mail.view.headers_bg");
+ let headers = crate::conf::value(context, "mail.view.headers");
if self.mode == ViewMode::Raw {
clear_area(grid, area);
@@ -394,9 +393,9 @@ impl Component for MailView {
let (_x, _y) = write_string_to_grid(
&$string,
grid,
- headers_fg,
- headers_bg,
- Attr::Default,
+ headers.fg,
+ headers.bg,
+ headers.attrs,
(set_y(upper_left, y), bottom_right),
Some(get_x(upper_left)),
);
@@ -446,9 +445,9 @@ impl Component for MailView {
let (_x, _) = write_string_to_grid(
"List-ID: ",
grid,
- headers_fg,
- headers_bg,
- Attr::Default,
+ headers.fg,
+ headers.bg,
+ headers.attrs,
(set_y(upper_left, y), bottom_right),
None,
);
@@ -474,9 +473,9 @@ impl Component for MailView {
let (_x, _y) = write_string_to_grid(
" Available actions: [ ",
grid,
- headers_fg,
- headers_bg,
- Attr::Default,
+ headers.fg,
+ headers.bg,
+ headers.attrs,
((x, y), bottom_right),
Some(get_x(upper_left)),
);
@@ -527,8 +526,9 @@ impl Component for MailView {
grid[(x - 2, y)].set_ch(' ');
}
if x > 0 {
- grid[(x - 1, y)].set_fg(headers_fg);
- grid[(x - 1, y)].set_bg(headers_bg);
+ grid[(x - 1, y)].set_fg(headers.fg);
+ grid[(x - 1, y)].set_bg(headers.bg);
+ grid[(x - 1, y)].set_attrs(headers.attrs);
grid[(x - 1, y)].set_ch(']');
}
}
@@ -646,10 +646,7 @@ impl Component for MailView {
.map(|v| String::from_utf8_lossy(v).into_owned())
.unwrap_or_else(|e| e.to_string())
};
- let colors = PagerColors {
- fg: crate::conf::color(context, "mail.view.body_fg"),
- bg: crate::conf::color(context, "mail.view.body_bg"),
- };
+ let colors = crate::conf::value(context, "mail.view.body");
self.pager = Pager::from_string(text, Some(context), None, None, colors);
}
ViewMode::Ansi(ref buf) => {
@@ -676,10 +673,7 @@ impl Component for MailView {
} else {
self.pager.cursor_pos()
};
- let colors = PagerColors {
- fg: crate::conf::color(context, "mail.view.body_fg"),
- bg: crate::conf::color(context, "mail.view.body_bg"),
- };
+ let colors = crate::conf::value(context, "mail.view.body");
self.pager =
Pager::from_string(text, Some(context), Some(cursor_pos), None, colors);
self.subview = None;
diff --git a/ui/src/components/mail/view/envelope.rs b/ui/src/components/mail/view/envelope.rs
index cddd4221..ef632171 100644
--- a/ui/src/components/mail/view/envelope.rs
+++ b/ui/src/components/mail/view/envelope.rs
@@ -339,10 +339,7 @@ impl Component for EnvelopeView {
} else {
self.pager.as_ref().map(Pager::cursor_pos)
};
- let colors = PagerColors {
- fg: crate::conf::color(context, "mail.view.body_fg"),
- bg: crate::conf::color(context, "mail.view.body_bg"),
- };
+ let colors = crate::conf::value(context, "mail.view.body");
self.pager = Some(Pager::from_string(
text,
Some(context),
@@ -421,10 +418,7 @@ impl Component for EnvelopeView {
match u.content_type() {
ContentType::MessageRfc822 => {
self.mode = ViewMode::Subview;
- let colors = PagerColors {
- fg: crate::conf::color(context, "mail.view.body_fg"),
- bg: crate::conf::color(context, "mail.view.body_bg"),
- };
+ let colors = crate::conf::value(context, "mail.view.body");
self.subview = Some(Box::new(Pager::from_string(
String::from_utf8_lossy(&decode_rec(u, None)).to_string(),
Some(context),
diff --git a/ui/src/components/mail/view/html.rs b/ui/src/components/mail/view/html.rs
index 7e4ecbfc..7d750266 100644
--- a/ui/src/components/mail/view/html.rs
+++ b/ui/src/components/mail/view/html.rs
@@ -109,10 +109,7 @@ impl HtmlView {
s
});
}
- let colors = PagerColors {
- fg: crate::conf::color(context, "mail.view.body_fg"),
- bg: crate::conf::color(context, "mail.view.body_bg"),
- };
+ let colors = crate::conf::value(context, "mail.view.body");
let pager = Pager::from_string(display_text, None, None, None, colors);
HtmlView { pager, bytes, id }
}
diff --git a/ui/src/components/utilities.rs b/ui/src/components/utilities.rs
index 21f5ac89..46bde9e5 100644
--- a/ui/src/components/utilities.rs
+++ b/ui/src/components/utilities.rs
@@ -264,12 +264,6 @@ impl Component for VSplit {
}
}
-#[derive(Debug, Default, Clone, Copy)]
-pub struct PagerColors {
- pub fg: Color,
- pub bg: Color,
-}
-
#[derive(Debug, Clone, Copy)]
pub enum PageMovement {
Up(usize),
@@ -295,7 +289,7 @@ pub struct Pager {
minimum_width: usize,
dirty: bool,
- colors: PagerColors,
+ colors: ThemeAttribute,
initialised: bool,
content: CellBuffer,
movement: Option<PageMovement>,
@@ -346,7 +340,7 @@ impl Pager {
context: Option<&Context>,
cursor_pos: Option<usize>,
mut width: Option<usize>,
- colors: PagerColors,
+ colors: ThemeAttribute,
) -> Self {
let pager_filter: Option<&String> = if let Some(context) = context {
context.settings.pager.filter.as_ref()
@@ -435,7 +429,7 @@ impl Pager {
text: &str,
cursor_pos: Option<usize>,
width: Option<usize>,
- colors: PagerColors,
+ colors: ThemeAttribute,
) -> Self {
let lines: Vec<String> = if let Some(width) = width {
text.split_lines(width)
@@ -477,7 +471,7 @@ impl Pager {
..Default::default()
}
}
- pub fn print_string(content: &mut CellBuffer, lines: Vec<String>, colors: PagerColors) {
+ pub fn print_string(content: &mut CellBuffer, lines: Vec<String>, colors: ThemeAttribute) {
let width = content.size().0;
debug!(colors);
for (i, l) in lines.iter().enumerate() {