From d3ce424361adf0b79a0a5f0e2f37d8c7e8c78b5e Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Wed, 5 Jun 2019 01:27:13 +0300 Subject: [PATCH] ui: add update and expand_headers in MailView --- ui/src/components/mail/view.rs | 52 +++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/ui/src/components/mail/view.rs b/ui/src/components/mail/view.rs index ba8083dcc..461586a71 100644 --- a/ui/src/components/mail/view.rs +++ b/ui/src/components/mail/view.rs @@ -67,6 +67,7 @@ pub struct MailView { subview: Option>, dirty: bool, mode: ViewMode, + expand_headers: bool, cmd_buf: String, id: ComponentId, @@ -110,6 +111,7 @@ impl MailView { subview, dirty: true, mode: ViewMode::Normal, + expand_headers: false, cmd_buf: String::with_capacity(4), id: ComponentId::new_v4(), @@ -279,6 +281,12 @@ impl MailView { } buf } + + pub fn update(&mut self, new_coordinates: (usize, usize, EnvelopeHash)) { + self.coordinates = new_coordinates; + self.mode = ViewMode::Normal; + self.set_dirty(); + } } impl Component for MailView { @@ -355,7 +363,7 @@ impl Component for MailView { grid[(x, y)].set_bg(Color::Default); grid[(x, y)].set_fg(Color::Default); } - let (x, y) = write_string_to_grid( + let (x, mut y) = write_string_to_grid( &format!("Message-ID: <{}>", envelope.message_id_raw()), grid, Color::Byte(33), @@ -368,6 +376,43 @@ impl Component for MailView { grid[(x, y)].set_bg(Color::Default); grid[(x, y)].set_fg(Color::Default); } + if self.expand_headers && envelope.in_reply_to().is_some() { + let (x, _y) = write_string_to_grid( + &format!("In-Reply-To: {}", envelope.in_reply_to_display().unwrap()), + grid, + Color::Byte(33), + Color::Default, + (set_y(upper_left, y + 1), bottom_right), + true, + ); + 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!( + "References: {}", + envelope + .references() + .iter() + .map(|r| r.to_string()) + .collect::>() + .join(", ") + ), + grid, + Color::Byte(33), + Color::Default, + (set_y(upper_left, _y + 1), bottom_right), + true, + ); + 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); + } + y = _y; + } clear_area(grid, (set_y(upper_left, y + 1), set_y(bottom_right, y + 1))); context .dirty_areas @@ -656,6 +701,11 @@ impl Component for MailView { } }; } + UIEvent::Input(Key::Char('h')) => { + self.expand_headers = !self.expand_headers; + self.dirty = true; + return true; + } UIEvent::Input(Key::Char('g')) if !self.cmd_buf.is_empty() && self.mode == ViewMode::Url => {