|
|
|
@ -25,27 +25,32 @@ use std::process::{Command, Stdio};
|
|
|
|
|
|
|
|
|
|
pub struct HtmlView {
|
|
|
|
|
pager: Pager,
|
|
|
|
|
bytes: Vec<u8>
|
|
|
|
|
bytes: Vec<u8>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl HtmlView {
|
|
|
|
|
pub fn new(bytes: Vec<u8>) -> Self {
|
|
|
|
|
let mut html_filter = Command::new("w3m")
|
|
|
|
|
.args(&["-I", "utf-8", "-T", "text/html"])
|
|
|
|
|
.args(&["-I", "utf-8", "-T", "text/html"])
|
|
|
|
|
.stdin(Stdio::piped())
|
|
|
|
|
.stdout(Stdio::piped())
|
|
|
|
|
.spawn()
|
|
|
|
|
.expect("Failed to start html filter process");
|
|
|
|
|
html_filter.stdin.as_mut().unwrap().write_all(&bytes).expect("Failed to write to w3m stdin");
|
|
|
|
|
let mut display_text = String::from("Text piped through `w3m`. Press `v` to open in web browser. \n\n");
|
|
|
|
|
display_text.push_str(&String::from_utf8_lossy(&html_filter.wait_with_output().unwrap().stdout));
|
|
|
|
|
html_filter
|
|
|
|
|
.stdin
|
|
|
|
|
.as_mut()
|
|
|
|
|
.unwrap()
|
|
|
|
|
.write_all(&bytes)
|
|
|
|
|
.expect("Failed to write to w3m stdin");
|
|
|
|
|
let mut display_text =
|
|
|
|
|
String::from("Text piped through `w3m`. Press `v` to open in web browser. \n\n");
|
|
|
|
|
display_text.push_str(&String::from_utf8_lossy(
|
|
|
|
|
&html_filter.wait_with_output().unwrap().stdout,
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
let buf = MailView::plain_text_to_buf(&display_text, true);
|
|
|
|
|
let pager = Pager::from_buf(&buf, None);
|
|
|
|
|
HtmlView {
|
|
|
|
|
pager,
|
|
|
|
|
bytes
|
|
|
|
|
}
|
|
|
|
|
HtmlView { pager, bytes }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -66,20 +71,19 @@ impl Component for HtmlView {
|
|
|
|
|
.stdin(Stdio::piped())
|
|
|
|
|
.stdout(Stdio::piped())
|
|
|
|
|
.spawn()
|
|
|
|
|
.unwrap_or_else(|_| {
|
|
|
|
|
panic!("Failed to start {}", binary.display())
|
|
|
|
|
});
|
|
|
|
|
.unwrap_or_else(|_| panic!("Failed to start {}", binary.display()));
|
|
|
|
|
context.temp_files.push(p);
|
|
|
|
|
} else {
|
|
|
|
|
context.replies.push_back(UIEvent {
|
|
|
|
|
id: 0,
|
|
|
|
|
event_type: UIEventType::StatusNotification(format!(
|
|
|
|
|
"Couldn't find a default application for html files.")),
|
|
|
|
|
"Couldn't find a default application for html files."
|
|
|
|
|
)),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
},
|
|
|
|
|
_ => {},
|
|
|
|
|
}
|
|
|
|
|
_ => {}
|
|
|
|
|
}
|
|
|
|
|
self.pager.process_event(event, context);
|
|
|
|
|
}
|
|
|
|
|