Fix theme_default not being respected

jmap-eventsource
Manos Pitsidianakis 2020-11-23 00:33:20 +02:00
parent 714ccb5e16
commit 6dd3b0bb4f
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
4 changed files with 88 additions and 71 deletions

View File

@ -209,6 +209,7 @@ impl MailListingTrait for PlainListing {
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"),
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() {
@ -1066,9 +1067,9 @@ impl Component for PlainListing {
self.filter_term self.filter_term
), ),
grid, grid,
Color::Default, self.color_cache.theme_default.fg,
Color::Default, self.color_cache.theme_default.bg,
Attr::DEFAULT, self.color_cache.theme_default.attrs,
area, area,
Some(get_x(upper_left)), Some(get_x(upper_left)),
); );

View File

@ -1145,9 +1145,9 @@ impl Component for MailView {
let (_x, _y) = write_string_to_grid( let (_x, _y) = write_string_to_grid(
id, id,
grid, grid,
Color::Default, headers.fg,
Color::Default, headers.bg,
Attr::DEFAULT, headers.attrs,
((_x, y), bottom_right), ((_x, y), bottom_right),
None, None,
); );
@ -1177,9 +1177,9 @@ impl Component for MailView {
let (_x, _y) = write_string_to_grid( let (_x, _y) = write_string_to_grid(
"list-archive, ", "list-archive, ",
grid, grid,
Color::Default, headers.fg,
Color::Default, headers.bg,
Attr::DEFAULT, headers.attrs,
((x, y), bottom_right), ((x, y), bottom_right),
Some(get_x(upper_left)), Some(get_x(upper_left)),
); );
@ -1190,9 +1190,9 @@ impl Component for MailView {
let (_x, _y) = write_string_to_grid( let (_x, _y) = write_string_to_grid(
"list-post, ", "list-post, ",
grid, grid,
Color::Default, headers.fg,
Color::Default, headers.bg,
Attr::DEFAULT, headers.attrs,
((x, y), bottom_right), ((x, y), bottom_right),
Some(get_x(upper_left)), Some(get_x(upper_left)),
); );
@ -1203,9 +1203,9 @@ impl Component for MailView {
let (_x, _y) = write_string_to_grid( let (_x, _y) = write_string_to_grid(
"list-unsubscribe, ", "list-unsubscribe, ",
grid, grid,
Color::Default, headers.fg,
Color::Default, headers.bg,
Attr::DEFAULT, headers.attrs,
((x, y), bottom_right), ((x, y), bottom_right),
Some(get_x(upper_left)), Some(get_x(upper_left)),
); );
@ -1217,16 +1217,18 @@ impl Component for MailView {
grid[(x - 2, y)].set_ch(' '); grid[(x - 2, y)].set_ch(' ');
} }
if x > 0 { if x > 0 {
grid[(x - 1, y)].set_fg(headers.fg); grid[(x - 1, y)]
grid[(x - 1, y)].set_bg(headers.bg); .set_ch(']')
grid[(x - 1, y)].set_attrs(headers.attrs); .set_fg(headers.fg)
grid[(x - 1, y)].set_ch(']'); .set_bg(headers.bg)
.set_attrs(headers.attrs);
} }
} }
for x in x..=get_x(bottom_right) { for x in x..=get_x(bottom_right) {
grid[(x, y)].set_ch(' '); grid[(x, y)]
grid[(x, y)].set_bg(Color::Default); .set_ch(' ')
grid[(x, y)].set_fg(Color::Default); .set_fg(headers.fg)
.set_bg(headers.bg);
} }
y += 1; y += 1;
} }

View File

