Add range check in url open along with status bar notifications

concerns #13
embed
Manos Pitsidianakis 2018-07-23 16:29:22 +03:00
parent d0e6bc24f4
commit d962da665f
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
3 changed files with 27 additions and 6 deletions

View File

@ -172,7 +172,12 @@ impl Component for MailView {
let finder = LinkFinder::new();
let mut t = envelope.body().text().to_string();
let links: Vec<Link> = finder.links(&t).collect();
links[lidx].as_str().to_string()
if let Some(u) = links.get(lidx) {
u.as_str().to_string()
} else {
context.replies.push_back(UIEvent { id: 0, event_type: UIEventType::StatusNotification(format!("Link `{}` not found.", lidx)) });
return;
}
};

View File

@ -269,6 +269,7 @@ impl Component for Pager {
pub struct StatusBar {
container: Entity,
status: String,
notifications: VecDeque<String>,
ex_buffer: String,
mode: UIMode,
height: usize,
@ -280,6 +281,7 @@ impl StatusBar {
StatusBar {
container: container,
status: String::with_capacity(256),
notifications: VecDeque::new(),
ex_buffer: String::with_capacity(256),
dirty: true,
mode: UIMode::Normal,
@ -288,11 +290,20 @@ impl StatusBar {
}
fn draw_status_bar(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) {
clear_area(grid, area);
write_string_to_grid(&self.status,
grid,
Color::Byte(123),
Color::Byte(26),
area, false);
if let Some(n) = self.notifications.pop_front() {
self.dirty = true;
write_string_to_grid(&n,
grid,
Color::Byte(219),
Color::Byte(88),
area, false);
} else {
write_string_to_grid(&self.status,
grid,
Color::Byte(123),
Color::Byte(26),
area, false);
}
change_colors(grid, area, Color::Byte(123), Color::Byte(26));
context.dirty_areas.push_back(area);
}
@ -377,6 +388,10 @@ impl Component for StatusBar {
UIEventType::Resize => {
self.dirty = true;
},
UIEventType::StatusNotification(s) => {
self.notifications.push_back(s.clone());
self.dirty = true;
},
_ => {},
}
}

View File

@ -107,6 +107,7 @@ pub enum UIEventType {
Notification(String),
EditDraft(std::path::PathBuf),
Action(Action),
StatusNotification(String),
}