ui/themes: add envelope view headers/body theme colors

async
Manos Pitsidianakis 2020-01-22 00:05:26 +02:00
parent dc63e1f657
commit aa04ddda3d
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
5 changed files with 117 additions and 42 deletions

View File

@ -368,13 +368,11 @@ impl Component for MailView {
))));
}
}
let account = &context.accounts[self.coordinates.0];
let envelope: EnvelopeRef = account.collection.get_env(self.coordinates.2);
let header_fg = if context.settings.terminal.theme == "light" {
Color::Black
} else {
Color::Byte(33)
};
let headers_fg = crate::conf::color(context, "mail.view.headers_fg");
let headers_bg = crate::conf::color(context, "mail.view.headers_bg");
if self.mode == ViewMode::Raw {
clear_area(grid, area);
@ -396,8 +394,8 @@ impl Component for MailView {
let (_x, _y) = write_string_to_grid(
&$string,
grid,
header_fg,
Color::Default,
headers_fg,
headers_bg,
Attr::Default,
(set_y(upper_left, y), bottom_right),
Some(get_x(upper_left)),
@ -448,8 +446,8 @@ impl Component for MailView {
let (_x, _) = write_string_to_grid(
"List-ID: ",
grid,
header_fg,
Color::Default,
headers_fg,
headers_bg,
Attr::Default,
(set_y(upper_left, y), bottom_right),
None,
@ -476,8 +474,8 @@ impl Component for MailView {
let (_x, _y) = write_string_to_grid(
" Available actions: [ ",
grid,
header_fg,
Color::Default,
headers_fg,
headers_bg,
Attr::Default,
((x, y), bottom_right),
Some(get_x(upper_left)),
@ -529,8 +527,8 @@ impl Component for MailView {
grid[(x - 2, y)].set_ch(' ');
}
if x > 0 {
grid[(x - 1, y)].set_fg(header_fg);
grid[(x - 1, y)].set_bg(Color::Default);
grid[(x - 1, y)].set_fg(headers_fg);
grid[(x - 1, y)].set_bg(headers_bg);
grid[(x - 1, y)].set_ch(']');
}
}
@ -648,7 +646,11 @@ impl Component for MailView {
.map(|v| String::from_utf8_lossy(v).into_owned())
.unwrap_or_else(|e| e.to_string())
};
self.pager = Pager::from_string(text, Some(context), None, None);
let colors = PagerColors {
fg: crate::conf::color(context, "mail.view.body_fg"),
bg: crate::conf::color(context, "mail.view.body_bg"),
};
self.pager = Pager::from_string(text, Some(context), None, None, colors);
}
ViewMode::Ansi(ref buf) => {
write_string_to_grid(
@ -674,7 +676,12 @@ impl Component for MailView {
} else {
self.pager.cursor_pos()
};
self.pager = Pager::from_string(text, Some(context), Some(cursor_pos), None);
let colors = PagerColors {
fg: crate::conf::color(context, "mail.view.body_fg"),
bg: crate::conf::color(context, "mail.view.body_bg"),
};
self.pager =
Pager::from_string(text, Some(context), Some(cursor_pos), None, colors);
self.subview = None;
}
};

View File

@ -339,7 +339,17 @@ impl Component for EnvelopeView {
} else {
self.pager.as_ref().map(Pager::cursor_pos)
};
self.pager = Some(Pager::from_string(text, Some(context), cursor_pos, None));
let colors = PagerColors {
fg: crate::conf::color(context, "mail.view.body_fg"),
bg: crate::conf::color(context, "mail.view.body_bg"),
};
self.pager = Some(Pager::from_string(
text,
Some(context),
cursor_pos,
None,
colors,
));
}
};
self.dirty = false;
@ -411,11 +421,16 @@ 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"),
};
self.subview = Some(Box::new(Pager::from_string(
String::from_utf8_lossy(&decode_rec(u, None)).to_string(),
Some(context),
None,
None,
colors,
)));
}

View File

@ -109,7 +109,11 @@ impl HtmlView {
s
});
}
let pager = Pager::from_string(display_text, None, None, None);
let colors = PagerColors {
fg: crate::conf::color(context, "mail.view.body_fg"),
bg: crate::conf::color(context, "mail.view.body_bg"),
};
let pager = Pager::from_string(display_text, None, None, None, colors);
HtmlView { pager, bytes, id }
}
}

View File

