summaryrefslogtreecommitdiffstats
path: root/ui/src/components
diff options
context:
space:
mode:
authorManos Pitsidianakis <el13635@mail.ntua.gr>2020-01-22 00:05:26 +0200
committerManos Pitsidianakis <el13635@mail.ntua.gr>2020-01-22 00:05:26 +0200
commitaa04ddda3dcb8c9ca20286b3af83c7e6b697a792 (patch)
tree99dfe618271b80bbaef9de2c78d41e54fdb53c42 /ui/src/components
parentdc63e1f657eec972b3179db29d4dd7d5318adecd (diff)
ui/themes: add envelope view headers/body theme colors
Diffstat (limited to 'ui/src/components')
-rw-r--r--ui/src/components/mail/view.rs37
-rw-r--r--ui/src/components/mail/view/envelope.rs17
-rw-r--r--ui/src/components/mail/view/html.rs6
-rw-r--r--ui/src/components/utilities.rs55
4 files changed, 85 insertions, 30 deletions
diff --git a/ui/src/components/mail/view.rs b/ui/src/components/mail/view.rs
index a1db5efc..78458c64 100644
--- a/ui/src/components/mail/view.rs
+++ b/ui/src/components/mail/view.rs
@@ -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;
}
};
diff --git a/ui/src/components/mail/view/envelope.rs b/ui/src/components/mail/view/envelope.rs
index 6fbae798..cddd4221 100644
--- a/ui/src/components/mail/view/envelope.rs
+++ b/ui/src/components/mail/view/envelope.rs
@@ -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,
)));
}
diff --git a/ui/src/components/mail/view/html.rs b/ui/src/components/mail/view/html.rs
index 9fc5231b..7e4ecbfc 100644
--- a/ui/src/components/mail/view/html.rs
+++ b/ui/src/components/mail/view/html.rs
@@ -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 }
}
}
diff --git a/ui/src/components/utilities.rs b/ui/src/components/utilities.rs
index 3a79be93..21f5ac89 100644
--- a/ui/src/components/utilities.rs
+++ b/ui/src/components/utilities.rs
@@ -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;