mail/listing*: various theme color fixes

memfd
Manos Pitsidianakis 2020-07-26 02:03:45 +03:00
parent 74673880e6
commit 70a4409e59
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
4 changed files with 110 additions and 31 deletions

View File

@ -224,6 +224,9 @@ impl MailListingTrait for CompactListing {
}; };
if !context.settings.terminal.use_color() { if !context.settings.terminal.use_color() {
self.color_cache.highlighted.attrs |= Attr::REVERSE; self.color_cache.highlighted.attrs |= Attr::REVERSE;
self.color_cache.tag_default.attrs |= Attr::REVERSE;
self.color_cache.even_highlighted.attrs |= Attr::REVERSE;
self.color_cache.odd_highlighted.attrs |= Attr::REVERSE;
} }
// Get mailbox as a reference. // Get mailbox as a reference.

View File

@ -190,6 +190,7 @@ impl MailListingTrait for ConversationsListing {
if !context.settings.terminal.use_color() { if !context.settings.terminal.use_color() {
self.color_cache.highlighted.attrs |= Attr::REVERSE; self.color_cache.highlighted.attrs |= Attr::REVERSE;
self.color_cache.tag_default.attrs |= Attr::REVERSE;
} }
// Get mailbox as a reference. // Get mailbox as a reference.
// //

View File

@ -141,6 +141,9 @@ impl MailListingTrait for PlainListing {
}; };
if !context.settings.terminal.use_color() { if !context.settings.terminal.use_color() {
self.color_cache.highlighted.attrs |= Attr::REVERSE; self.color_cache.highlighted.attrs |= Attr::REVERSE;
self.color_cache.tag_default.attrs |= Attr::REVERSE;
self.color_cache.even_highlighted.attrs |= Attr::REVERSE;
self.color_cache.odd_highlighted.attrs |= Attr::REVERSE;
} }
// Get mailbox as a reference. // Get mailbox as a reference.

View File

