HtmlView: add html_open config setting
Add config setting in case xdg query default app for text/html mime type doesn't yield results.issue-133
parent
b87d54ea3f
commit
d8d43a16fe
|
@ -1020,6 +1020,11 @@ Always show headers when scrolling.
|
|||
Pipe html attachments through this filter before display
|
||||
.\" default value
|
||||
.Pq Em none
|
||||
.It Ic html_open Ar String
|
||||
.Pq Em optional
|
||||
A command to open html files.
|
||||
.\" default value
|
||||
.Pq Em none
|
||||
.It Ic filter Ar String
|
||||
.Pq Em optional
|
||||
A command to pipe mail output through for viewing in pager.
|
||||
|
|
|
@ -1431,7 +1431,9 @@ impl Component for MailView {
|
|||
let mut text = "Viewing attachment. Press `r` to return \n".to_string();
|
||||
if let Some(attachment) = self.open_attachment(aidx, context) {
|
||||
if attachment.is_html() {
|
||||
self.subview = Some(Box::new(HtmlView::new(attachment, context)));
|
||||
let mut subview = Box::new(HtmlView::new(attachment, context));
|
||||
subview.set_coordinates(Some(self.coordinates));
|
||||
self.subview = Some(subview);
|
||||
self.mode = ViewMode::Subview;
|
||||
} else {
|
||||
text.push_str(&attachment.text());
|
||||
|
@ -1462,7 +1464,9 @@ impl Component for MailView {
|
|||
}
|
||||
}
|
||||
ViewMode::Normal if body.is_html() => {
|
||||
self.subview = Some(Box::new(HtmlView::new(body, context)));
|
||||
let mut subview = Box::new(HtmlView::new(body, context));
|
||||
subview.set_coordinates(Some(self.coordinates));
|
||||
self.subview = Some(subview);
|
||||
self.mode = ViewMode::Subview;
|
||||
}
|
||||
ViewMode::Normal
|
||||
|
@ -1483,7 +1487,7 @@ impl Component for MailView {
|
|||
_ => false,
|
||||
} =>
|
||||
{
|
||||
self.subview = Some(Box::new(HtmlView::new(
|
||||
let mut subview = Box::new(HtmlView::new(
|
||||
body.content_type
|
||||
.parts()
|
||||
.unwrap()
|
||||
|
@ -1491,7 +1495,9 @@ impl Component for MailView {
|
|||
.find(|a| a.is_html())
|
||||
.unwrap_or(body),
|
||||
context,
|
||||
)));
|
||||
));
|
||||
subview.set_coordinates(Some(self.coordinates));
|
||||
self.subview = Some(subview);
|
||||
self.mode = ViewMode::Subview;
|
||||
self.initialised = false;
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ use std::process::{Command, Stdio};
|
|||
pub struct HtmlView {
|
||||
pager: Pager,
|
||||
bytes: Vec<u8>,
|
||||
coordinates: Option<(AccountHash, MailboxHash, EnvelopeHash)>,
|
||||
id: ComponentId,
|
||||
}
|
||||
|
||||
|
@ -111,7 +112,16 @@ impl HtmlView {
|
|||
}
|
||||
let colors = crate::conf::value(context, "mail.view.body");
|
||||
let pager = Pager::from_string(display_text, None, None, None, colors);
|
||||
HtmlView { pager, bytes, id }
|
||||
HtmlView {
|
||||
pager,
|
||||
bytes,
|
||||
id,
|
||||
coordinates: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_coordinates(&mut self, new_value: Option<(AccountHash, MailboxHash, EnvelopeHash)>) {
|
||||
self.coordinates = new_value;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -131,7 +141,15 @@ impl Component for HtmlView {
|
|||
}
|
||||
|
||||
if let UIEvent::Input(Key::Char('v')) = event {
|
||||
if let Ok(command) = query_default_app("text/html") {
|
||||
let command = if let Some(coordinates) = self.coordinates {
|
||||
mailbox_settings!(context[coordinates.0][&coordinates.1].pager.html_open)
|
||||
.as_ref()
|
||||
.map(|s| s.to_string())
|
||||
.or_else(|| query_default_app("text/html").ok())
|
||||
} else {
|
||||
query_default_app("text/html").ok()
|
||||
};
|
||||
if let Some(command) = command {
|
||||
let p = create_temp_file(&self.bytes, None, None, true);
|
||||
let (exec_cmd, argument) =
|
||||
super::desktop_exec_to_command(&command, p.path.display().to_string(), false);
|
||||
|
|
|
@ -88,6 +88,11 @@ pub struct PagerSettingsOverride {
|
|||
#[serde(deserialize_with = "non_empty_string")]
|
||||
#[serde(default)]
|
||||
pub url_launcher: Option<Option<String>>,
|
||||
#[doc = " A command to open html files."]
|
||||
#[doc = " Default: None"]
|
||||
#[serde(deserialize_with = "non_empty_string", alias = "html-open")]
|
||||
#[serde(default)]
|
||||
pub html_open: Option<Option<String>>,
|
||||
}
|
||||
impl Default for PagerSettingsOverride {
|
||||
fn default() -> Self {
|
||||
|
@ -104,6 +109,7 @@ impl Default for PagerSettingsOverride {
|
|||
auto_choose_multipart_alternative: None,
|
||||
show_date_in_my_timezone: None,
|
||||
url_launcher: None,
|
||||
html_open: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,14 +87,25 @@ pub struct PagerSettings {
|
|||
alias = "auto-choose-multipart-alternative"
|
||||
)]
|
||||
pub auto_choose_multipart_alternative: ToggleFlag,
|
||||
|
||||
/// Show Date: in my timezone
|
||||
/// Default: true
|
||||
#[serde(default = "internal_value_true", alias = "show-date-in-my-timezone")]
|
||||
pub show_date_in_my_timezone: ToggleFlag,
|
||||
|
||||
/// A command to launch URLs with. The URL will be given as the first argument of the command.
|
||||
/// Default: None
|
||||
#[serde(default = "none", deserialize_with = "non_empty_string")]
|
||||
pub url_launcher: Option<String>,
|
||||
|
||||
/// A command to open html files.
|
||||
/// Default: None
|
||||
#[serde(
|
||||
default = "none",
|
||||
deserialize_with = "non_empty_string",
|
||||
alias = "html-open"
|
||||
)]
|
||||
pub html_open: Option<String>,
|
||||
}
|
||||
|
||||
impl Default for PagerSettings {
|
||||
|
@ -106,6 +117,7 @@ impl Default for PagerSettings {
|
|||
pager_ratio: 80,
|
||||
filter: None,
|
||||
html_filter: None,
|
||||
html_open: None,
|
||||
format_flowed: true,
|
||||
split_long_lines: true,
|
||||
minimum_width: 80,
|
||||
|
@ -128,6 +140,7 @@ impl DotAddressable for PagerSettings {
|
|||
"pager_ratio" => self.pager_ratio.lookup(field, tail),
|
||||
"filter" => self.filter.lookup(field, tail),
|
||||
"html_filter" => self.html_filter.lookup(field, tail),
|
||||
"html_open" => self.html_open.lookup(field, tail),
|
||||
"format_flowed" => self.format_flowed.lookup(field, tail),
|
||||
"split_long_lines" => self.split_long_lines.lookup(field, tail),
|
||||
"minimum_width" => self.minimum_width.lookup(field, tail),
|
||||
|
|
Loading…
Reference in New Issue