compose: expand cursor reach to attachment area

jmap-eventsource
Manos Pitsidianakis 2020-10-09 17:17:11 +03:00
parent e42c9281fd
commit eb1cb5cec6
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
1 changed files with 100 additions and 34 deletions

View File

@ -38,7 +38,9 @@ use std::sync::{Arc, Mutex};
enum Cursor { enum Cursor {
Headers, Headers,
Body, Body,
//Attachments, Sign,
Encrypt,
Attachments,
} }
#[derive(Debug)] #[derive(Debug)]
@ -438,7 +440,11 @@ impl Composer {
), ),
grid, grid,
theme_default.fg, theme_default.fg,
theme_default.bg, if self.cursor == Cursor::Sign {
Color::Byte(237)
} else {
theme_default.bg
},
theme_default.attrs, theme_default.attrs,
(pos_inc(upper_left!(area), (0, 1)), bottom_right!(area)), (pos_inc(upper_left!(area), (0, 1)), bottom_right!(area)),
None, None,
@ -448,7 +454,11 @@ impl Composer {
"☐ don't sign", "☐ don't sign",
grid, grid,
theme_default.fg, theme_default.fg,
theme_default.bg, if self.cursor == Cursor::Sign {
Color::Byte(237)
} else {
theme_default.bg
},
theme_default.attrs, theme_default.attrs,
(pos_inc(upper_left!(area), (0, 1)), bottom_right!(area)), (pos_inc(upper_left!(area), (0, 1)), bottom_right!(area)),
None, None,
@ -465,7 +475,11 @@ impl Composer {
), ),
grid, grid,
theme_default.fg, theme_default.fg,
theme_default.bg, if self.cursor == Cursor::Encrypt {
Color::Byte(237)
} else {
theme_default.bg
},
theme_default.attrs, theme_default.attrs,
(pos_inc(upper_left!(area), (0, 2)), bottom_right!(area)), (pos_inc(upper_left!(area), (0, 2)), bottom_right!(area)),
None, None,
@ -475,7 +489,11 @@ impl Composer {
"☐ don't encrypt", "☐ don't encrypt",
grid, grid,
theme_default.fg, theme_default.fg,
theme_default.bg, if self.cursor == Cursor::Encrypt {
Color::Byte(237)
} else {
theme_default.bg
},
theme_default.attrs, theme_default.attrs,
(pos_inc(upper_left!(area), (0, 2)), bottom_right!(area)), (pos_inc(upper_left!(area), (0, 2)), bottom_right!(area)),
None, None,
@ -486,7 +504,11 @@ impl Composer {
"no attachments", "no attachments",
grid, grid,
theme_default.fg, theme_default.fg,
theme_default.bg, if self.cursor == Cursor::Attachments {
Color::Byte(237)
} else {
theme_default.bg
},
theme_default.attrs, theme_default.attrs,
(pos_inc(upper_left!(area), (0, 3)), bottom_right!(area)), (pos_inc(upper_left!(area), (0, 3)), bottom_right!(area)),
None, None,
@ -496,7 +518,11 @@ impl Composer {
&format!("{} attachments ", attachments_no), &format!("{} attachments ", attachments_no),
grid, grid,
theme_default.fg, theme_default.fg,
theme_default.bg, if self.cursor == Cursor::Attachments {
Color::Byte(237)
} else {
theme_default.bg
},
theme_default.attrs, theme_default.attrs,
(pos_inc(upper_left!(area), (0, 3)), bottom_right!(area)), (pos_inc(upper_left!(area), (0, 3)), bottom_right!(area)),
None, None,
@ -602,13 +628,16 @@ impl Component for Composer {
); );
let attachments_no = self.draft.attachments().len(); let attachments_no = self.draft.attachments().len();
let attachment_area = ( let attachment_area = (
(mid + 1, get_y(bottom_right) - 2 - attachments_no), (
mid + 1,
get_y(bottom_right).saturating_sub(4 + attachments_no),
),
pos_dec(bottom_right, (mid, 0)), pos_dec(bottom_right, (mid, 0)),
); );
let body_area = ( let body_area = (
pos_inc(upper_left, (mid + 1, header_height + 1)), pos_inc(upper_left, (mid + 1, header_height + 1)),
pos_dec(bottom_right, (mid, 3 + attachments_no)), pos_dec(bottom_right, (mid, 4 + attachments_no)),
); );
let (x, y) = write_string_to_grid( let (x, y) = write_string_to_grid(
@ -696,26 +725,30 @@ impl Component for Composer {
self.pager.draw(grid, body_area, context); self.pager.draw(grid, body_area, context);
} }
if self.cursor == Cursor::Body { match self.cursor {
change_colors( Cursor::Headers => {
grid, change_colors(
( grid,
set_y(upper_left!(body_area), get_y(bottom_right!(body_area))), (
bottom_right!(body_area), set_y(upper_left!(body_area), get_y(bottom_right!(body_area))),
), bottom_right!(body_area),
theme_default.fg, ),
Color::Byte(237), theme_default.fg,
); theme_default.bg,
} else { );
change_colors( }
grid, Cursor::Body => {
( change_colors(
set_y(upper_left!(body_area), get_y(bottom_right!(body_area))), grid,
bottom_right!(body_area), (
), set_y(upper_left!(body_area), get_y(bottom_right!(body_area))),
theme_default.fg, bottom_right!(body_area),
theme_default.bg, ),
); theme_default.fg,
Color::Byte(237),
);
}
Cursor::Sign | Cursor::Encrypt | Cursor::Attachments => {}
} }
match self.mode { match self.mode {
@ -948,16 +981,49 @@ impl Component for Composer {
return true; return true;
}*/ }*/
UIEvent::Input(ref key) UIEvent::Input(ref key)
if shortcut!(key == shortcuts[Self::DESCRIPTION]["scroll_up"]) => if self.mode.is_edit()
&& shortcut!(key == shortcuts[Self::DESCRIPTION]["scroll_up"]) =>
{ {
self.cursor = Cursor::Headers; self.cursor = match self.cursor {
self.form.process_event(event, context); Cursor::Headers => return true,
Cursor::Body => {
self.form.process_event(event, context);
Cursor::Headers
}
Cursor::Sign => Cursor::Body,
Cursor::Encrypt => Cursor::Sign,
Cursor::Attachments => Cursor::Encrypt,
};
self.dirty = true; self.dirty = true;
} }
UIEvent::Input(ref key) UIEvent::Input(ref key)
if shortcut!(key == shortcuts[Self::DESCRIPTION]["scroll_down"]) => if self.mode.is_edit()
&& shortcut!(key == shortcuts[Self::DESCRIPTION]["scroll_down"]) =>
{ {
self.cursor = Cursor::Body; self.cursor = match self.cursor {
Cursor::Headers => Cursor::Body,
Cursor::Body => Cursor::Sign,
Cursor::Sign => Cursor::Encrypt,
Cursor::Encrypt => Cursor::Attachments,
Cursor::Attachments => return true,
};
self.dirty = true;
}
UIEvent::Input(Key::Char('\n'))
if self.mode.is_edit()
&& (self.cursor == Cursor::Sign || self.cursor == Cursor::Encrypt) =>
{
match self.cursor {
Cursor::Sign => {
let is_true = self.sign_mail.is_true();
self.sign_mail = ToggleFlag::from(!is_true);
}
Cursor::Encrypt => {
let is_true = self.encrypt_mail.is_true();
self.encrypt_mail = ToggleFlag::from(!is_true);
}
_ => {}
};
self.dirty = true; self.dirty = true;
} }
UIEvent::Input(ref key) UIEvent::Input(ref key)