@ -24,6 +24,82 @@ use crate::components::utilities::PageMovement;
use std::cmp; use std::cmp;
use std::convert::TryInto; use std::convert::TryInto;
macro_rules! row_attr {
($color_cache:expr, $even: expr, $unseen:expr, $highlighted:expr, $selected:expr $(,)*) => {{
ThemeAttribute {
fg: if $highlighted {
if $even {
$color_cache.even_highlighted.fg
} else {
$color_cache.odd_highlighted.fg
}
} else if $selected {
if $even {
$color_cache.even_selected.fg
} else {
$color_cache.odd_selected.fg
}
} else if $unseen {
if $even {
$color_cache.even_unseen.fg
} else {
$color_cache.odd_unseen.fg
}
} else if $even {
$color_cache.even.fg
} else {
$color_cache.odd.fg
},
bg: if $highlighted {
if $even {
$color_cache.even_highlighted.bg
} else {
$color_cache.odd_highlighted.bg
}
} else if $selected {
if $even {
$color_cache.even_selected.bg
} else {
$color_cache.odd_selected.bg
}
} else if $unseen {
if $even {
$color_cache.even_unseen.bg
} else {
$color_cache.odd_unseen.bg
}
} else if $even {
$color_cache.even.bg
} else {
$color_cache.odd.bg
},
attrs: if $highlighted {
if $even {
$color_cache.even_highlighted.attrs
} else {
$color_cache.odd_highlighted.attrs
}
} else if $selected {
if $even {
$color_cache.even_selected.attrs
} else {
$color_cache.odd_selected.attrs
}
} else if $unseen {
if $even {
$color_cache.even_unseen.attrs
} else {
$color_cache.odd_unseen.attrs
}
} else if $even {
$color_cache.even.attrs
} else {
$color_cache.odd.attrs
},
}
}};
}
/// A list of all mail (`Envelope`s) in a `Mailbox`. On `\n` it opens the `Envelope` content in a /// A list of all mail (`Envelope`s) in a `Mailbox`. On `\n` it opens the `Envelope` content in a
/// `MailView`. /// `MailView`.
#[derive(Debug)] #[derive(Debug)]
@ -80,19 +156,25 @@ impl MailListingTrait for ThreadListing {
self.cursor_pos.0 = self.new_cursor_pos.0; self.cursor_pos.0 = self.new_cursor_pos.0;
self.color_cache = ColorCache { self.color_cache = ColorCache {
unseen: crate::conf::value(context, "mail.listing.plain.even_unseen"), even_unseen: crate::conf::value(context, "mail.listing.plain.even_unseen"),
highlighted: crate::conf::value(context, "mail.listing.plain.even_highlighted"), even_selected: crate::conf::value(context, "mail.listing.plain.even_selected"),
even_highlighted: crate::conf::value(context, "mail.listing.plain.even_highlighted"),
odd_unseen: crate::conf::value(context, "mail.listing.plain.odd_unseen"),
odd_selected: crate::conf::value(context, "mail.listing.plain.odd_selected"),
odd_highlighted: crate::conf::value(context, "mail.listing.plain.odd_highlighted"),
even: crate::conf::value(context, "mail.listing.plain.even"), even: crate::conf::value(context, "mail.listing.plain.even"),
odd: crate::conf::value(context, "mail.listing.plain.odd"), odd: crate::conf::value(context, "mail.listing.plain.odd"),
even_unseen: crate::conf::value(context, "mail.listing.plain.even_unseen"),
odd_unseen: crate::conf::value(context, "mail.listing.plain.odd_unseen"),
selected: crate::conf::value(context, "mail.listing.plain.even_selected"),
attachment_flag: crate::conf::value(context, "mail.listing.attachment_flag"), attachment_flag: crate::conf::value(context, "mail.listing.attachment_flag"),
thread_snooze_flag: crate::conf::value(context, "mail.listing.thread_snooze_flag"), thread_snooze_flag: crate::conf::value(context, "mail.listing.thread_snooze_flag"),
tag_default: crate::conf::value(context, "mail.listing.tag_default"),
theme_default: crate::conf::value(context, "theme_default"),
..self.color_cache ..self.color_cache
}; };
if !context.settings.terminal.use_color() { if !context.settings.terminal.use_color() {
self.color_cache.highlighted.attrs |= Attr::REVERSE; self.color_cache.highlighted.attrs |= Attr::REVERSE;
self.color_cache.tag_default.attrs |= Attr::REVERSE;
self.color_cache.even_highlighted.attrs |= Attr::REVERSE;
self.color_cache.odd_highlighted.attrs |= Attr::REVERSE;
} }
// Get mailbox as a reference. // Get mailbox as a reference.
@ -636,21 +718,21 @@ impl ListingTrait for ThreadListing {
.collection .collection
.get_env(env_hash); .get_env(env_hash);
let fg_color = if !envelope.is_seen() { let row_attr = row_attr!(
Color::Byte(0) self.color_cache,
} else { idx % 2 == 0,
Color::Default !envelope.is_seen(),
}; self.cursor_pos.2 == idx,
let bg_color = if self.cursor_pos.2 == idx { false,
Color::Byte(246) );
} else if !envelope.is_seen() { for row in grid.bounds_iter(area) {
Color::Byte(251) for c in row {
} else if idx % 2 == 0 { grid[c]
Color::Byte(236) .set_fg(row_attr.fg)
} else { .set_bg(row_attr.bg)
Color::Default .set_attrs(row_attr.attrs);
}; }
change_colors(grid, area, fg_color, bg_color); }
} }
fn set_movement(&mut self, mvm: PageMovement) { fn set_movement(&mut self, mvm: PageMovement) {
@ -842,17 +924,7 @@ impl ThreadListing {
panic!(); panic!();
} }
let row_attr = if *is_seen { let row_attr = row_attr!(self.color_cache, idx % 2 == 0, !*is_seen, false, false,);
if idx % 2 == 0 {
self.color_cache.even
} else {
self.color_cache.odd
}
} else if idx % 2 == 0 {
self.color_cache.even_unseen
} else {
self.color_cache.odd_unseen
};
let (x, _) = write_string_to_grid( let (x, _) = write_string_to_grid(
&idx.to_string(), &idx.to_string(),
&mut self.data_columns.columns[0], &mut self.data_columns.columns[0],