themes: add mail.sidebar_account_name key

memfd
Manos Pitsidianakis 2020-07-21 19:24:52 +03:00
parent 44ffbe54e2
commit 1bd89b3c96
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
3 changed files with 178 additions and 104 deletions

View File

@ -1352,13 +1352,18 @@ impl Listing {
} }
} }
let account_attrs = if must_highlight_account {
crate::conf::value(context, "mail.sidebar_highlighted_account_name")
} else {
crate::conf::value(context, "mail.sidebar_account_name")
};
/* Print account name first */ /* Print account name first */
write_string_to_grid( write_string_to_grid(
&a.name, &a.name,
grid, grid,
self.theme_default.fg, account_attrs.fg,
self.theme_default.bg, account_attrs.bg,
Attr::BOLD, account_attrs.attrs,
area, area,
None, None,
); );

View File

@ -24,6 +24,69 @@ use crate::components::utilities::PageMovement;
use crate::jobs::{oneshot, JobId}; use crate::jobs::{oneshot, JobId};
use std::iter::FromIterator; use std::iter::FromIterator;
macro_rules! row_attr {
($field:ident, $color_cache:expr, $unseen:expr, $highlighted:expr, $selected:expr $(,)*) => {{
let fg = if $unseen {
$color_cache.unseen.fg
} else if $highlighted {
$color_cache.highlighted.fg
} else if $selected {
$color_cache.selected.fg
} else {
$color_cache.$field.fg
};
let bg = if $unseen {
$color_cache.unseen.bg
} else if $highlighted {
$color_cache.highlighted.bg
} else if $selected {
$color_cache.selected.bg
} else {
$color_cache.$field.bg
};
let attrs = if $unseen {
$color_cache.unseen.attrs
} else if $highlighted {
$color_cache.highlighted.attrs
} else if $selected {
$color_cache.selected.attrs
} else {
$color_cache.$field.attrs
};
ThemeAttribute { fg, bg, attrs }
}};
($color_cache:expr, $unseen:expr, $highlighted:expr, $selected:expr $(,)*) => {{
let fg = if $unseen {
$color_cache.unseen.fg
} else if $highlighted {
$color_cache.highlighted.fg
} else if $selected {
$color_cache.selected.fg
} else {
$color_cache.theme_default.fg
};
let bg = if $unseen {
$color_cache.unseen.bg
} else if $highlighted {
$color_cache.highlighted.bg
} else if $selected {
$color_cache.selected.bg
} else {
$color_cache.theme_default.bg
};
let attrs = if $unseen {
$color_cache.unseen.attrs
} else if $highlighted {
$color_cache.highlighted.attrs
} else if $selected {
$color_cache.selected.attrs
} else {
$color_cache.theme_default.attrs
};
ThemeAttribute { fg, bg, 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
/// `ThreadView`. /// `ThreadView`.
#[derive(Debug)] #[derive(Debug)]
@ -295,36 +358,30 @@ impl MailListingTrait for ConversationsListing {
panic!(); panic!();
} }
let thread = threads.thread_ref(thread); let thread = threads.thread_ref(thread);
let fg_color = if thread.unseen() > 0 {
self.color_cache.unseen.fg let row_attr = row_attr!(self.color_cache, thread.unseen() > 0, false, false,);
} else {
self.color_cache.theme_default.fg
};
let bg_color = if thread.unseen() > 0 {
self.color_cache.unseen.bg
} else {
self.color_cache.theme_default.bg
};
/* draw flags */ /* draw flags */
let (x, _) = write_string_to_grid( let (x, _) = write_string_to_grid(
&strings.flag, &strings.flag,
&mut self.content, &mut self.content,
fg_color, row_attr.fg,
bg_color, row_attr.bg,
Attr::DEFAULT, row_attr.attrs,
((0, 3 * idx), (width - 1, 3 * idx)), ((0, 3 * idx), (width - 1, 3 * idx)),
None, None,
); );
for x in x..(x + 3) { for x in x..(x + 3) {
self.content[(x, 3 * idx)].set_bg(bg_color); self.content[(x, 3 * idx)].set_bg(row_attr.bg);
} }
let subject_attr =
row_attr!(subject, self.color_cache, thread.unseen() > 0, false, false);
/* draw subject */ /* draw subject */
let (mut x, _) = write_string_to_grid( let (mut x, _) = write_string_to_grid(
&strings.subject, &strings.subject,
&mut self.content, &mut self.content,
fg_color, subject_attr.fg,
bg_color, subject_attr.bg,
Attr::BOLD, subject_attr.attrs,
((x, 3 * idx), (width - 1, 3 * idx)), ((x, 3 * idx), (width - 1, 3 * idx)),
None, None,
); );
@ -354,32 +411,34 @@ impl MailListingTrait for ConversationsListing {
for x in x..width { for x in x..width {
self.content[(x, 3 * idx)] self.content[(x, 3 * idx)]
.set_ch(' ') .set_ch(' ')
.set_fg(fg_color) .set_fg(row_attr.fg)
.set_bg(bg_color); .set_bg(row_attr.bg);
} }
let date_attr = row_attr!(date, self.color_cache, thread.unseen() > 0, false, false);
/* Next line, draw date */ /* Next line, draw date */
let (x, _) = write_string_to_grid( let (x, _) = write_string_to_grid(
&strings.date, &strings.date,
&mut self.content, &mut self.content,
fg_color, date_attr.fg,
bg_color, date_attr.bg,
Attr::DEFAULT, date_attr.attrs,
((0, 3 * idx + 1), (width - 1, 3 * idx + 1)), ((0, 3 * idx + 1), (width - 1, 3 * idx + 1)),
None, None,
); );
for x in x..(x + 4) { for x in x..(x + 4) {
self.content[(x, 3 * idx + 1)] self.content[(x, 3 * idx + 1)]
.set_ch('▁') .set_ch('▁')
.set_fg(fg_color) .set_fg(row_attr.fg)
.set_bg(bg_color); .set_bg(row_attr.bg);
} }
let from_attr = row_attr!(from, self.color_cache, thread.unseen() > 0, false, false);
/* draw from */ /* draw from */
let (x, _) = write_string_to_grid( let (x, _) = write_string_to_grid(
&strings.from, &strings.from,
&mut self.content, &mut self.content,
fg_color, from_attr.fg,
bg_color, from_attr.bg,
Attr::DEFAULT, from_attr.attrs,
((x + 4, 3 * idx + 1), (width - 1, 3 * idx + 1)), ((x + 4, 3 * idx + 1), (width - 1, 3 * idx + 1)),
None, None,
); );
@ -387,14 +446,14 @@ impl MailListingTrait for ConversationsListing {
for x in x..width { for x in x..width {
self.content[(x, 3 * idx + 1)] self.content[(x, 3 * idx + 1)]
.set_ch('▁') .set_ch('▁')
.set_fg(fg_color) .set_fg(row_attr.fg)
.set_bg(bg_color); .set_bg(row_attr.bg);
} }
for x in 0..width { for x in 0..width {
self.content[(x, 3 * idx + 2)] self.content[(x, 3 * idx + 2)]
.set_ch('▓') .set_ch('▓')
.set_fg(padding_fg) .set_fg(padding_fg)
.set_bg(bg_color); .set_bg(row_attr.bg);
} }
} }
if self.length == 0 && self.filter_term.is_empty() { if self.length == 0 && self.filter_term.is_empty() {
@ -446,32 +505,17 @@ impl ListingTrait for ConversationsListing {
let threads = account.collection.get_threads(self.cursor_pos.1); let threads = account.collection.get_threads(self.cursor_pos.1);
let thread = threads.thread_ref(thread_hash); let thread = threads.thread_ref(thread_hash);
let fg_color = if thread.unseen() > 0 { let row_attr = row_attr!(
self.color_cache.unseen.fg self.color_cache,
} else if self.cursor_pos.2 == idx { thread.unseen() > 0,
self.color_cache.highlighted.fg self.cursor_pos.2 == idx,
} else if self.selection[&thread_hash] { self.selection[&thread_hash]
self.color_cache.selected.fg );
let padding_fg = if thread.unseen() > 0 {
self.color_cache.unseen_padding.fg
} else { } else {
self.color_cache.theme_default.fg self.color_cache.padding.fg
};
let bg_color = if self.cursor_pos.2 == idx {
self.color_cache.highlighted.bg
} else if self.selection[&thread_hash] {
self.color_cache.selected.bg
} else if thread.unseen() > 0 {
self.color_cache.unseen.bg
} else {
self.color_cache.theme_default.bg
};
let attrs = if self.cursor_pos.2 == idx {
self.color_cache.highlighted.attrs
} else if self.selection[&thread_hash] {
self.color_cache.selected.attrs
} else if thread.unseen() > 0 {
self.color_cache.unseen.attrs
} else {
self.color_cache.theme_default.attrs
}; };
copy_area( copy_area(
@ -480,46 +524,43 @@ impl ListingTrait for ConversationsListing {
area, area,
((0, 3 * idx), pos_dec(self.content.size(), (1, 1))), ((0, 3 * idx), pos_dec(self.content.size(), (1, 1))),
); );
let padding_fg = self.color_cache.padding.fg;
let (upper_left, bottom_right) = area; let (upper_left, bottom_right) = area;
let width = self.content.size().0; let width = self.content.size().0;
let (x, y) = upper_left; let (x, y) = upper_left;
if self.cursor_pos.2 == idx || self.selection[&thread_hash] { if self.cursor_pos.2 == idx || self.selection[&thread_hash] {
for x in x..=get_x(bottom_right) { for x in x..=get_x(bottom_right) {
grid[(x, y)] grid[(x, y)]
.set_fg(fg_color) .set_fg(row_attr.fg)
.set_bg(bg_color) .set_bg(row_attr.bg)
.set_attrs(attrs); .set_attrs(row_attr.attrs);
grid[(x, y + 1)] grid[(x, y + 1)]
.set_fg(fg_color) .set_fg(row_attr.fg)
.set_bg(bg_color) .set_bg(row_attr.bg)
.set_attrs(attrs); .set_attrs(row_attr.attrs);
grid[(x, y + 2)] grid[(x, y + 2)]
.set_fg(padding_fg) .set_fg(padding_fg)
.set_bg(bg_color) .set_bg(row_attr.bg)
.set_attrs(attrs); .set_attrs(row_attr.attrs);
} }
} else if width < width!(area) { } else if width < width!(area) {
/* fill any remaining columns, if our view is wider than self.content */ /* fill any remaining columns, if our view is wider than self.content */
for x in (x + width)..=get_x(bottom_right) { for x in (x + width)..=get_x(bottom_right) {
grid[(x, y)] grid[(x, y)]
.set_fg(fg_color) .set_fg(row_attr.fg)
.set_bg(bg_color) .set_bg(row_attr.bg)
.set_attrs(attrs); .set_attrs(row_attr.attrs);
grid[(x, y + 1)] grid[(x, y + 1)]
.set_fg(fg_color) .set_fg(row_attr.fg)
.set_bg(bg_color) .set_bg(row_attr.bg)
.set_attrs(attrs); .set_attrs(row_attr.attrs);
grid[(x, y + 2)] grid[(x, y + 2)]
.set_fg(padding_fg) .set_fg(padding_fg)
.set_bg(bg_color) .set_bg(row_attr.bg)
.set_attrs(attrs); .set_attrs(row_attr.attrs);
} }
} }
} }
@ -883,7 +924,7 @@ impl ConversationsListing {
if thread.len() > 1 { if thread.len() > 1 {
EntryStrings { EntryStrings {
date: DateString(ConversationsListing::format_date(context, thread.date())), date: DateString(ConversationsListing::format_date(context, thread.date())),
subject: SubjectString(format!("{} ({})", subject, thread.len(),)), subject: SubjectString(format!("{} ({})", subject, thread.len())),
flag: FlagString(format!( flag: FlagString(format!(
"{}{}", "{}{}",
if thread.has_attachments() { "📎" } else { "" }, if thread.has_attachments() { "📎" } else { "" },
@ -967,17 +1008,14 @@ impl ConversationsListing {
let env_hash = threads.thread_nodes()[&thread_node_hash].message().unwrap(); let env_hash = threads.thread_nodes()[&thread_node_hash].message().unwrap();
let fg_color = if thread.unseen() > 0 { let row_attr = row_attr!(self.color_cache, thread.unseen() > 0, false, false);
self.color_cache.unseen.fg
let padding_fg = if thread.unseen() > 0 {
self.color_cache.unseen_padding.fg
} else { } else {
self.color_cache.theme_default.fg self.color_cache.padding.fg
}; };
let bg_color = if thread.unseen() > 0 {
self.color_cache.unseen.bg
} else {
self.color_cache.theme_default.bg
};
let padding_fg = self.color_cache.padding.fg;
let mut from_address_list = Vec::new(); let mut from_address_list = Vec::new();
let mut from_address_set: std::collections::HashSet<Vec<u8>> = let mut from_address_set: std::collections::HashSet<Vec<u8>> =
std::collections::HashSet::new(); std::collections::HashSet::new();
@ -1008,22 +1046,23 @@ impl ConversationsListing {
let (x, _) = write_string_to_grid( let (x, _) = write_string_to_grid(
&strings.flag, &strings.flag,
&mut self.content, &mut self.content,
fg_color, row_attr.fg,
bg_color, row_attr.bg,
Attr::DEFAULT, row_attr.attrs,
((0, 3 * idx), (width - 1, 3 * idx)), ((0, 3 * idx), (width - 1, 3 * idx)),
None, None,
); );
for c in self.content.row_iter(x..(x + 4), 3 * idx) { for c in self.content.row_iter(x..(x + 4), 3 * idx) {
self.content[c].set_bg(bg_color); self.content[c].set_bg(row_attr.bg);
} }
let subject_attr = row_attr!(subject, self.color_cache, thread.unseen() > 0, false, false);
/* draw subject */ /* draw subject */
let (x, _) = write_string_to_grid( let (x, _) = write_string_to_grid(
&strings.subject, &strings.subject,
&mut self.content, &mut self.content,
fg_color, subject_attr.fg,
bg_color, subject_attr.bg,
Attr::BOLD, subject_attr.attrs,
((x, 3 * idx), (width - 1, 3 * idx)), ((x, 3 * idx), (width - 1, 3 * idx)),
None, None,
); );
@ -1060,41 +1099,43 @@ impl ConversationsListing {
}; };
for c in self.content.row_iter(x..width, 3 * idx) { for c in self.content.row_iter(x..width, 3 * idx) {
self.content[c].set_ch(' '); self.content[c].set_ch(' ');
self.content[c].set_bg(bg_color); self.content[c].set_bg(row_attr.bg);
} }
let date_attr = row_attr!(date, self.color_cache, thread.unseen() > 0, false, false);
/* Next line, draw date */ /* Next line, draw date */
let (x, _) = write_string_to_grid( let (x, _) = write_string_to_grid(
&strings.date, &strings.date,
&mut self.content, &mut self.content,
fg_color, date_attr.fg,
bg_color, date_attr.bg,
Attr::DEFAULT, date_attr.attrs,
((0, 3 * idx + 1), (width - 1, 3 * idx + 1)), ((0, 3 * idx + 1), (width - 1, 3 * idx + 1)),
None, None,
); );
for c in self.content.row_iter(x..(x + 5), 3 * idx + 1) { for c in self.content.row_iter(x..(x + 5), 3 * idx + 1) {
self.content[c].set_ch('▁'); self.content[c].set_ch('▁');
self.content[c].set_bg(bg_color); self.content[c].set_bg(row_attr.bg);
} }
let from_attr = row_attr!(from, self.color_cache, thread.unseen() > 0, false, false);
/* draw from */ /* draw from */
let (x, _) = write_string_to_grid( let (x, _) = write_string_to_grid(
&strings.from, &strings.from,
&mut self.content, &mut self.content,
fg_color, from_attr.fg,
bg_color, from_attr.bg,
Attr::DEFAULT, from_attr.attrs,
((x + 4, 3 * idx + 1), (width - 1, 3 * idx + 1)), ((x + 4, 3 * idx + 1), (width - 1, 3 * idx + 1)),
None, None,
); );
for c in self.content.row_iter(x..width, 3 * idx + 1) { for c in self.content.row_iter(x..width, 3 * idx + 1) {
self.content[c].set_ch('▁'); self.content[c].set_ch('▁');
self.content[c].set_bg(bg_color); self.content[c].set_bg(row_attr.bg);
} }
for c in self.content.row_iter(0..width, 3 * idx + 2) { for c in self.content.row_iter(0..width, 3 * idx + 2) {
self.content[c].set_ch('▓'); self.content[c].set_ch('▓');
self.content[c].set_fg(padding_fg); self.content[c].set_fg(padding_fg);
self.content[c].set_bg(bg_color); self.content[c].set_bg(row_attr.bg);
} }
} }
} }

View File

@ -254,9 +254,11 @@ const DEFAULT_KEYS: &[&str] = &[
"widgets.form.highlighted", "widgets.form.highlighted",
"widgets.options.highlighted", "widgets.options.highlighted",
"mail.sidebar", "mail.sidebar",
"mail.sidebar_account_name",
"mail.sidebar_unread_count", "mail.sidebar_unread_count",
"mail.sidebar_index", "mail.sidebar_index",
"mail.sidebar_highlighted", "mail.sidebar_highlighted",
"mail.sidebar_highlighted_account_name",
"mail.sidebar_highlighted_unread_count", "mail.sidebar_highlighted_unread_count",
"mail.sidebar_highlighted_index", "mail.sidebar_highlighted_index",
"mail.sidebar_highlighted_account", "mail.sidebar_highlighted_account",
@ -1319,6 +1321,19 @@ impl Default for Themes {
/* Mail Sidebar */ /* Mail Sidebar */
add!("mail.sidebar"); add!("mail.sidebar");
add!(
"mail.sidebar_account_name",
dark = {
fg: "mail.sidebar",
bg: "mail.sidebar",
attrs: Attr::BOLD,
},
light = {
fg: "mail.sidebar",
bg: "mail.sidebar",
attrs: Attr::BOLD,
}
);
add!("mail.sidebar_unread_count", dark = { fg: Color::Byte(243) }); add!("mail.sidebar_unread_count", dark = { fg: Color::Byte(243) });
add!("mail.sidebar_index", dark = { fg: Color::Byte(243) }); add!("mail.sidebar_index", dark = { fg: Color::Byte(243) });
add!("mail.sidebar_highlighted", dark = { fg: Color::Byte(233), bg: Color::Byte(15) }); add!("mail.sidebar_highlighted", dark = { fg: Color::Byte(233), bg: Color::Byte(15) });
@ -1351,6 +1366,19 @@ impl Default for Themes {
bg: Color::Byte(233), bg: Color::Byte(233),
} }
); );
add!(
"mail.sidebar_highlighted_account_name",
dark = {
fg: "mail.sidebar_highlighted_account",
bg: "mail.sidebar_highlighted_account",
attrs: Attr::BOLD,
},
light = {
fg: "mail.sidebar_highlighted_account",
bg: "mail.sidebar_highlighted_account",
attrs: Attr::BOLD,
}
);
add!( add!(
"mail.sidebar_highlighted_account_unread_count", "mail.sidebar_highlighted_account_unread_count",
light = { light = {