themes: add {even,odd}_unseen, {even,odd}_selected, {even,odd}_highlighted

Suggested in #21
master
Manos Pitsidianakis 2020-04-05 14:54:50 +03:00
parent e633434b93
commit d8135674df
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
5 changed files with 214 additions and 63 deletions

View File

@ -53,9 +53,15 @@ struct ColorCache {
unseen: ThemeAttribute, unseen: ThemeAttribute,
highlighted: ThemeAttribute, highlighted: ThemeAttribute,
selected: ThemeAttribute,
even: ThemeAttribute, even: ThemeAttribute,
odd: ThemeAttribute, odd: ThemeAttribute,
selected: ThemeAttribute, even_unseen: ThemeAttribute,
even_highlighted: ThemeAttribute,
even_selected: ThemeAttribute,
odd_unseen: ThemeAttribute,
odd_highlighted: ThemeAttribute,
odd_selected: ThemeAttribute,
attachment_flag: ThemeAttribute, attachment_flag: ThemeAttribute,
thread_snooze_flag: ThemeAttribute, thread_snooze_flag: ThemeAttribute,
tag_default: ThemeAttribute, tag_default: ThemeAttribute,

View File

@ -115,11 +115,14 @@ impl MailListingTrait for CompactListing {
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.compact.unseen"), even_unseen: crate::conf::value(context, "mail.listing.compact.even_unseen"),
highlighted: crate::conf::value(context, "mail.listing.compact.highlighted"), even_selected: crate::conf::value(context, "mail.listing.compact.even_selected"),
even_highlighted: crate::conf::value(context, "mail.listing.compact.even_highlighted"),
odd_unseen: crate::conf::value(context, "mail.listing.compact.odd_unseen"),
odd_selected: crate::conf::value(context, "mail.listing.compact.odd_selected"),
odd_highlighted: crate::conf::value(context, "mail.listing.compact.odd_highlighted"),
even: crate::conf::value(context, "mail.listing.compact.even"), even: crate::conf::value(context, "mail.listing.compact.even"),
odd: crate::conf::value(context, "mail.listing.compact.odd"), 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"), 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"), tag_default: crate::conf::value(context, "mail.listing.tag_default"),
@ -210,31 +213,63 @@ impl ListingTrait for CompactListing {
let thread = threads.thread_ref(thread_hash); let thread = threads.thread_ref(thread_hash);
let fg_color = if thread.unseen() > 0 { let fg_color = if thread.unseen() > 0 {
self.color_cache.unseen.fg if idx % 2 == 0 {
self.color_cache.even_unseen.fg
} else {
self.color_cache.odd_unseen.fg
}
} else if self.cursor_pos.2 == idx { } else if self.cursor_pos.2 == idx {
self.color_cache.highlighted.fg if idx % 2 == 0 {
self.color_cache.even_highlighted.fg
} else {
self.color_cache.odd_highlighted.fg
}
} else if idx % 2 == 0 { } else if idx % 2 == 0 {
self.color_cache.even.fg self.color_cache.even.fg
} else { } else {
self.color_cache.odd.fg self.color_cache.odd.fg
}; };
let bg_color = if self.cursor_pos.2 == idx { let bg_color = if self.cursor_pos.2 == idx {
self.color_cache.highlighted.bg if idx % 2 == 0 {
self.color_cache.even_highlighted.bg
} else {
self.color_cache.odd_highlighted.bg
}
} else if self.selection[&thread_hash] { } else if self.selection[&thread_hash] {
self.color_cache.selected.bg if idx % 2 == 0 {
self.color_cache.even_selected.bg
} else {
self.color_cache.odd_selected.bg
}
} else if thread.unseen() > 0 { } else if thread.unseen() > 0 {
self.color_cache.unseen.bg if idx % 2 == 0 {
self.color_cache.even_unseen.bg
} else {
self.color_cache.odd_unseen.bg
}
} else if idx % 2 == 0 { } else if idx % 2 == 0 {
self.color_cache.even.bg self.color_cache.even.bg
} else { } else {
self.color_cache.odd.bg self.color_cache.odd.bg
}; };
let attrs = if self.cursor_pos.2 == idx { let attrs = if self.cursor_pos.2 == idx {
self.color_cache.highlighted.attrs if idx % 2 == 0 {
self.color_cache.even_highlighted.attrs
} else {
self.color_cache.odd_highlighted.attrs
}
} else if self.selection[&thread_hash] { } else if self.selection[&thread_hash] {
self.color_cache.selected.attrs if idx % 2 == 0 {
self.color_cache.even_selected.attrs
} else {
self.color_cache.odd_selected.attrs
}
} else if thread.unseen() > 0 { } else if thread.unseen() > 0 {
self.color_cache.unseen.attrs if idx % 2 == 0 {
self.color_cache.even_unseen.attrs
} else {
self.color_cache.odd_unseen.attrs
}
} else if idx % 2 == 0 { } else if idx % 2 == 0 {
self.color_cache.even.attrs self.color_cache.even.attrs
} else { } else {
@ -851,7 +886,11 @@ impl CompactListing {
} }
let thread = threads.thread_ref(thread); let thread = threads.thread_ref(thread);
let row_attr = if thread.unseen() > 0 { let row_attr = if thread.unseen() > 0 {
self.color_cache.unseen if idx % 2 == 0 {
self.color_cache.even_unseen
} else {
self.color_cache.odd_unseen
}
} else if idx % 2 == 0 { } else if idx % 2 == 0 {
self.color_cache.even self.color_cache.even
} else { } else {
@ -1017,12 +1056,16 @@ impl CompactListing {
return; return;
} }
let idx = self.order[&thread_hash]; let idx = self.order[&thread_hash];
let (fg_color, bg_color) = if thread.unseen() > 0 { let row_attr = if thread.unseen() > 0 {
(self.color_cache.unseen.fg, self.color_cache.unseen.bg) if idx % 2 == 0 {
self.color_cache.even_unseen
} else {
self.color_cache.odd_unseen
}
} else if idx % 2 == 0 { } else if idx % 2 == 0 {
(self.color_cache.even.fg, self.color_cache.even.bg) self.color_cache.even
} else { } else {
(self.color_cache.odd.fg, self.color_cache.odd.bg) self.color_cache.odd
}; };
let envelope: EnvelopeRef = account.collection.get_env(env_hash); let envelope: EnvelopeRef = account.collection.get_env(env_hash);
let strings = self.make_entry_string(&envelope, context, threads, thread_hash); let strings = self.make_entry_string(&envelope, context, threads, thread_hash);
@ -1038,57 +1081,57 @@ impl CompactListing {
let (x, _) = write_string_to_grid( let (x, _) = write_string_to_grid(
&idx.to_string(), &idx.to_string(),
&mut columns[0], &mut columns[0],
fg_color, row_attr.fg,
bg_color, row_attr.bg,
Attr::DEFAULT, row_attr.attrs,
((0, idx), (min_width.0, idx)), ((0, idx), (min_width.0, idx)),
None, None,
); );
for c in columns[0].row_iter(x..min_width.0, idx) { for c in columns[0].row_iter(x..min_width.0, idx) {
columns[0][c].set_bg(bg_color); columns[0][c].set_bg(row_attr.bg);
} }
let (x, _) = write_string_to_grid( let (x, _) = write_string_to_grid(
&strings.date, &strings.date,
&mut columns[1], &mut columns[1],
fg_color, row_attr.fg,
bg_color, row_attr.bg,
Attr::DEFAULT, row_attr.attrs,
((0, idx), (min_width.1.saturating_sub(1), idx)), ((0, idx), (min_width.1.saturating_sub(1), idx)),
None, None,
); );
for c in columns[1].row_iter(x..min_width.1, idx) { for c in columns[1].row_iter(x..min_width.1, idx) {
columns[1][c].set_bg(bg_color); columns[1][c].set_bg(row_attr.bg);
} }
let (x, _) = write_string_to_grid( let (x, _) = write_string_to_grid(
&strings.from, &strings.from,
&mut columns[2], &mut columns[2],
fg_color, row_attr.fg,
bg_color, row_attr.bg,
Attr::DEFAULT, row_attr.attrs,
((0, idx), (min_width.2, idx)), ((0, idx), (min_width.2, idx)),
None, None,
); );
for c in columns[2].row_iter(x..min_width.2, idx) { for c in columns[2].row_iter(x..min_width.2, idx) {
columns[2][c].set_bg(bg_color); columns[2][c].set_bg(row_attr.bg);
} }
let (x, _) = write_string_to_grid( let (x, _) = write_string_to_grid(
&strings.flag, &strings.flag,
&mut columns[3], &mut columns[3],
fg_color, row_attr.fg,
bg_color, row_attr.bg,
Attr::DEFAULT, row_attr.attrs,
((0, idx), (min_width.3, idx)), ((0, idx), (min_width.3, idx)),
None, None,
); );
for c in columns[3].row_iter(x..min_width.3, idx) { for c in columns[3].row_iter(x..min_width.3, idx) {
columns[3][c].set_bg(bg_color); columns[3][c].set_bg(row_attr.bg);
} }
let (x, _) = write_string_to_grid( let (x, _) = write_string_to_grid(
&strings.subject, &strings.subject,
&mut columns[4], &mut columns[4],
fg_color, row_attr.fg,
bg_color, row_attr.bg,
Attr::DEFAULT, row_attr.attrs,
((0, idx), (min_width.4, idx)), ((0, idx), (min_width.4, idx)),
None, None,
); );
@ -1125,7 +1168,7 @@ impl CompactListing {
}; };
for c in columns[4].row_iter(x..min_width.4, idx) { for c in columns[4].row_iter(x..min_width.4, idx) {
columns[4][c].set_ch(' '); columns[4][c].set_ch(' ');
columns[4][c].set_bg(bg_color); columns[4][c].set_bg(row_attr.bg);
} }
match (thread.snoozed(), thread.has_attachments()) { match (thread.snoozed(), thread.has_attachments()) {
(true, true) => { (true, true) => {

View File

@ -100,7 +100,7 @@ impl MailListingTrait for ConversationsListing {
from: crate::conf::value(context, "mail.listing.conversations.from"), from: crate::conf::value(context, "mail.listing.conversations.from"),
date: crate::conf::value(context, "mail.listing.conversations.date"), date: crate::conf::value(context, "mail.listing.conversations.date"),
padding: crate::conf::value(context, "mail.listing.conversations.padding"), padding: crate::conf::value(context, "mail.listing.conversations.padding"),
selected: crate::conf::value(context, "mail.listing.compact.selected"), selected: crate::conf::value(context, "mail.listing.conversations.selected"),
unseen: crate::conf::value(context, "mail.listing.conversations.unseen"), unseen: crate::conf::value(context, "mail.listing.conversations.unseen"),
unseen_padding: crate::conf::value( unseen_padding: crate::conf::value(
context, context,
@ -560,7 +560,7 @@ impl fmt::Display for ConversationsListing {
} }
impl ConversationsListing { impl ConversationsListing {
const DESCRIPTION: &'static str = "compact listing"; const DESCRIPTION: &'static str = "conversations listing";
pub fn new(coordinates: (usize, MailboxHash)) -> Self { pub fn new(coordinates: (usize, MailboxHash)) -> Self {
ConversationsListing { ConversationsListing {
cursor_pos: (0, 1, 0), cursor_pos: (0, 1, 0),

View File

@ -116,11 +116,14 @@ impl MailListingTrait for PlainListing {
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.unseen"),
highlighted: crate::conf::value(context, "mail.listing.plain.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"),
selected: crate::conf::value(context, "mail.listing.plain.selected"), even_unseen: crate::conf::value(context, "mail.listing.plain.even_unseen"),
odd_unseen: crate::conf::value(context, "mail.listing.plain.odd_unseen"),
even_highlighted: crate::conf::value(context, "mail.listing.plain.even_highlighted"),
odd_highlighted: crate::conf::value(context, "mail.listing.plain.odd_highlighted"),
even_selected: crate::conf::value(context, "mail.listing.plain.even_selected"),
odd_selected: crate::conf::value(context, "mail.listing.plain.odd_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"), tag_default: crate::conf::value(context, "mail.listing.tag_default"),
@ -213,31 +216,63 @@ impl ListingTrait for PlainListing {
let envelope: EnvelopeRef = account.collection.get_env(i); let envelope: EnvelopeRef = account.collection.get_env(i);
let fg_color = if !envelope.is_seen() { let fg_color = if !envelope.is_seen() {
self.color_cache.unseen.fg if idx % 2 == 0 {
self.color_cache.even_unseen.fg
} else {
self.color_cache.odd_unseen.fg
}
} else if self.cursor_pos.2 == idx { } else if self.cursor_pos.2 == idx {
self.color_cache.highlighted.fg if idx % 2 == 0 {
self.color_cache.even_highlighted.fg
} else {
self.color_cache.odd_highlighted.fg
}
} else if idx % 2 == 0 { } else if idx % 2 == 0 {
self.color_cache.even.fg self.color_cache.even.fg
} else { } else {
self.color_cache.odd.fg self.color_cache.odd.fg
}; };
let bg_color = if self.cursor_pos.2 == idx { let bg_color = if self.cursor_pos.2 == idx {
self.color_cache.highlighted.bg if idx % 2 == 0 {
self.color_cache.even_highlighted.bg
} else {
self.color_cache.odd_highlighted.bg
}
} else if self.selection[&i] { } else if self.selection[&i] {
self.color_cache.selected.bg if idx % 2 == 0 {
self.color_cache.even_selected.bg
} else {
self.color_cache.odd_selected.bg
}
} else if !envelope.is_seen() { } else if !envelope.is_seen() {
self.color_cache.unseen.bg if idx % 2 == 0 {
self.color_cache.even_unseen.bg
} else {
self.color_cache.odd_unseen.bg
}
} else if idx % 2 == 0 { } else if idx % 2 == 0 {
self.color_cache.even.bg self.color_cache.even.bg
} else { } else {
self.color_cache.odd.bg self.color_cache.odd.bg
}; };
let attrs = if self.cursor_pos.2 == idx { let attrs = if self.cursor_pos.2 == idx {
self.color_cache.highlighted.attrs if idx % 2 == 0 {
self.color_cache.even_highlighted.attrs
} else {
self.color_cache.odd_highlighted.attrs
}
} else if self.selection[&i] { } else if self.selection[&i] {
self.color_cache.selected.attrs if idx % 2 == 0 {
self.color_cache.even_selected.attrs
} else {
self.color_cache.odd_selected.attrs
}
} else if !envelope.is_seen() { } else if !envelope.is_seen() {
self.color_cache.unseen.attrs if idx % 2 == 0 {
self.color_cache.even_unseen.attrs
} else {
self.color_cache.odd_unseen.attrs
}
} else if idx % 2 == 0 { } else if idx % 2 == 0 {
self.color_cache.even.attrs self.color_cache.even.attrs
} else { } else {
@ -791,7 +826,11 @@ impl PlainListing {
let envelope: EnvelopeRef = context.accounts[self.cursor_pos.0].collection.get_env(i); let envelope: EnvelopeRef = context.accounts[self.cursor_pos.0].collection.get_env(i);
let row_attr = if !envelope.is_seen() { let row_attr = if !envelope.is_seen() {
self.color_cache.unseen if idx % 2 == 0 {
self.color_cache.even_unseen
} else {
self.color_cache.odd_unseen
}
} else if idx % 2 == 0 { } else if idx % 2 == 0 {
self.color_cache.even self.color_cache.even
} else { } else {

View File

@ -174,14 +174,20 @@ const DEFAULT_KEYS: &'static [&'static str] = &[
"mail.sidebar_highlighted_account_index", "mail.sidebar_highlighted_account_index",
"mail.listing.compact.even", "mail.listing.compact.even",
"mail.listing.compact.odd", "mail.listing.compact.odd",
"mail.listing.compact.unseen", "mail.listing.compact.even_unseen",
"mail.listing.compact.selected", "mail.listing.compact.odd_unseen",
"mail.listing.compact.highlighted", "mail.listing.compact.even_selected",
"mail.listing.compact.odd_selected",
"mail.listing.compact.even_highlighted",
"mail.listing.compact.odd_highlighted",
"mail.listing.plain.even", "mail.listing.plain.even",
"mail.listing.plain.odd", "mail.listing.plain.odd",
"mail.listing.plain.unseen", "mail.listing.plain.even_unseen",
"mail.listing.plain.selected", "mail.listing.plain.odd_unseen",
"mail.listing.plain.highlighted", "mail.listing.plain.even_selected",
"mail.listing.plain.odd_selected",
"mail.listing.plain.even_highlighted",
"mail.listing.plain.odd_highlighted",
"mail.listing.conversations", "mail.listing.conversations",
"mail.listing.conversations.subject", "mail.listing.conversations.subject",
"mail.listing.conversations.from", "mail.listing.conversations.from",
@ -578,7 +584,7 @@ impl Default for Theme {
); );
add!("mail.listing.compact.odd"); add!("mail.listing.compact.odd");
add!( add!(
"mail.listing.compact.unseen", "mail.listing.compact.even_unseen",
dark = { dark = {
fg: Color::Byte(0), fg: Color::Byte(0),
bg: Color::Byte(251) bg: Color::Byte(251)
@ -588,7 +594,26 @@ impl Default for Theme {
bg: Color::Byte(251) bg: Color::Byte(251)
} }
); );
add!("mail.listing.compact.selected", add!(
"mail.listing.compact.odd_unseen",
dark = {
fg: Color::Byte(0),
bg: Color::Byte(251)
},
light = {
fg: Color::Byte(0),
bg: Color::Byte(251)
}
);
add!("mail.listing.compact.even_selected",
dark = {
bg: Color::Byte(210)
},
light = {
bg: Color::Byte(210)
}
);
add!("mail.listing.compact.odd_selected",
dark = { dark = {
bg: Color::Byte(210) bg: Color::Byte(210)
}, },
@ -597,7 +622,16 @@ impl Default for Theme {
} }
); );
add!( add!(
"mail.listing.compact.highlighted", "mail.listing.compact.even_highlighted",
dark = {
bg: Color::Byte(246)
},
light = {
bg: Color::Byte(244)
}
);
add!(
"mail.listing.compact.odd_highlighted",
dark = { dark = {
bg: Color::Byte(246) bg: Color::Byte(246)
}, },
@ -674,7 +708,7 @@ impl Default for Theme {
); );
add!("mail.listing.plain.odd"); add!("mail.listing.plain.odd");
add!( add!(
"mail.listing.plain.unseen", "mail.listing.plain.even_unseen",
dark = { dark = {
fg: Color::Byte(0), fg: Color::Byte(0),
bg: Color::Byte(251) bg: Color::Byte(251)
@ -685,7 +719,27 @@ impl Default for Theme {
bg: Color::Byte(251) bg: Color::Byte(251)
} }
); );
add!("mail.listing.plain.selected", add!(
"mail.listing.plain.odd_unseen",
dark = {
fg: Color::Byte(0),
bg: Color::Byte(251)
},
light = {
fg: Color::Byte(0),
bg: Color::Byte(251)
}
);
add!("mail.listing.plain.even_selected",
dark = {
bg: Color::Byte(210)
},
light = {
bg: Color::Byte(210)
}
);
add!("mail.listing.plain.odd_selected",
dark = { dark = {
bg: Color::Byte(210) bg: Color::Byte(210)
}, },
@ -694,7 +748,16 @@ impl Default for Theme {
} }
); );
add!( add!(
"mail.listing.plain.highlighted", "mail.listing.plain.even_highlighted",
dark = {
bg: Color::Byte(246)
},
light = {
bg: Color::Byte(244)
}
);
add!(
"mail.listing.plain.odd_highlighted",
dark = { dark = {
bg: Color::Byte(246) bg: Color::Byte(246)
}, },