2018-08-07 15:01:15 +03:00
|
|
|
/*
|
|
|
|
* meli - ui crate.
|
|
|
|
*
|
|
|
|
* Copyright 2017-2018 Manos Pitsidianakis
|
|
|
|
*
|
|
|
|
* This file is part of meli.
|
|
|
|
*
|
|
|
|
* meli is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* meli is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with meli. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2018-07-22 18:02:44 +03:00
|
|
|
use super::*;
|
2018-07-27 18:01:52 +03:00
|
|
|
use linkify::{Link, LinkFinder};
|
2018-07-23 15:40:13 +03:00
|
|
|
use std::process::{Command, Stdio};
|
2018-07-22 18:02:44 +03:00
|
|
|
|
2018-07-25 19:05:42 +03:00
|
|
|
use mime_apps::query_default_app;
|
|
|
|
|
2018-07-23 15:40:13 +03:00
|
|
|
#[derive(PartialEq, Debug)]
|
|
|
|
enum ViewMode {
|
|
|
|
Normal,
|
|
|
|
Url,
|
2018-07-26 00:07:00 +03:00
|
|
|
Attachment(usize),
|
2018-08-05 12:44:31 +03:00
|
|
|
Raw,
|
2018-07-25 22:37:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
impl ViewMode {
|
|
|
|
fn is_attachment(&self) -> bool {
|
|
|
|
match self {
|
|
|
|
ViewMode::Attachment(_) => true,
|
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
2018-07-23 15:40:13 +03:00
|
|
|
}
|
|
|
|
|
2018-07-22 23:11:07 +03:00
|
|
|
/// Contains an Envelope view, with sticky headers, a pager for the body, and subviews for more
|
|
|
|
/// menus
|
2018-07-22 18:02:44 +03:00
|
|
|
pub struct MailView {
|
|
|
|
coordinates: (usize, usize, usize),
|
|
|
|
pager: Option<Pager>,
|
|
|
|
subview: Option<Box<MailView>>,
|
|
|
|
dirty: bool,
|
2018-07-23 15:40:13 +03:00
|
|
|
mode: ViewMode,
|
|
|
|
|
|
|
|
cmd_buf: String,
|
2018-07-22 18:02:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
impl MailView {
|
2018-07-27 18:01:52 +03:00
|
|
|
pub fn new(
|
|
|
|
coordinates: (usize, usize, usize),
|
|
|
|
pager: Option<Pager>,
|
|
|
|
subview: Option<Box<MailView>>,
|
|
|
|
) -> Self {
|
2018-07-22 18:02:44 +03:00
|
|
|
MailView {
|
2018-08-07 15:01:15 +03:00
|
|
|
coordinates,
|
|
|
|
pager,
|
|
|
|
subview,
|
2018-07-22 18:02:44 +03:00
|
|
|
dirty: true,
|
2018-07-23 15:40:13 +03:00
|
|
|
mode: ViewMode::Normal,
|
|
|
|
|
|
|
|
cmd_buf: String::with_capacity(4),
|
2018-07-22 18:02:44 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Component for MailView {
|
|
|
|
fn draw(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) {
|
|
|
|
let upper_left = upper_left!(area);
|
|
|
|
let bottom_right = bottom_right!(area);
|
|
|
|
|
|
|
|
let (envelope_idx, y): (usize, usize) = {
|
2018-07-27 18:01:52 +03:00
|
|
|
let threaded = context.accounts[self.coordinates.0]
|
|
|
|
.runtime_settings
|
|
|
|
.threaded;
|
|
|
|
let mailbox = &mut context.accounts[self.coordinates.0][self.coordinates.1]
|
|
|
|
.as_ref()
|
|
|
|
.unwrap();
|
2018-07-22 18:02:44 +03:00
|
|
|
let envelope_idx: usize = if threaded {
|
|
|
|
mailbox.threaded_mail(self.coordinates.2)
|
|
|
|
} else {
|
|
|
|
self.coordinates.2
|
|
|
|
};
|
|
|
|
|
|
|
|
let envelope: &Envelope = &mailbox.collection[envelope_idx];
|
|
|
|
|
2018-08-05 12:44:31 +03:00
|
|
|
if self.mode == ViewMode::Raw {
|
|
|
|
clear_area(grid, area);
|
2018-08-07 15:01:15 +03:00
|
|
|
context.dirty_areas.push_back(area);
|
2018-08-05 12:44:31 +03:00
|
|
|
(envelope_idx, get_y(upper_left) - 1)
|
|
|
|
} else {
|
|
|
|
let (x, y) = write_string_to_grid(
|
|
|
|
&format!("Date: {}", envelope.date_as_str()),
|
|
|
|
grid,
|
|
|
|
Color::Byte(33),
|
|
|
|
Color::Default,
|
|
|
|
area,
|
|
|
|
true,
|
2018-08-07 15:01:15 +03:00
|
|
|
);
|
2018-08-05 12:44:31 +03:00
|
|
|
for x in x..=get_x(bottom_right) {
|
|
|
|
grid[(x, y)].set_ch(' ');
|
|
|
|
grid[(x, y)].set_bg(Color::Default);
|
|
|
|
grid[(x, y)].set_fg(Color::Default);
|
|
|
|
}
|
|
|
|
let (x, y) = write_string_to_grid(
|
|
|
|
&format!("From: {}", envelope.from_to_string()),
|
|
|
|
grid,
|
|
|
|
Color::Byte(33),
|
|
|
|
Color::Default,
|
|
|
|
(set_y(upper_left, y + 1), bottom_right),
|
|
|
|
true,
|
2018-08-07 15:01:15 +03:00
|
|
|
);
|
2018-08-05 12:44:31 +03:00
|
|
|
for x in x..=get_x(bottom_right) {
|
|
|
|
grid[(x, y)].set_ch(' ');
|
|
|
|
grid[(x, y)].set_bg(Color::Default);
|
|
|
|
grid[(x, y)].set_fg(Color::Default);
|
|
|
|
}
|
|
|
|
let (x, y) = write_string_to_grid(
|
|
|
|
&format!("To: {}", envelope.to_to_string()),
|
|
|
|
grid,
|
|
|
|
Color::Byte(33),
|
|
|
|
Color::Default,
|
|
|
|
(set_y(upper_left, y + 1), bottom_right),
|
|
|
|
true,
|
2018-08-07 15:01:15 +03:00
|
|
|
);
|
2018-08-05 12:44:31 +03:00
|
|
|
for x in x..=get_x(bottom_right) {
|
|
|
|
grid[(x, y)].set_ch(' ');
|
|
|
|
grid[(x, y)].set_bg(Color::Default);
|
|
|
|
grid[(x, y)].set_fg(Color::Default);
|
|
|
|
}
|
|
|
|
let (x, y) = write_string_to_grid(
|
|
|
|
&format!("Subject: {}", envelope.subject()),
|
|
|
|
grid,
|
|
|
|
Color::Byte(33),
|
|
|
|
Color::Default,
|
|
|
|
(set_y(upper_left, y + 1), bottom_right),
|
|
|
|
true,
|
2018-08-07 15:01:15 +03:00
|
|
|
);
|
2018-08-05 12:44:31 +03:00
|
|
|
for x in x..=get_x(bottom_right) {
|
|
|
|
grid[(x, y)].set_ch(' ');
|
|
|
|
grid[(x, y)].set_bg(Color::Default);
|
|
|
|
grid[(x, y)].set_fg(Color::Default);
|
|
|
|
}
|
|
|
|
let (x, y) = write_string_to_grid(
|
|
|
|
&format!("Message-ID: {}", envelope.message_id_raw()),
|
|
|
|
grid,
|
|
|
|
Color::Byte(33),
|
|
|
|
Color::Default,
|
|
|
|
(set_y(upper_left, y + 1), bottom_right),
|
|
|
|
true,
|
2018-08-07 15:01:15 +03:00
|
|
|
);
|
2018-08-05 12:44:31 +03:00
|
|
|
for x in x..=get_x(bottom_right) {
|
|
|
|
grid[(x, y)].set_ch(' ');
|
|
|
|
grid[(x, y)].set_bg(Color::Default);
|
|
|
|
grid[(x, y)].set_fg(Color::Default);
|
|
|
|
}
|
|
|
|
clear_area(grid, (set_y(upper_left, y + 1), set_y(bottom_right, y + 2)));
|
|
|
|
context
|
|
|
|
.dirty_areas
|
|
|
|
.push_back((upper_left, set_y(bottom_right, y + 1)));
|
|
|
|
(envelope_idx, y + 1)
|
2018-07-22 18:02:44 +03:00
|
|
|
}
|
|
|
|
};
|
2018-07-23 15:40:13 +03:00
|
|
|
|
2018-07-22 18:02:44 +03:00
|
|
|
if self.dirty {
|
2018-07-23 22:21:41 +03:00
|
|
|
let buf = {
|
2018-07-27 18:01:52 +03:00
|
|
|
let mailbox_idx = self.coordinates; // coordinates are mailbox idxs
|
|
|
|
let mailbox = &mut context.accounts[mailbox_idx.0][mailbox_idx.1]
|
|
|
|
.as_ref()
|
|
|
|
.unwrap();
|
|
|
|
let envelope: &Envelope = &mailbox.collection[envelope_idx];
|
2018-07-23 22:21:41 +03:00
|
|
|
|
|
|
|
let finder = LinkFinder::new();
|
2018-07-23 15:40:13 +03:00
|
|
|
let mut text = match self.mode {
|
2018-08-05 12:44:31 +03:00
|
|
|
ViewMode::Normal => {
|
2018-07-25 22:37:28 +03:00
|
|
|
let mut t = envelope.body().text().to_string();
|
|
|
|
if envelope.body().count_attachments() > 1 {
|
2018-07-27 18:01:52 +03:00
|
|
|
t = envelope.body().attachments().iter().enumerate().fold(
|
|
|
|
t,
|
|
|
|
|mut s, (idx, a)| {
|
|
|
|
s.push_str(&format!("[{}] {}\n\n", idx, a));
|
|
|
|
s
|
|
|
|
},
|
|
|
|
);
|
2018-07-25 22:37:28 +03:00
|
|
|
}
|
|
|
|
t
|
2018-07-27 18:01:52 +03:00
|
|
|
}
|
2018-08-07 15:01:15 +03:00
|
|
|
ViewMode::Raw => String::from_utf8_lossy(&envelope.bytes()).into_owned(),
|
2018-08-05 12:44:31 +03:00
|
|
|
ViewMode::Url => {
|
2018-07-25 22:37:28 +03:00
|
|
|
let mut t = envelope.body().text().to_string();
|
2018-08-05 12:44:31 +03:00
|
|
|
for (lidx, l) in finder.links(&envelope.body().text()).enumerate() {
|
2018-08-08 12:38:24 +03:00
|
|
|
let offset = if lidx < 10 {
|
|
|
|
lidx * 3
|
|
|
|
} else if lidx < 100 {
|
|
|
|
26 + (lidx - 9) * 4
|
|
|
|
} else if lidx < 1000 {
|
|
|
|
385 + (lidx - 99) * 5
|
|
|
|
} else {
|
|
|
|
panic!("BUG: Message body with more than 100 urls");
|
|
|
|
};
|
|
|
|
t.insert_str(l.start() + offset, &format!("[{}]", lidx));
|
2018-08-05 12:44:31 +03:00
|
|
|
}
|
2018-07-25 22:37:28 +03:00
|
|
|
if envelope.body().count_attachments() > 1 {
|
2018-07-27 18:01:52 +03:00
|
|
|
t = envelope.body().attachments().iter().enumerate().fold(
|
|
|
|
t,
|
|
|
|
|mut s, (idx, a)| {
|
|
|
|
s.push_str(&format!("[{}] {}\n\n", idx, a));
|
|
|
|
s
|
|
|
|
},
|
|
|
|
);
|
2018-07-25 22:37:28 +03:00
|
|
|
}
|
2018-07-23 15:40:13 +03:00
|
|
|
t
|
2018-07-27 18:01:52 +03:00
|
|
|
}
|
2018-08-05 12:44:31 +03:00
|
|
|
ViewMode::Attachment(aidx) => {
|
|
|
|
let attachments = envelope.body().attachments();
|
2018-08-07 15:01:15 +03:00
|
|
|
let mut ret = "Viewing attachment. Press `r` to return \n".to_string();
|
2018-08-05 12:44:31 +03:00
|
|
|
ret.push_str(&attachments[aidx].text());
|
|
|
|
ret
|
|
|
|
}
|
2018-07-23 15:40:13 +03:00
|
|
|
};
|
2018-07-23 22:21:41 +03:00
|
|
|
let mut buf = CellBuffer::from(&text);
|
2018-08-07 15:01:15 +03:00
|
|
|
if self.mode == ViewMode::Url {
|
|
|
|
// URL indexes must be colored (ugh..)
|
2018-08-08 12:38:24 +03:00
|
|
|
let lines: Vec<&str> = text.split('\n').map(|l| l.trim_right()).collect();
|
2018-08-07 15:01:15 +03:00
|
|
|
let mut shift = 0;
|
2018-08-08 12:38:24 +03:00
|
|
|
let mut lidx_total = 0;
|
2018-08-07 15:01:15 +03:00
|
|
|
for r in &lines {
|
|
|
|
for l in finder.links(&r) {
|
2018-08-08 12:38:24 +03:00
|
|
|
let offset = if lidx_total < 10 {
|
|
|
|
3
|
|
|
|
} else if lidx_total < 100 {
|
|
|
|
4
|
|
|
|
} else if lidx_total < 1000 {
|
|
|
|
5
|
|
|
|
} else {
|
|
|
|
panic!("BUG: Message body with more than 100 urls");
|
|
|
|
};
|
|
|
|
for i in 1..=offset {
|
|
|
|
buf[(l.start() + shift - i, 0)].set_fg(Color::Byte(226));
|
|
|
|
//buf[(l.start() + shift - 2, 0)].set_fg(Color::Byte(226));
|
|
|
|
//buf[(l.start() + shift - 3, 0)].set_fg(Color::Byte(226));
|
|
|
|
}
|
|
|
|
lidx_total += 1;
|
2018-07-23 22:21:41 +03:00
|
|
|
}
|
2018-08-07 15:01:15 +03:00
|
|
|
// Each Cell represents one char so next line will be:
|
|
|
|
shift += r.chars().count() + 1;
|
2018-07-27 18:01:52 +03:00
|
|
|
}
|
2018-07-23 22:21:41 +03:00
|
|
|
}
|
2018-07-25 22:37:28 +03:00
|
|
|
buf
|
|
|
|
};
|
|
|
|
let cursor_pos = if self.mode.is_attachment() {
|
|
|
|
Some(0)
|
|
|
|
} else {
|
|
|
|
self.pager.as_mut().map(|p| p.cursor_pos())
|
2018-07-23 15:40:13 +03:00
|
|
|
};
|
2018-08-07 15:01:15 +03:00
|
|
|
self.pager = Some(Pager::from_buf(&buf, cursor_pos));
|
2018-07-22 18:02:44 +03:00
|
|
|
self.dirty = false;
|
|
|
|
}
|
2018-08-07 15:01:15 +03:00
|
|
|
|
|
|
|
if let Some(p) = self.pager.as_mut() {
|
|
|
|
p.draw(grid, (set_y(upper_left, y + 1), bottom_right), context);
|
|
|
|
}
|
2018-07-22 18:02:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fn process_event(&mut self, event: &UIEvent, context: &mut Context) {
|
2018-07-23 15:40:13 +03:00
|
|
|
match event.event_type {
|
2018-07-24 13:28:15 +03:00
|
|
|
UIEventType::Input(Key::Esc) => {
|
2018-07-25 22:37:28 +03:00
|
|
|
self.cmd_buf.clear();
|
2018-07-27 18:01:52 +03:00
|
|
|
}
|
|
|
|
UIEventType::Input(Key::Char(c)) if c >= '0' && c <= '9' => {
|
2018-07-24 16:55:00 +03:00
|
|
|
self.cmd_buf.push(c);
|
2018-07-27 18:01:52 +03:00
|
|
|
}
|
2018-08-07 15:01:15 +03:00
|
|
|
UIEventType::Input(Key::Char('r'))
|
|
|
|
if self.mode == ViewMode::Normal || self.mode == ViewMode::Raw =>
|
|
|
|
{
|
2018-08-05 12:44:31 +03:00
|
|
|
self.mode = if self.mode == ViewMode::Raw {
|
|
|
|
ViewMode::Normal
|
|
|
|
} else {
|
|
|
|
ViewMode::Raw
|
|
|
|
};
|
|
|
|
self.dirty = true;
|
|
|
|
}
|
2018-07-27 18:01:52 +03:00
|
|
|
UIEventType::Input(Key::Char('r')) if self.mode.is_attachment() => {
|
2018-07-25 22:37:28 +03:00
|
|
|
self.mode = ViewMode::Normal;
|
|
|
|
self.dirty = true;
|
2018-07-27 18:01:52 +03:00
|
|
|
}
|
|
|
|
UIEventType::Input(Key::Char('a'))
|
2018-08-07 15:01:15 +03:00
|
|
|
if !self.cmd_buf.is_empty() && self.mode == ViewMode::Normal =>
|
2018-07-27 18:01:52 +03:00
|
|
|
{
|
2018-07-24 16:55:00 +03:00
|
|
|
let lidx = self.cmd_buf.parse::<usize>().unwrap();
|
|
|
|
self.cmd_buf.clear();
|
|
|
|
|
2018-07-24 20:20:32 +03:00
|
|
|
{
|
2018-07-27 18:01:52 +03:00
|
|
|
let threaded = context.accounts[self.coordinates.0]
|
|
|
|
.runtime_settings
|
|
|
|
.threaded;
|
|
|
|
let mailbox = &mut context.accounts[self.coordinates.0][self.coordinates.1]
|
|
|
|
.as_ref()
|
|
|
|
.unwrap();
|
2018-07-24 16:55:00 +03:00
|
|
|
let envelope_idx: usize = if threaded {
|
|
|
|
mailbox.threaded_mail(self.coordinates.2)
|
|
|
|
} else {
|
|
|
|
self.coordinates.2
|
|
|
|
};
|
|
|
|
|
|
|
|
let envelope: &Envelope = &mailbox.collection[envelope_idx];
|
|
|
|
if let Some(u) = envelope.body().attachments().get(lidx) {
|
2018-07-25 22:37:28 +03:00
|
|
|
match u.content_type().0 {
|
2018-08-08 10:41:25 +03:00
|
|
|
ContentType::Text { .. } => {
|
2018-07-25 22:37:28 +03:00
|
|
|
self.mode = ViewMode::Attachment(lidx);
|
|
|
|
self.dirty = true;
|
2018-07-27 18:01:52 +03:00
|
|
|
}
|
2018-07-25 22:37:28 +03:00
|
|
|
ContentType::Multipart { .. } => {
|
2018-07-27 18:01:52 +03:00
|
|
|
context.replies.push_back(UIEvent {
|
|
|
|
id: 0,
|
2018-08-07 15:01:15 +03:00
|
|
|
event_type: UIEventType::StatusNotification(
|
|
|
|
"Multipart attachments are not supported yet.".to_string(),
|
|
|
|
),
|
2018-07-27 18:01:52 +03:00
|
|
|
});
|
2018-07-26 00:07:00 +03:00
|
|
|
return;
|
2018-07-27 18:01:52 +03:00
|
|
|
}
|
2018-07-25 22:37:28 +03:00
|
|
|
ContentType::Unsupported { .. } => {
|
|
|
|
let attachment_type = u.mime_type();
|
2018-07-26 00:07:00 +03:00
|
|
|
let binary = query_default_app(&attachment_type);
|
|
|
|
if let Ok(binary) = binary {
|
|
|
|
let mut p = create_temp_file(&decode(u), None);
|
|
|
|
Command::new(&binary)
|
|
|
|
.arg(p.path())
|
|
|
|
.stdin(Stdio::piped())
|
|
|
|
.stdout(Stdio::piped())
|
|
|
|
.spawn()
|
2018-08-07 15:01:15 +03:00
|
|
|
.unwrap_or_else(|_| {
|
|
|
|
panic!("Failed to start {}", binary.display())
|
|
|
|
});
|
2018-07-26 00:07:00 +03:00
|
|
|
} else {
|
2018-07-27 18:01:52 +03:00
|
|
|
context.replies.push_back(UIEvent {
|
|
|
|
id: 0,
|
|
|
|
event_type: UIEventType::StatusNotification(format!(
|
|
|
|
"Couldn't find a default application for type {}",
|
|
|
|
attachment_type
|
|
|
|
)),
|
|
|
|
});
|
2018-07-26 00:07:00 +03:00
|
|
|
return;
|
|
|
|
}
|
2018-07-27 18:01:52 +03:00
|
|
|
}
|
2018-07-25 22:37:28 +03:00
|
|
|
}
|
2018-07-24 16:55:00 +03:00
|
|
|
} else {
|
2018-07-27 18:01:52 +03:00
|
|
|
context.replies.push_back(UIEvent {
|
|
|
|
id: 0,
|
|
|
|
event_type: UIEventType::StatusNotification(format!(
|
|
|
|
"Attachment `{}` not found.",
|
|
|
|
lidx
|
|
|
|
)),
|
|
|
|
});
|
2018-07-24 16:55:00 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
};
|
2018-07-27 18:01:52 +03:00
|
|
|
}
|
|
|
|
UIEventType::Input(Key::Char('g'))
|
2018-08-07 15:01:15 +03:00
|
|
|
if !self.cmd_buf.is_empty() && self.mode == ViewMode::Url =>
|
2018-07-27 18:01:52 +03:00
|
|
|
{
|
2018-07-23 15:40:13 +03:00
|
|
|
let lidx = self.cmd_buf.parse::<usize>().unwrap();
|
|
|
|
self.cmd_buf.clear();
|
|
|
|
let url = {
|
2018-07-27 18:01:52 +03:00
|
|
|
let threaded = context.accounts[self.coordinates.0]
|
|
|
|
.runtime_settings
|
|
|
|
.threaded;
|
|
|
|
let mailbox = &mut context.accounts[self.coordinates.0][self.coordinates.1]
|
|
|
|
.as_ref()
|
|
|
|
.unwrap();
|
2018-07-23 15:40:13 +03:00
|
|
|
let envelope_idx: usize = if threaded {
|
|
|
|
mailbox.threaded_mail(self.coordinates.2)
|
|
|
|
} else {
|
|
|
|
self.coordinates.2
|
|
|
|
};
|
|
|
|
|
|
|
|
let envelope: &Envelope = &mailbox.collection[envelope_idx];
|
|
|
|
let finder = LinkFinder::new();
|
|
|
|
let mut t = envelope.body().text().to_string();
|
|
|
|
let links: Vec<Link> = finder.links(&t).collect();
|
2018-07-23 16:29:22 +03:00
|
|
|
if let Some(u) = links.get(lidx) {
|
|
|
|
u.as_str().to_string()
|
|
|
|
} else {
|
2018-07-27 18:01:52 +03:00
|
|
|
context.replies.push_back(UIEvent {
|
|
|
|
id: 0,
|
|
|
|
event_type: UIEventType::StatusNotification(format!(
|
|
|
|
"Link `{}` not found.",
|
|
|
|
lidx
|
|
|
|
)),
|
|
|
|
});
|
2018-07-23 16:29:22 +03:00
|
|
|
return;
|
|
|
|
}
|
2018-07-23 15:40:13 +03:00
|
|
|
};
|
|
|
|
|
2018-07-24 20:20:32 +03:00
|
|
|
Command::new("xdg-open")
|
2018-07-23 15:40:13 +03:00
|
|
|
.arg(url)
|
|
|
|
.stdin(Stdio::piped())
|
|
|
|
.stdout(Stdio::piped())
|
|
|
|
.spawn()
|
|
|
|
.expect("Failed to start xdg_open");
|
2018-07-27 18:01:52 +03:00
|
|
|
}
|
|
|
|
UIEventType::Input(Key::Char('u')) => {
|
2018-07-23 15:40:13 +03:00
|
|
|
match self.mode {
|
2018-07-27 18:01:52 +03:00
|
|
|
ViewMode::Normal => self.mode = ViewMode::Url,
|
|
|
|
ViewMode::Url => self.mode = ViewMode::Normal,
|
|
|
|
_ => {}
|
2018-07-23 15:40:13 +03:00
|
|
|
}
|
|
|
|
self.dirty = true;
|
2018-07-27 18:01:52 +03:00
|
|
|
}
|
|
|
|
_ => {}
|
2018-07-23 15:40:13 +03:00
|
|
|
}
|
2018-07-22 18:02:44 +03:00
|
|
|
if let Some(ref mut sub) = self.subview {
|
|
|
|
sub.process_event(event, context);
|
2018-08-07 15:01:15 +03:00
|
|
|
} else if let Some(ref mut p) = self.pager {
|
|
|
|
p.process_event(event, context);
|
2018-07-22 18:02:44 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
fn is_dirty(&self) -> bool {
|
2018-07-27 18:01:52 +03:00
|
|
|
self.dirty
|
|
|
|
|| self.pager.as_ref().map(|p| p.is_dirty()).unwrap_or(false)
|
|
|
|
|| self.subview.as_ref().map(|p| p.is_dirty()).unwrap_or(false)
|
2018-07-22 18:02:44 +03:00
|
|
|
}
|
|
|
|
}
|