@ -264,6 +264,12 @@ 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),
@ -289,6 +295,7 @@ pub struct Pager {
minimum_width: usize,
dirty: bool,
colors: PagerColors,
initialised: bool,
content: CellBuffer,
movement: Option<PageMovement>,
@ -321,9 +328,12 @@ impl Pager {
let height = lines.len() + 2;
let width = width.unwrap_or_else(|| lines.iter().map(|l| l.len()).max().unwrap_or(0));
let ascii_drawing = self.content.ascii_drawing;
let mut content = CellBuffer::new(width, height, Cell::with_char(' '));
let mut empty_cell = Cell::with_char(' ');
empty_cell.set_fg(self.colors.fg);
empty_cell.set_bg(self.colors.bg);
let mut content = CellBuffer::new(width, height, empty_cell);
content.set_ascii_drawing(ascii_drawing);
Pager::print_string(&mut content, lines);
Pager::print_string(&mut content, lines, self.colors);
self.text = text.to_string();
self.content = content;
self.height = height;
@ -336,6 +346,7 @@ impl Pager {
context: Option<&Context>,
cursor_pos: Option<usize>,
mut width: Option<usize>,
colors: PagerColors,
) -> Self {
let pager_filter: Option<&String> = if let Some(context) = context {
context.settings.pager.filter.as_ref()
@ -396,12 +407,15 @@ impl Pager {
let height = lines.len() + 1;
let width = width.unwrap_or_else(|| lines.iter().map(|l| l.len()).max().unwrap_or(0));
let mut empty_cell = Cell::with_char(' ');
empty_cell.set_fg(colors.fg);
empty_cell.set_bg(colors.bg);
let mut content = if let Some(context) = context {
CellBuffer::new_with_context(width, height, Cell::with_char(' '), context)
CellBuffer::new_with_context(width, height, empty_cell, context)
} else {
CellBuffer::new(width, height, Cell::with_char(' '))
CellBuffer::new(width, height, empty_cell)
};
Pager::print_string(&mut content, lines);
Pager::print_string(&mut content, lines, colors);
content
};
Pager {
@ -413,10 +427,16 @@ impl Pager {
dirty: true,
content,
id: ComponentId::new_v4(),
colors,
..Default::default()
}
}
pub fn from_str(text: &str, cursor_pos: Option<usize>, width: Option<usize>) -> Self {
pub fn from_str(
text: &str,
cursor_pos: Option<usize>,
width: Option<usize>,
colors: PagerColors,
) -> Self {
let lines: Vec<String> = if let Some(width) = width {
text.split_lines(width)
} else {
@ -425,9 +445,12 @@ impl Pager {
let height = lines.len() + 1;
let width = width.unwrap_or_else(|| lines.iter().map(|l| l.len()).max().unwrap_or(0));
let mut content = CellBuffer::new(width, height, Cell::with_char(' '));
let mut empty_cell = Cell::with_char(' ');
empty_cell.set_fg(colors.fg);
empty_cell.set_bg(colors.bg);
let mut content = CellBuffer::new(width, height, empty_cell);
Pager::print_string(&mut content, lines);
Pager::print_string(&mut content, lines, colors);
Pager {
text: text.to_string(),
cursor: (0, cursor_pos.unwrap_or(0)),
@ -435,10 +458,12 @@ impl Pager {
width,
dirty: true,
content,
colors,
id: ComponentId::new_v4(),
..Default::default()
}
}
pub fn from_buf(content: CellBuffer, cursor_pos: Option<usize>) -> Self {
let (width, height) = content.size();
Pager {
@ -452,14 +477,15 @@ impl Pager {
..Default::default()
}
}
pub fn print_string(content: &mut CellBuffer, lines: Vec<String>) {
pub fn print_string(content: &mut CellBuffer, lines: Vec<String>, colors: PagerColors) {
let width = content.size().0;
debug!(colors);
for (i, l) in lines.iter().enumerate() {
write_string_to_grid(
l,
content,
Color::Default,
Color::Default,
colors.fg,
colors.bg,
Attr::Default,
((0, i), (width.saturating_sub(1), i)),
None,
@ -499,9 +525,12 @@ impl Component for Pager {
.text
.split_lines_reflow(self.reflow, Some(width.saturating_sub(2)));
let height = lines.len() + 2;
let mut content = CellBuffer::new(width, height, Cell::with_char(' '));
let mut empty_cell = Cell::with_char(' ');
empty_cell.set_fg(self.colors.fg);
empty_cell.set_bg(self.colors.bg);
let mut content = CellBuffer::new(width, height, empty_cell);
content.set_ascii_drawing(self.content.ascii_drawing);
Pager::print_string(&mut content, lines);
Pager::print_string(&mut content, lines, self.colors);
self.content = content;
self.height = height;
self.width = width;

View File

@ -316,19 +316,39 @@ impl Default for Theme {
"mail.listing.conversations.date_fg",
"mail.listing.conversations.date_bg",
"mail.listing.conversations.unseen_padding",
"mail.view.headers_fg",
"mail.view.headers_bg",
"mail.view.body_fg",
"mail.view.body_bg",
*/
light.insert("mail.listing.attachment_flag_fg".into(), Color::Byte(103));
light.insert("mail.listing.attachment_flag_bg".into(), Color::Default);
light.insert("mail.listing.thread_snooze_flag_fg".into(), Color::Red);
light.insert("mail.listing.thread_snooze_flag_bg".into(), Color::Default);
dark.insert("mail.listing.attachment_flag_fg".into(), Color::Byte(103));
dark.insert("mail.listing.attachment_flag_bg".into(), Color::Default);
dark.insert("mail.listing.thread_snooze_flag_fg".into(), Color::Red);
dark.insert("mail.listing.thread_snooze_flag_bg".into(), Color::Default);
add!(
"mail.view.headers_fg",
dark = Color::Byte(33),
light = Color::Black
);
add!("mail.view.headers_bg");
add!("mail.view.body_fg");
add!("mail.view.body_bg");
add!(
"mail.listing.attachment_flag_fg",
light = Color::Byte(103),
dark = Color::Byte(103)
);
add!(
"mail.listing.attachment_flag_bg",
light = Color::Default,
dark = Color::Default
);
add!(
"mail.listing.thread_snooze_flag_fg",
light = Color::Red,
dark = Color::Red
);
add!(
"mail.listing.thread_snooze_flag_bg",
light = Color::Default,
dark = Color::Default
);
Theme { light, dark }
}