From 5f24515145f4e36315ca1e308f909b7e275b42b0 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Sun, 26 Aug 2018 19:29:12 +0300 Subject: [PATCH] Add buffer display in statusbar --- ui/src/components/mail/view/envelope.rs | 41 ++++++++++++------- ui/src/components/mail/view/html.rs | 4 +- ui/src/components/mail/view/mod.rs | 52 +++++++++++++++++-------- ui/src/components/mod.rs | 20 +++++++++- ui/src/components/utilities.rs | 21 +++++++++- ui/src/types/mod.rs | 9 ++++- 6 files changed, 111 insertions(+), 36 deletions(-) diff --git a/ui/src/components/mail/view/envelope.rs b/ui/src/components/mail/view/envelope.rs index 2a809d080..caf78dc5f 100644 --- a/ui/src/components/mail/view/envelope.rs +++ b/ui/src/components/mail/view/envelope.rs @@ -326,8 +326,12 @@ impl Component for EnvelopeView { } } match event.event_type { - UIEventType::Input(Key::Esc) => { + UIEventType::Input(Key::Esc) | UIEventType::Input(Key::Alt('')) => { self.cmd_buf.clear(); + context.replies.push_back(UIEvent { + id: 0, + event_type: UIEventType::StatusEvent(StatusEvent::BufClear), + }); return true; } UIEventType::Input(Key::Char(c)) if c >= '0' && c <= '9' => { @@ -358,6 +362,10 @@ impl Component for EnvelopeView { { let lidx = self.cmd_buf.parse::().unwrap(); self.cmd_buf.clear(); + context.replies.push_back(UIEvent { + id: 0, + event_type: UIEventType::StatusEvent(StatusEvent::BufClear), + }); { let envelope: &Envelope = self.wrapper.envelope(); @@ -382,8 +390,11 @@ impl Component for EnvelopeView { ContentType::Multipart { .. } => { context.replies.push_back(UIEvent { id: 0, - event_type: UIEventType::StatusNotification( - "Multipart attachments are not supported yet.".to_string(), + event_type: UIEventType::StatusEvent( + StatusEvent::DisplayMessage( + "Multipart attachments are not supported yet." + .to_string(), + ), ), }); return true; @@ -405,10 +416,12 @@ impl Component for EnvelopeView { } else { context.replies.push_back(UIEvent { id: 0, - event_type: UIEventType::StatusNotification(format!( - "Couldn't find a default application for type {}", - attachment_type - )), + event_type: UIEventType::StatusEvent( + StatusEvent::DisplayMessage(format!( + "Couldn't find a default application for type {}", + attachment_type + )), + ), }); return true; } @@ -417,9 +430,8 @@ impl Component for EnvelopeView { } else { context.replies.push_back(UIEvent { id: 0, - event_type: UIEventType::StatusNotification(format!( - "Attachment `{}` not found.", - lidx + event_type: UIEventType::StatusEvent(StatusEvent::DisplayMessage( + format!("Attachment `{}` not found.", lidx), )), }); return true; @@ -432,6 +444,10 @@ impl Component for EnvelopeView { { let lidx = self.cmd_buf.parse::().unwrap(); self.cmd_buf.clear(); + context.replies.push_back(UIEvent { + id: 0, + event_type: UIEventType::StatusEvent(StatusEvent::BufClear), + }); let url = { let envelope: &Envelope = self.wrapper.envelope(); let finder = LinkFinder::new(); @@ -445,9 +461,8 @@ impl Component for EnvelopeView { } else { context.replies.push_back(UIEvent { id: 0, - event_type: UIEventType::StatusNotification(format!( - "Link `{}` not found.", - lidx + event_type: UIEventType::StatusEvent(StatusEvent::DisplayMessage( + format!("Link `{}` not found.", lidx), )), }); return true; diff --git a/ui/src/components/mail/view/html.rs b/ui/src/components/mail/view/html.rs index a9dbc7178..8fbe90fde 100644 --- a/ui/src/components/mail/view/html.rs +++ b/ui/src/components/mail/view/html.rs @@ -86,9 +86,9 @@ impl Component for HtmlView { } else { context.replies.push_back(UIEvent { id: 0, - event_type: UIEventType::StatusNotification( + event_type: UIEventType::StatusEvent(StatusEvent::DisplayMessage( "Couldn't find a default application for html files.".to_string(), - ), + )), }); } return true; diff --git a/ui/src/components/mail/view/mod.rs b/ui/src/components/mail/view/mod.rs index f5344718f..06e4bc2f4 100644 --- a/ui/src/components/mail/view/mod.rs +++ b/ui/src/components/mail/view/mod.rs @@ -352,11 +352,19 @@ impl Component for MailView { } } match event.event_type { - UIEventType::Input(Key::Esc) => { + UIEventType::Input(Key::Esc) | UIEventType::Input(Key::Alt('')) => { self.cmd_buf.clear(); + context.replies.push_back(UIEvent { + id: 0, + event_type: UIEventType::StatusEvent(StatusEvent::BufClear), + }); } UIEventType::Input(Key::Char(c)) if c >= '0' && c <= '9' => { self.cmd_buf.push(c); + context.replies.push_back(UIEvent { + id: 0, + event_type: UIEventType::StatusEvent(StatusEvent::BufSet(self.cmd_buf.clone())), + }); } UIEventType::Input(Key::Char('r')) if self.mode == ViewMode::Normal || self.mode == ViewMode::Raw => @@ -380,6 +388,10 @@ impl Component for MailView { { let lidx = self.cmd_buf.parse::().unwrap(); self.cmd_buf.clear(); + context.replies.push_back(UIEvent { + id: 0, + event_type: UIEventType::StatusEvent(StatusEvent::BufClear), + }); { let accounts = &context.accounts; @@ -403,10 +415,9 @@ impl Component for MailView { Err(e) => { context.replies.push_back(UIEvent { id: 0, - event_type: UIEventType::StatusNotification(format!( - "{}", - e - )), + event_type: UIEventType::StatusEvent( + StatusEvent::DisplayMessage(format!("{}", e)), + ), }); } } @@ -420,8 +431,11 @@ impl Component for MailView { ContentType::Multipart { .. } => { context.replies.push_back(UIEvent { id: 0, - event_type: UIEventType::StatusNotification( - "Multipart attachments are not supported yet.".to_string(), + event_type: UIEventType::StatusEvent( + StatusEvent::DisplayMessage( + "Multipart attachments are not supported yet." + .to_string(), + ), ), }); return true; @@ -443,10 +457,12 @@ impl Component for MailView { } else { context.replies.push_back(UIEvent { id: 0, - event_type: UIEventType::StatusNotification(format!( - "Couldn't find a default application for type {}", - attachment_type - )), + event_type: UIEventType::StatusEvent( + StatusEvent::DisplayMessage(format!( + "Couldn't find a default application for type {}", + attachment_type + )), + ), }); return true; } @@ -455,9 +471,8 @@ impl Component for MailView { } else { context.replies.push_back(UIEvent { id: 0, - event_type: UIEventType::StatusNotification(format!( - "Attachment `{}` not found.", - lidx + event_type: UIEventType::StatusEvent(StatusEvent::DisplayMessage( + format!("Attachment `{}` not found.", lidx), )), }); return true; @@ -469,6 +484,10 @@ impl Component for MailView { { let lidx = self.cmd_buf.parse::().unwrap(); self.cmd_buf.clear(); + context.replies.push_back(UIEvent { + id: 0, + event_type: UIEventType::StatusEvent(StatusEvent::BufClear), + }); let url = { let accounts = &context.accounts; let mailbox = &accounts[self.coordinates.0][self.coordinates.1] @@ -487,9 +506,8 @@ impl Component for MailView { } else { context.replies.push_back(UIEvent { id: 0, - event_type: UIEventType::StatusNotification(format!( - "Link `{}` not found.", - lidx + event_type: UIEventType::StatusEvent(StatusEvent::DisplayMessage( + format!("Link `{}` not found.", lidx), )), }); return true; diff --git a/ui/src/components/mod.rs b/ui/src/components/mod.rs index acf40e120..06ba74406 100644 --- a/ui/src/components/mod.rs +++ b/ui/src/components/mod.rs @@ -39,7 +39,7 @@ use std::fmt; use std::fmt::{Debug, Display}; use std::ops::Deref; -use super::{Key, UIEvent, UIEventType}; +use super::{Key, StatusEvent, UIEvent, UIEventType}; /// The upper and lower boundary char. const HORZ_BOUNDARY: char = '─'; /// The left and right boundary char. @@ -113,6 +113,22 @@ fn new_draft(_context: &mut Context) -> Vec { v.into_bytes() } +pub(crate) fn is_box_char(ch: char) -> bool { + match ch { + HORZ_BOUNDARY | VERT_BOUNDARY => true, + _ => false, + } +} + +/* + * pub(crate) fn is_box_char(ch: char) -> bool { + * match ch { + * '└' | '─' | '┘' | '┴' | '┌' | '│' | '├' | '┐' | '┬' | '┤' | '┼' | '╷' | '╵' | '╴' | '╶' => true, + * _ => false, + * } + * } + */ + fn bin_to_ch(b: u32) -> char { match b { 0b0001 => '╶', @@ -345,7 +361,7 @@ fn set_and_join_horz(grid: &mut CellBuffer, idx: Pos) -> u32 { bin_set } -fn set_and_join_box(grid: &mut CellBuffer, idx: Pos, ch: char) { +pub(crate) fn set_and_join_box(grid: &mut CellBuffer, idx: Pos, ch: char) { /* Connected sides: * * 1 diff --git a/ui/src/components/utilities.rs b/ui/src/components/utilities.rs index 09436265f..b757834f3 100644 --- a/ui/src/components/utilities.rs +++ b/ui/src/components/utilities.rs @@ -428,6 +428,7 @@ pub struct StatusBar { status: String, notifications: VecDeque, ex_buffer: String, + display_buffer: String, mode: UIMode, height: usize, dirty: bool, @@ -447,6 +448,7 @@ impl StatusBar { status: String::with_capacity(256), notifications: VecDeque::new(), ex_buffer: String::with_capacity(256), + display_buffer: String::with_capacity(8), dirty: true, mode: UIMode::Normal, height: 1, @@ -467,6 +469,15 @@ impl StatusBar { false, ); } + let (x, y) = bottom_right!(area); + for (idx, c) in self.display_buffer.chars().rev().enumerate() { + if let Some(cell) = grid.get_mut(x.saturating_sub(idx).saturating_sub(1), y) { + cell.set_ch(c); + } else { + break; + } + } + change_colors(grid, area, Color::Byte(123), Color::Byte(26)); context.dirty_areas.push_back(area); } @@ -595,10 +606,18 @@ impl Component for StatusBar { UIEventType::Resize => { self.dirty = true; } - UIEventType::StatusNotification(s) => { + UIEventType::StatusEvent(StatusEvent::DisplayMessage(s)) => { self.notifications.push_back(s.clone()); self.dirty = true; } + UIEventType::StatusEvent(StatusEvent::BufClear) => { + self.display_buffer.clear(); + self.dirty = true; + } + UIEventType::StatusEvent(StatusEvent::BufSet(s)) => { + self.display_buffer = s.clone(); + self.dirty = true; + } _ => {} } false diff --git a/ui/src/types/mod.rs b/ui/src/types/mod.rs index 6e9f1c6bd..bd7a67e65 100644 --- a/ui/src/types/mod.rs +++ b/ui/src/types/mod.rs @@ -41,6 +41,13 @@ use std; use std::fmt; use std::thread; +#[derive(Debug)] +pub enum StatusEvent { + DisplayMessage(String), + BufClear, + BufSet(String), +} + /// `ThreadEvent` encapsulates all of the possible values we need to transfer between our threads /// to the main process. #[derive(Debug)] @@ -83,7 +90,7 @@ pub enum UIEventType { Notification(String), EditDraft(File), Action(Action), - StatusNotification(String), + StatusEvent(StatusEvent), MailboxUpdate((usize, usize)), StartupCheck,