diff options
author | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2018-07-23 16:29:22 +0300 |
---|---|---|
committer | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-06-10 19:40:24 +0300 |
commit | d962da665f3a4a026b5539f1964d820652e14814 (patch) | |
tree | dc95172d8be763e94a9ec7ff4117faf2fe35572f /ui | |
parent | d0e6bc24f4664ed2d50cb40bc83c81c7914b409b (diff) |
Add range check in url open along with status bar notifications
concerns #13
Diffstat (limited to 'ui')
-rw-r--r-- | ui/src/components/mail/view.rs | 7 | ||||
-rw-r--r-- | ui/src/components/utilities.rs | 25 | ||||
-rw-r--r-- | ui/src/lib.rs | 1 |
3 files changed, 27 insertions, 6 deletions
diff --git a/ui/src/components/mail/view.rs b/ui/src/components/mail/view.rs index b8a43ffa..60d7c5a1 100644 --- a/ui/src/components/mail/view.rs +++ b/ui/src/components/mail/view.rs @@ -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; + } }; diff --git a/ui/src/components/utilities.rs b/ui/src/components/utilities.rs index 2d14adfc..b5822eab 100644 --- a/ui/src/components/utilities.rs +++ b/ui/src/components/utilities.rs @@ -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; + }, _ => {}, } } diff --git a/ui/src/lib.rs b/ui/src/lib.rs index 93a25bee..81b9f57a 100644 --- a/ui/src/lib.rs +++ b/ui/src/lib.rs @@ -107,6 +107,7 @@ pub enum UIEventType { Notification(String), EditDraft(std::path::PathBuf), Action(Action), + StatusNotification(String), } |