summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorManos Pitsidianakis <el13635@mail.ntua.gr>2018-08-05 12:44:31 +0300
committerManos Pitsidianakis <el13635@mail.ntua.gr>2019-06-10 19:40:26 +0300
commit375b256a4e8eead6a4d7989b667554d542723abb (patch)
tree11f7119f97b28e294c59e3bbffcd308283fef0e3 /ui
parent63ce729205f4063112ebdd9ba5bdef858f1028c9 (diff)
Add raw mode view in email
Diffstat (limited to 'ui')
-rw-r--r--ui/src/components/mail/view.rs181
-rw-r--r--ui/src/components/utilities.rs4
2 files changed, 101 insertions, 84 deletions
diff --git a/ui/src/components/mail/view.rs b/ui/src/components/mail/view.rs
index 649737ac..a5644ea0 100644
--- a/ui/src/components/mail/view.rs
+++ b/ui/src/components/mail/view.rs
@@ -9,7 +9,7 @@ enum ViewMode {
Normal,
Url,
Attachment(usize),
- // Raw,
+ Raw,
}
impl ViewMode {
@@ -73,76 +73,84 @@ impl Component for MailView {
let envelope: &Envelope = &mailbox.collection[envelope_idx];
- let (x, y) = write_string_to_grid(
- &format!("Date: {}", envelope.date_as_str()),
- grid,
- Color::Byte(33),
- Color::Default,
- area,
- 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!("From: {}", envelope.from_to_string()),
- 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!("To: {}", envelope.to_to_string()),
- 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!("Subject: {}", envelope.subject()),
- 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!("Message-ID: {}", envelope.message_id_raw()),
- 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);
+ if self.mode == ViewMode::Raw {
+ clear_area(grid, area);
+ context
+ .dirty_areas
+ .push_back(area);
+ (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,
+ );
+ 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,
+ );
+ 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,
+ );
+ 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,
+ );
+ 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,
+ );
+ 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)
}
- 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)
};
if self.dirty {
@@ -157,11 +165,8 @@ impl Component for MailView {
let finder = LinkFinder::new();
let mut text = match self.mode {
- ViewMode::Url => {
+ ViewMode::Normal => {
let mut t = envelope.body().text().to_string();
- for (lidx, l) in finder.links(&envelope.body().text()).enumerate() {
- t.insert_str(l.start() + (lidx * 3), &format!("[{}]", lidx));
- }
if envelope.body().count_attachments() > 1 {
t = envelope.body().attachments().iter().enumerate().fold(
t,
@@ -173,14 +178,14 @@ impl Component for MailView {
}
t
}
- ViewMode::Attachment(aidx) => {
- let attachments = envelope.body().attachments();
- let mut ret = format!("Viewing attachment. Press `r` to return \n");
- ret.push_str(&attachments[aidx].text());
- ret
- }
- _ => {
+ ViewMode::Raw => {
+ String::from_utf8_lossy(&envelope.bytes()).into_owned()
+ },
+ ViewMode::Url => {
let mut t = envelope.body().text().to_string();
+ for (lidx, l) in finder.links(&envelope.body().text()).enumerate() {
+ t.insert_str(l.start() + (lidx * 3), &format!("[{}]", lidx));
+ }
if envelope.body().count_attachments() > 1 {
t = envelope.body().attachments().iter().enumerate().fold(
t,
@@ -192,6 +197,12 @@ impl Component for MailView {
}
t
}
+ ViewMode::Attachment(aidx) => {
+ let attachments = envelope.body().attachments();
+ let mut ret = format!("Viewing attachment. Press `r` to return \n");
+ ret.push_str(&attachments[aidx].text());
+ ret
+ }
};
let mut buf = CellBuffer::from(&text);
match self.mode {
@@ -236,6 +247,14 @@ impl Component for MailView {
//TODO:this should be an Action
self.cmd_buf.push(c);
}
+ UIEventType::Input(Key::Char('r')) if self.mode == ViewMode::Normal || self.mode == ViewMode::Raw => {
+ self.mode = if self.mode == ViewMode::Raw {
+ ViewMode::Normal
+ } else {
+ ViewMode::Raw
+ };
+ self.dirty = true;
+ }
UIEventType::Input(Key::Char('r')) if self.mode.is_attachment() => {
//TODO:one quit shortcut?
self.mode = ViewMode::Normal;
diff --git a/ui/src/components/utilities.rs b/ui/src/components/utilities.rs
index 43573813..e2c7de65 100644
--- a/ui/src/components/utilities.rs
+++ b/ui/src/components/utilities.rs
@@ -259,15 +259,13 @@ impl Component for Pager {
if !self.is_dirty() {
return;
}
- let upper_left = upper_left!(area);
- let bottom_right = bottom_right!(area);
self.dirty = false;
if self.height == 0 || self.height == self.cursor_pos || self.width == 0 {
return;
}
- clear_area(grid, (upper_left, bottom_right));
+ clear_area(grid, area);
//let pager_context: usize = context.settings.pager.pager_context;
//let pager_stop: bool = context.settings.pager.pager_stop;
//let rows = y(bottom_right) - y(upper_left);