conf/themes: add mail.view.headers_names and mail.view.headers_area

Allow separate customization of header names and the rest of the header
area.
jmap-eventsource
Manos Pitsidianakis 2020-12-01 22:14:37 +02:00
parent f8a47586e9
commit 7e1e57a2df
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
3 changed files with 81 additions and 43 deletions

View File

@ -263,6 +263,10 @@ mail.listing.conversations.selected
.It .It
mail.view.headers mail.view.headers
.It .It
mail.view.headers_names
.It
mail.view.headers_area
.It
mail.view.body mail.view.body
.It .It
mail.view.thread.indentation.a mail.view.thread.indentation.a

View File

@ -1051,6 +1051,8 @@ impl Component for MailView {
let envelope: EnvelopeRef = account.collection.get_env(self.coordinates.2); let envelope: EnvelopeRef = account.collection.get_env(self.coordinates.2);
let headers = crate::conf::value(context, "mail.view.headers"); let headers = crate::conf::value(context, "mail.view.headers");
let headers_names = crate::conf::value(context, "mail.view.headers_names");
let headers_area = crate::conf::value(context, "mail.view.headers_area");
if let ViewMode::Source(_) = self.mode { if let ViewMode::Source(_) = self.mode {
clear_area(grid, area, self.theme_default); clear_area(grid, area, self.theme_default);
@ -1070,55 +1072,71 @@ impl Component for MailView {
) || height_p < height; ) || height_p < height;
let (_, mut y) = upper_left; let (_, mut y) = upper_left;
macro_rules! print_header { macro_rules! print_header {
($($string:expr)+) => { ($(($header:literal, $string:expr)),*$(,)?) => {
$({ $({
if sticky || skip_header_ctr == 0 { if sticky || skip_header_ctr == 0 {
if y <= get_y(bottom_right) { if y <= get_y(bottom_right) {
let (_x, _y) = write_string_to_grid( let (_x, _y) = write_string_to_grid(
&$string, $header,
grid, grid,
headers.fg, headers_names.fg,
headers.bg, headers_names.bg,
headers.attrs, headers_names.attrs,
(set_y(upper_left, y), bottom_right), (set_y(upper_left, y), bottom_right),
Some(get_x(upper_left)), Some(get_x(upper_left)),
); );
clear_area(grid, ((std::cmp::min(_x, get_x(bottom_right)), _y), (get_x(bottom_right), _y)), headers); if let Some(cell) = grid.get_mut(_x,_y) {
y = _y + 1; cell.set_ch(' ')
.set_fg(headers_area.fg)
.set_bg(headers_area.bg)
.set_attrs(headers_area.attrs);
}
let (_x, _y) = write_string_to_grid(
&$string,
grid,
headers.fg,
headers.bg,
headers.attrs,
((_x +1, _y), bottom_right),
Some(get_x(upper_left)),
);
clear_area(grid, ((std::cmp::min(_x, get_x(bottom_right)), _y), (get_x(bottom_right), _y)), headers_area);
y = _y + 1;
} }
} else { } else {
skip_header_ctr -= 1; skip_header_ctr -= 1;
} }
self.headers_no += 1; self.headers_no += 1;
})+ })+
}; };
} }
print_header!( print_header!(
format!("Date: {}", envelope.date_as_str()) ("Date:", envelope.date_as_str()),
format!("From: {}", envelope.field_from_to_string()) ("From:", envelope.field_from_to_string()),
format!("To: {}", envelope.field_to_to_string()) ("To:", envelope.field_to_to_string()),
); );
if envelope.other_headers().contains_key("Cc") if envelope.other_headers().contains_key("Cc")
&& !envelope.other_headers()["Cc"].is_empty() && !envelope.other_headers()["Cc"].is_empty()
{ {
print_header!(format!("Cc: {}", envelope.field_cc_to_string())); print_header!(("Cc:", envelope.field_cc_to_string()));
} }
print_header!( print_header!(
format!("Subject: {}", envelope.subject()) ("Subject:", envelope.subject()),
format!("Message-ID: <{}>", envelope.message_id_raw()) ("Message-ID:", format!("<{}>", envelope.message_id_raw()))
); );
if self.expand_headers { if self.expand_headers {
if let Some(val) = envelope.in_reply_to_display() { if let Some(val) = envelope.in_reply_to_display() {
print_header!( print_header!(
format!("In-Reply-To: {}", val) ("In-Reply-To:", val),
format!( (
"References: {}", "References:",
envelope envelope
.references() .references()
.iter() .iter()
.map(std::string::ToString::to_string) .map(std::string::ToString::to_string)
.collect::<Vec<String>>() .collect::<Vec<String>>()
.join(", ") .join(", ")
) )
); );
} }
@ -1136,14 +1154,14 @@ impl Component for MailView {
clear_area( clear_area(
grid, grid,
(set_y(upper_left, y), set_y(bottom_right, y)), (set_y(upper_left, y), set_y(bottom_right, y)),
headers, headers_area,
); );
let (_x, _) = write_string_to_grid( let (_x, _) = write_string_to_grid(
"List-ID: ", "List-ID: ",
grid, grid,
headers.fg, headers_names.fg,
headers.bg, headers_names.bg,
headers.attrs, headers_names.attrs,
(set_y(upper_left, y), bottom_right), (set_y(upper_left, y), bottom_right),
None, None,
); );
@ -1169,9 +1187,9 @@ impl Component for MailView {
let (_x, _y) = write_string_to_grid( let (_x, _y) = write_string_to_grid(
" Available actions: [ ", " Available actions: [ ",
grid, grid,
headers.fg, headers_names.fg,
headers.bg, headers_names.bg,
headers.attrs, headers_names.attrs,
((x, y), bottom_right), ((x, y), bottom_right),
Some(get_x(upper_left)), Some(get_x(upper_left)),
); );
@ -1224,16 +1242,16 @@ impl Component for MailView {
if x > 0 { if x > 0 {
grid[(x - 1, y)] grid[(x - 1, y)]
.set_ch(']') .set_ch(']')
.set_fg(headers.fg) .set_fg(headers_names.fg)
.set_bg(headers.bg) .set_bg(headers_names.bg)
.set_attrs(headers.attrs); .set_attrs(headers_names.attrs);
} }
} }
for x in x..=get_x(bottom_right) { for x in x..=get_x(bottom_right) {
grid[(x, y)] grid[(x, y)]
.set_ch(' ') .set_ch(' ')
.set_fg(headers.fg) .set_fg(headers_area.fg)
.set_bg(headers.bg); .set_bg(headers_area.bg);
} }
y += 1; y += 1;
} }
@ -1243,7 +1261,7 @@ impl Component for MailView {
clear_area( clear_area(
grid, grid,
(set_y(upper_left, y), set_y(bottom_right, y)), (set_y(upper_left, y), set_y(bottom_right, y)),
headers, headers_area,
); );
context context
.dirty_areas .dirty_areas

View File

@ -292,6 +292,8 @@ const DEFAULT_KEYS: &[&str] = &[
"mail.listing.conversations.highlighted", "mail.listing.conversations.highlighted",
"mail.listing.conversations.selected", "mail.listing.conversations.selected",
"mail.view.headers", "mail.view.headers",
"mail.view.headers_names",
"mail.view.headers_area",
"mail.view.body", "mail.view.body",
"mail.view.thread.indentation.a", "mail.view.thread.indentation.a",
"mail.view.thread.indentation.b", "mail.view.thread.indentation.b",
@ -1646,6 +1648,20 @@ impl Default for Themes {
fg: Color::Black, fg: Color::Black,
} }
); );
add!(
"mail.view.headers_names",
light = {
fg: "mail.view.headers",
bg: "mail.view.headers",
attrs: "mail.view.headers",
},
dark = {
fg: "mail.view.headers",
bg: "mail.view.headers",
attrs: "mail.view.headers",
}
);
add!("mail.view.headers_area");
add!("mail.view.body"); add!("mail.view.body");
add!("mail.view.thread.indentation.a", light = { bg: Color::Byte(69) }, dark = { bg: Color::Byte(69) }); // CornflowerBlue add!("mail.view.thread.indentation.a", light = { bg: Color::Byte(69) }, dark = { bg: Color::Byte(69) }); // CornflowerBlue
add!("mail.view.thread.indentation.b", light = { bg: Color::Byte(196) }, dark = { bg: Color::Byte(196) }); // Red1 add!("mail.view.thread.indentation.b", light = { bg: Color::Byte(196) }, dark = { bg: Color::Byte(196) }); // Red1