@ -233,6 +233,7 @@ impl ThreadView {
e.heading = string; e.heading = string;
width = cmp::max(width, e.index.0 * 4 + e.heading.grapheme_width() + 2); width = cmp::max(width, e.index.0 * 4 + e.heading.grapheme_width() + 2);
} }
let theme_default = crate::conf::value(context, "theme_default");
let mut content = CellBuffer::new_with_context(width, height, None, context); let mut content = CellBuffer::new_with_context(width, height, None, context);
if self.reversed { if self.reversed {
for (y, e) in self.entries.iter().rev().enumerate() { for (y, e) in self.entries.iter().rev().enumerate() {
@ -259,16 +260,16 @@ impl ThreadView {
&e.heading, &e.heading,
&mut content, &mut content,
if e.seen { if e.seen {
Color::Default theme_default.fg
} else { } else {
Color::Byte(0) Color::Byte(0)
}, },
if e.seen { if e.seen {
Color::Default theme_default.bg
} else { } else {
Color::Byte(251) Color::Byte(251)
}, },
Attr::DEFAULT, theme_default.attrs,
( (
(e.index.0 * 4 + 1, 2 * y), (e.index.0 * 4 + 1, 2 * y),
(e.index.0 * 4 + e.heading.grapheme_width() + 1, height - 1), (e.index.0 * 4 + e.heading.grapheme_width() + 1, height - 1),
@ -287,9 +288,7 @@ impl ThreadView {
if let Some(len) = highlight_reply_subjects[y] { if let Some(len) = highlight_reply_subjects[y] {
let index = e.index.0 * 4 + 1 + e.heading.grapheme_width() - len; let index = e.index.0 * 4 + 1 + e.heading.grapheme_width() - len;
let area = ((index, 2 * y), (width - 2, 2 * y)); let area = ((index, 2 * y), (width - 2, 2 * y));
let fg_color = Color::Byte(33); change_colors(&mut content, area, Color::Byte(33), theme_default.bg);
let bg_color = Color::Default;
change_colors(&mut content, area, fg_color, bg_color);
} }
set_and_join_box(&mut content, (e.index.0 * 4, 2 * y), BoxBoundary::Vertical); set_and_join_box(&mut content, (e.index.0 * 4, 2 * y), BoxBoundary::Vertical);
set_and_join_box( set_and_join_box(
@ -322,9 +321,9 @@ impl ThreadView {
let index = (e.index.0 * 4, 2 * y - 1); let index = (e.index.0 * 4, 2 * y - 1);
if content[index].ch() == ' ' { if content[index].ch() == ' ' {
let mut ctr = 1; let mut ctr = 1;
content[(e.index.0 * 4, 2 * y - 1)].set_bg(Color::Default); content[(e.index.0 * 4, 2 * y - 1)].set_bg(theme_default.bg);
while content.get(e.index.0 * 4 + ctr, 2 * y - 1).is_some() { while content.get(e.index.0 * 4 + ctr, 2 * y - 1).is_some() {
content[(e.index.0 * 4 + ctr, 2 * y - 1)].set_bg(Color::Default); content[(e.index.0 * 4 + ctr, 2 * y - 1)].set_bg(theme_default.bg);
if content[(e.index.0 * 4 + ctr, 2 * y - 1)].ch() != ' ' { if content[(e.index.0 * 4 + ctr, 2 * y - 1)].ch() != ' ' {
break; break;
} }
@ -342,16 +341,16 @@ impl ThreadView {
&e.heading, &e.heading,
&mut content, &mut content,
if e.seen { if e.seen {
Color::Default theme_default.fg
} else { } else {
Color::Byte(0) Color::Byte(0)
}, },
if e.seen { if e.seen {
Color::Default theme_default.bg
} else { } else {
Color::Byte(251) Color::Byte(251)
}, },
Attr::DEFAULT, theme_default.attrs,
( (
(e.index.0 * 4 + 1, 2 * y), (e.index.0 * 4 + 1, 2 * y),
(e.index.0 * 4 + e.heading.grapheme_width() + 1, height - 1), (e.index.0 * 4 + e.heading.grapheme_width() + 1, height - 1),
@ -370,9 +369,7 @@ impl ThreadView {
if let Some(_len) = highlight_reply_subjects[y] { if let Some(_len) = highlight_reply_subjects[y] {
let index = e.index.0 * 4 + 1; let index = e.index.0 * 4 + 1;
let area = ((index, 2 * y), (width - 2, 2 * y)); let area = ((index, 2 * y), (width - 2, 2 * y));
let fg_color = Color::Byte(33); change_colors(&mut content, area, Color::Byte(33), theme_default.bg);
let bg_color = Color::Default;
change_colors(&mut content, area, fg_color, bg_color);
} }
set_and_join_box(&mut content, (e.index.0 * 4, 2 * y), BoxBoundary::Vertical); set_and_join_box(&mut content, (e.index.0 * 4, 2 * y), BoxBoundary::Vertical);
set_and_join_box( set_and_join_box(
@ -413,26 +410,36 @@ impl ThreadView {
} }
} }
fn highlight_line(&self, grid: &mut CellBuffer, dest_area: Area, src_area: Area, idx: usize) { fn highlight_line(
&self,
grid: &mut CellBuffer,
dest_area: Area,
src_area: Area,
idx: usize,
context: &Context,
) {
let visibles: Vec<&usize> = self let visibles: Vec<&usize> = self
.visible_entries .visible_entries
.iter() .iter()
.flat_map(|ref v| v.iter()) .flat_map(|ref v| v.iter())
.collect(); .collect();
if idx == *visibles[self.cursor_pos] { if idx == *visibles[self.cursor_pos] {
let fg_color = Color::Default; let theme_default = crate::conf::value(context, "theme_default");
let bg_color = Color::Byte(246); let bg_color = Color::Byte(246);
let attrs = if self.use_color { let attrs = if self.use_color {
Attr::DEFAULT theme_default.attrs
} else { } else {
Attr::REVERSE Attr::REVERSE
}; };
for row in grid.bounds_iter(dest_area) { for row in grid.bounds_iter(dest_area) {
for c in row { for c in row {
grid[c].set_fg(fg_color).set_bg(bg_color).set_attrs(attrs); grid[c]
.set_fg(theme_default.fg)
.set_bg(bg_color)
.set_attrs(attrs);
} }
} }
change_colors(grid, dest_area, fg_color, bg_color); change_colors(grid, dest_area, theme_default.fg, bg_color);
return; return;
} }
@ -563,7 +570,7 @@ impl ThreadView {
), ),
); );
self.highlight_line(grid, dest_area, src_area, idx); self.highlight_line(grid, dest_area, src_area, idx, context);
if rows < visibles.len() { if rows < visibles.len() {
ScrollBar::default().draw( ScrollBar::default().draw(
grid, grid,
@ -623,7 +630,7 @@ impl ThreadView {
), ),
); );
self.highlight_line(grid, dest_area, src_area, entry_idx); self.highlight_line(grid, dest_area, src_area, entry_idx, context);
if rows < visibles.len() { if rows < visibles.len() {
ScrollBar::default().draw( ScrollBar::default().draw(
grid, grid,
@ -656,9 +663,10 @@ impl ThreadView {
let bottom_right = bottom_right!(area); let bottom_right = bottom_right!(area);
let mid = get_x(upper_left) + self.content.size().0; let mid = get_x(upper_left) + self.content.size().0;
let theme_default = crate::conf::value(context, "theme_default");
/* First draw the thread subject on the first row */ /* First draw the thread subject on the first row */
let y = if self.dirty { let y = if self.dirty {
clear_area(grid, area, crate::conf::value(context, "theme_default")); clear_area(grid, area, theme_default);
let account = &context.accounts[&self.coordinates.0]; let account = &context.accounts[&self.coordinates.0];
let threads = account.collection.get_threads(self.coordinates.1); let threads = account.collection.get_threads(self.coordinates.1);
let thread_root = threads let thread_root = threads
@ -680,15 +688,16 @@ impl ThreadView {
&envelope.subject(), &envelope.subject(),
grid, grid,
Color::Byte(33), Color::Byte(33),
Color::Default, theme_default.bg,
Attr::DEFAULT, theme_default.attrs,
area, area,
Some(get_x(upper_left)), Some(get_x(upper_left)),
); );
for x in x..=get_x(bottom_right) { for x in x..=get_x(bottom_right) {
grid[(x, y)].set_ch(' '); grid[(x, y)]
grid[(x, y)].set_bg(Color::Default); .set_ch(' ')
grid[(x, y)].set_fg(Color::Default); .set_fg(theme_default.fg)
.set_bg(theme_default.bg);
} }
context context
.dirty_areas .dirty_areas
@ -699,7 +708,7 @@ impl ThreadView {
clear_area( clear_area(
grid, grid,
((mid, y + 1), set_x(bottom_right, mid)), ((mid, y + 1), set_x(bottom_right, mid)),
crate::conf::value(context, "theme_default"), theme_default,
); );
y + 2 y + 2
} else { } else {
@ -711,8 +720,9 @@ impl ThreadView {
} }
for x in get_x(upper_left)..=get_x(bottom_right) { for x in get_x(upper_left)..=get_x(bottom_right) {
set_and_join_box(grid, (x, y - 1), BoxBoundary::Horizontal); set_and_join_box(grid, (x, y - 1), BoxBoundary::Horizontal);
grid[(x, y - 1)].set_fg(Color::Byte(33)); grid[(x, y - 1)]
grid[(x, y - 1)].set_bg(Color::Default); .set_fg(Color::Byte(33))
.set_bg(theme_default.bg);
} }
match (self.show_mailview, self.show_thread) { match (self.show_mailview, self.show_thread) {
@ -730,7 +740,7 @@ impl ThreadView {
clear_area( clear_area(
grid, grid,
((mid + 1, get_y(upper_left) + y - 1), bottom_right), ((mid + 1, get_y(upper_left) + y - 1), bottom_right),
crate::conf::value(context, "theme_default"), theme_default,
); );
self.draw_list(grid, (set_y(upper_left, y), bottom_right), context); self.draw_list(grid, (set_y(upper_left, y), bottom_right), context);
} }
@ -757,9 +767,10 @@ impl ThreadView {
} }
let mid = mid; let mid = mid;
let theme_default = crate::conf::value(context, "theme_default");
/* First draw the thread subject on the first row */ /* First draw the thread subject on the first row */
let y = { let y = {
clear_area(grid, area, crate::conf::value(context, "theme_default")); clear_area(grid, area, theme_default);
let account = &context.accounts[&self.coordinates.0]; let account = &context.accounts[&self.coordinates.0];
let threads = account.collection.get_threads(self.coordinates.1); let threads = account.collection.get_threads(self.coordinates.1);
let thread_root = threads let thread_root = threads
@ -781,15 +792,16 @@ impl ThreadView {
&envelope.subject(), &envelope.subject(),
grid, grid,
Color::Byte(33), Color::Byte(33),
Color::Default, theme_default.bg,
Attr::DEFAULT, theme_default.attrs,
area, area,
Some(get_x(upper_left)), Some(get_x(upper_left)),
); );
for x in x..=get_x(bottom_right) { for x in x..=get_x(bottom_right) {
grid[(x, y)].set_ch(' '); grid[(x, y)]
grid[(x, y)].set_bg(Color::Default); .set_ch(' ')
grid[(x, y)].set_fg(Color::Default); .set_fg(theme_default.fg)
.set_bg(theme_default.bg);
} }
context context
.dirty_areas .dirty_areas
@ -799,8 +811,9 @@ impl ThreadView {
for x in get_x(upper_left)..=get_x(bottom_right) { for x in get_x(upper_left)..=get_x(bottom_right) {
set_and_join_box(grid, (x, y - 1), BoxBoundary::Horizontal); set_and_join_box(grid, (x, y - 1), BoxBoundary::Horizontal);
grid[(x, y - 1)].set_fg(Color::Default); grid[(x, y - 1)]
grid[(x, y - 1)].set_bg(Color::Default); .set_fg(theme_default.fg)
.set_bg(theme_default.bg);
} }
let (width, height) = self.content.size(); let (width, height) = self.content.size();
@ -811,7 +824,7 @@ impl ThreadView {
clear_area( clear_area(
grid, grid,
(set_y(upper_left, y), set_y(bottom_right, mid + 1)), (set_y(upper_left, y), set_y(bottom_right, mid + 1)),
crate::conf::value(context, "theme_default"), theme_default,
); );
let (width, height) = self.content.size(); let (width, height) = self.content.size();
@ -863,8 +876,9 @@ impl ThreadView {
context.dirty_areas.push_back(area); context.dirty_areas.push_back(area);
for x in get_x(upper_left)..=get_x(bottom_right) { for x in get_x(upper_left)..=get_x(bottom_right) {
set_and_join_box(grid, (x, mid), BoxBoundary::Horizontal); set_and_join_box(grid, (x, mid), BoxBoundary::Horizontal);
grid[(x, mid)].set_fg(Color::Default); grid[(x, mid)]
grid[(x, mid)].set_bg(Color::Default); .set_fg(theme_default.fg)
.set_bg(theme_default.bg);
} }
let area = (set_y(upper_left, y), set_y(bottom_right, mid - 1)); let area = (set_y(upper_left, y), set_y(bottom_right, mid - 1));
self.draw_list(grid, area, context); self.draw_list(grid, area, context);

View File

@ -94,12 +94,12 @@ impl CellBuffer {
/// Constructs a new `CellBuffer` with the given number of columns and rows, using the given /// Constructs a new `CellBuffer` with the given number of columns and rows, using the given
/// `cell` as a blank. /// `cell` as a blank.
pub fn new(cols: usize, rows: usize, cell: Cell) -> CellBuffer { pub fn new(cols: usize, rows: usize, default_cell: Cell) -> CellBuffer {
CellBuffer { CellBuffer {
cols, cols,
rows, rows,
buf: vec![cell; cols * rows], buf: vec![default_cell; cols * rows],
default_cell: cell, default_cell,
growable: false, growable: false,
ascii_drawing: false, ascii_drawing: false,
tag_table: Default::default(), tag_table: Default::default(),
@ -1089,7 +1089,7 @@ macro_rules! inspect_bounds {
$grid.resize( $grid.resize(
std::cmp::max($x + 1, $grid.cols), std::cmp::max($x + 1, $grid.cols),
$grid.rows, $grid.rows,
Cell::default(), $grid.default_cell,
); );
} else { } else {
$x = get_x(upper_left); $x = get_x(upper_left);
@ -1106,7 +1106,7 @@ macro_rules! inspect_bounds {
$grid.resize( $grid.resize(
$grid.cols, $grid.cols,
std::cmp::max($y + 1, $grid.rows), std::cmp::max($y + 1, $grid.rows),
Cell::default(), $grid.default_cell,
); );
} else { } else {
return ($x, $y - 1); return ($x, $y - 1);
@ -1135,7 +1135,7 @@ pub fn write_string_to_grid(
grid.resize( grid.resize(
std::cmp::max(grid.cols, x + 1), std::cmp::max(grid.cols, x + 1),
std::cmp::max(grid.rows, y + 1), std::cmp::max(grid.rows, y + 1),
Cell::default(), grid.default_cell,
); );
} else { } else {
return (x, y); return (x, y);
@ -1151,7 +1151,7 @@ pub fn write_string_to_grid(
grid.resize( grid.resize(
std::cmp::max(grid.cols, x + 1), std::cmp::max(grid.cols, x + 1),
std::cmp::max(grid.rows, y + 1), std::cmp::max(grid.rows, y + 1),
Cell::default(), grid.default_cell,
); );
} else { } else {
debug!(" Invalid area with string {} and area {:?}", s, area); debug!(" Invalid area with string {} and area {:?}", s, area);