|
|
|
@ -93,10 +93,10 @@ impl MailListing {
|
|
|
|
|
};
|
|
|
|
|
let new_area = (set_y(upper_left, get_y(upper_left)+(*idx % rows)), bottom_right);
|
|
|
|
|
let x = write_string_to_grid(&make_entry_string(envelope, *idx),
|
|
|
|
|
grid,
|
|
|
|
|
fg_color,
|
|
|
|
|
bg_color,
|
|
|
|
|
new_area);
|
|
|
|
|
grid,
|
|
|
|
|
fg_color,
|
|
|
|
|
bg_color,
|
|
|
|
|
new_area);
|
|
|
|
|
for x in x..=get_x(bottom_right) {
|
|
|
|
|
grid[(x,get_y(upper_left)+(*idx % rows))].set_ch(' ');
|
|
|
|
|
grid[(x,get_y(upper_left)+(*idx % rows))].set_bg(bg_color);
|
|
|
|
@ -131,16 +131,16 @@ impl MailListing {
|
|
|
|
|
if !envelope.is_seen() {
|
|
|
|
|
Color::Byte(251)
|
|
|
|
|
} else if idx % 2 == 0 {
|
|
|
|
|
Color::Byte(236)
|
|
|
|
|
Color::Byte(236)
|
|
|
|
|
} else {
|
|
|
|
|
Color::Default
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
let x = write_string_to_grid(&make_entry_string(envelope, idx),
|
|
|
|
|
grid,
|
|
|
|
|
fg_color,
|
|
|
|
|
bg_color,
|
|
|
|
|
(set_y(upper_left, y), bottom_right));
|
|
|
|
|
grid,
|
|
|
|
|
fg_color,
|
|
|
|
|
bg_color,
|
|
|
|
|
(set_y(upper_left, y), bottom_right));
|
|
|
|
|
|
|
|
|
|
for x in x..=get_x(bottom_right) {
|
|
|
|
|
grid[(x,y)].set_ch(' ');
|
|
|
|
@ -234,52 +234,51 @@ impl Component for MailListing {
|
|
|
|
|
{
|
|
|
|
|
let ref mail = self.mailbox.collection[self.cursor_pos];
|
|
|
|
|
|
|
|
|
|
eprintln!("writing headers {} {}", mail.get_date_as_str(), mail.get_subject());
|
|
|
|
|
let x = write_string_to_grid(&format!("Date: {}", mail.get_date_as_str()),
|
|
|
|
|
grid,
|
|
|
|
|
Color::Byte(33),
|
|
|
|
|
Color::Default,
|
|
|
|
|
(set_y(upper_left, mid+1), set_y(bottom_right, mid+1)));
|
|
|
|
|
grid,
|
|
|
|
|
Color::Byte(33),
|
|
|
|
|
Color::Default,
|
|
|
|
|
(set_y(upper_left, mid+1), set_y(bottom_right, mid+1)));
|
|
|
|
|
for x in x..=get_x(bottom_right) {
|
|
|
|
|
grid[(x, mid+1)].set_ch(' ');
|
|
|
|
|
grid[(x, mid+1)].set_bg(Color::Default);
|
|
|
|
|
grid[(x, mid+1)].set_fg(Color::Default);
|
|
|
|
|
}
|
|
|
|
|
let x = write_string_to_grid(&format!("From: {}", mail.get_from()),
|
|
|
|
|
grid,
|
|
|
|
|
Color::Byte(33),
|
|
|
|
|
Color::Default,
|
|
|
|
|
(set_y(upper_left, mid+2), set_y(bottom_right, mid+2)));
|
|
|
|
|
grid,
|
|
|
|
|
Color::Byte(33),
|
|
|
|
|
Color::Default,
|
|
|
|
|
(set_y(upper_left, mid+2), set_y(bottom_right, mid+2)));
|
|
|
|
|
for x in x..=get_x(bottom_right) {
|
|
|
|
|
grid[(x, mid+2)].set_ch(' ');
|
|
|
|
|
grid[(x, mid+2)].set_bg(Color::Default);
|
|
|
|
|
grid[(x, mid+2)].set_fg(Color::Default);
|
|
|
|
|
}
|
|
|
|
|
let x = write_string_to_grid(&format!("To: {}", mail.get_to()),
|
|
|
|
|
grid,
|
|
|
|
|
Color::Byte(33),
|
|
|
|
|
Color::Default,
|
|
|
|
|
(set_y(upper_left, mid+3), set_y(bottom_right, mid+3)));
|
|
|
|
|
grid,
|
|
|
|
|
Color::Byte(33),
|
|
|
|
|
Color::Default,
|
|
|
|
|
(set_y(upper_left, mid+3), set_y(bottom_right, mid+3)));
|
|
|
|
|
for x in x..=get_x(bottom_right) {
|
|
|
|
|
grid[(x, mid+3)].set_ch(' ');
|
|
|
|
|
grid[(x, mid+3)].set_bg(Color::Default);
|
|
|
|
|
grid[(x, mid+3)].set_fg(Color::Default);
|
|
|
|
|
}
|
|
|
|
|
let x = write_string_to_grid(&format!("Subject: {}", mail.get_subject()),
|
|
|
|
|
grid,
|
|
|
|
|
Color::Byte(33),
|
|
|
|
|
Color::Default,
|
|
|
|
|
(set_y(upper_left, mid+4), set_y(bottom_right, mid+4)));
|
|
|
|
|
grid,
|
|
|
|
|
Color::Byte(33),
|
|
|
|
|
Color::Default,
|
|
|
|
|
(set_y(upper_left, mid+4), set_y(bottom_right, mid+4)));
|
|
|
|
|
for x in x..=get_x(bottom_right) {
|
|
|
|
|
grid[(x, mid+4)].set_ch(' ');
|
|
|
|
|
grid[(x, mid+4)].set_bg(Color::Default);
|
|
|
|
|
grid[(x, mid+4)].set_fg(Color::Default);
|
|
|
|
|
}
|
|
|
|
|
let x = write_string_to_grid(&format!("Message-ID: {}", mail.get_message_id_raw()),
|
|
|
|
|
grid,
|
|
|
|
|
Color::Byte(33),
|
|
|
|
|
Color::Default,
|
|
|
|
|
(set_y(upper_left, mid+5), set_y(bottom_right, mid+5)));
|
|
|
|
|
grid,
|
|
|
|
|
Color::Byte(33),
|
|
|
|
|
Color::Default,
|
|
|
|
|
(set_y(upper_left, mid+5), set_y(bottom_right, mid+5)));
|
|
|
|
|
for x in x..=get_x(bottom_right) {
|
|
|
|
|
grid[(x, mid+5)].set_ch(' ');
|
|
|
|
|
grid[(x, mid+5)].set_bg(Color::Default);
|
|
|
|
@ -341,44 +340,53 @@ impl Component for MailListing {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
|
pub struct AccountMenu {
|
|
|
|
|
struct AccountMenuEntry {
|
|
|
|
|
name: String,
|
|
|
|
|
index: usize,
|
|
|
|
|
entries: Vec<(usize, Folder)>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
|
pub struct AccountMenu {
|
|
|
|
|
accounts: Vec<AccountMenuEntry>,
|
|
|
|
|
dirty: bool,
|
|
|
|
|
name: String,
|
|
|
|
|
cursor: Option<String>,
|
|
|
|
|
cursor: Option<(usize, usize)>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl AccountMenu {
|
|
|
|
|
pub fn new(account: &Account) -> Self{
|
|
|
|
|
let mut entries = Vec::with_capacity(account.len());
|
|
|
|
|
for (idx, acc) in account.list_folders().iter().enumerate() {
|
|
|
|
|
entries.push((idx, acc.clone()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn new(accounts: &Vec<Account>) -> Self {
|
|
|
|
|
let mut accounts = accounts.iter().enumerate().map(|(i, a)| {
|
|
|
|
|
AccountMenuEntry {
|
|
|
|
|
name: a.get_name().to_string(),
|
|
|
|
|
index: i,
|
|
|
|
|
entries: {
|
|
|
|
|
let mut entries = Vec::with_capacity(a.len());
|
|
|
|
|
for (idx, acc) in a.list_folders().iter().enumerate() {
|
|
|
|
|
entries.push((idx, acc.clone()));
|
|
|
|
|
}
|
|
|
|
|
entries}
|
|
|
|
|
}
|
|
|
|
|
}).collect();
|
|
|
|
|
AccountMenu {
|
|
|
|
|
entries: entries,
|
|
|
|
|
accounts: accounts,
|
|
|
|
|
dirty: true,
|
|
|
|
|
name: account.get_name().to_string(),
|
|
|
|
|
cursor: None,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fn highlight_folder(&mut self, m: &Mailbox) {
|
|
|
|
|
self.dirty = true;
|
|
|
|
|
self.cursor = Some(m.folder.get_name().to_string());
|
|
|
|
|
self.cursor = None;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Component for AccountMenu {
|
|
|
|
|
fn draw(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) {
|
|
|
|
|
if !(self.dirty) {
|
|
|
|
|
return;
|
|
|
|
|
fn print_account(&self, grid: &mut CellBuffer, area: Area, a: &AccountMenuEntry) -> usize {
|
|
|
|
|
if !is_valid_area!(area) {
|
|
|
|
|
eprintln!("BUG: invalid area in print_account");
|
|
|
|
|
}
|
|
|
|
|
let upper_left = upper_left!(area);
|
|
|
|
|
let bottom_right = bottom_right!(area);
|
|
|
|
|
self.dirty = false;
|
|
|
|
|
let mut parents: Vec<Option<usize>> = vec!(None; self.entries.len());
|
|
|
|
|
let mut parents: Vec<Option<usize>> = vec!(None; a.entries.len());
|
|
|
|
|
|
|
|
|
|
for (idx, e) in self.entries.iter().enumerate() {
|
|
|
|
|
for (idx, e) in a.entries.iter().enumerate() {
|
|
|
|
|
for c in e.1.get_children() {
|
|
|
|
|
parents[*c] = Some(idx);
|
|
|
|
|
}
|
|
|
|
@ -392,7 +400,7 @@ impl Component for AccountMenu {
|
|
|
|
|
|
|
|
|
|
let mut ind = 0;
|
|
|
|
|
let mut depth = String::from(" ");
|
|
|
|
|
let mut s = String::from(format!("\n\n {}\n", self.name));
|
|
|
|
|
let mut s = String::from(format!("\n\n {}\n", a.name));
|
|
|
|
|
fn pop(depth: &mut String) {
|
|
|
|
|
depth.pop();
|
|
|
|
|
depth.pop();
|
|
|
|
@ -407,7 +415,7 @@ impl Component for AccountMenu {
|
|
|
|
|
depth.push(' ');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn print(root: usize, parents: &Vec<Option<usize>>, depth: &mut String, entries: &Vec<(usize, Folder)>, mut s: String) -> String {
|
|
|
|
|
fn print(root: usize, parents: &Vec<Option<usize>>, depth: &mut String, entries: &Vec<(usize, Folder)>, s: &mut String) -> () {
|
|
|
|
|
let len = s.len();
|
|
|
|
|
s.insert_str(len, &format!("{}: {}\n ", entries[root].0, &entries[root].1.get_name()));
|
|
|
|
|
let children_no = entries[root].1.get_children().len();
|
|
|
|
@ -415,13 +423,12 @@ impl Component for AccountMenu {
|
|
|
|
|
let len = s.len();
|
|
|
|
|
s.insert_str(len, &format!("{}├─", depth));
|
|
|
|
|
push(depth, if idx == children_no - 1 {'│'} else { ' ' });
|
|
|
|
|
s = print(*child, parents, depth, entries, s);
|
|
|
|
|
print(*child, parents, depth, entries, s);
|
|
|
|
|
pop(depth);
|
|
|
|
|
}
|
|
|
|
|
s
|
|
|
|
|
}
|
|
|
|
|
for r in roots {
|
|
|
|
|
s =print(r, &parents, &mut depth, &self.entries, s);
|
|
|
|
|
print(r, &parents, &mut depth, &a.entries, &mut s);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -444,6 +451,27 @@ impl Component for AccountMenu {
|
|
|
|
|
(set_y(upper_left, y), bottom_right));
|
|
|
|
|
idx += 1;
|
|
|
|
|
}
|
|
|
|
|
idx
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Component for AccountMenu {
|
|
|
|
|
fn draw(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) {
|
|
|
|
|
if !(self.dirty) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
let upper_left = upper_left!(area);
|
|
|
|
|
let bottom_right = bottom_right!(area);
|
|
|
|
|
self.dirty = false;
|
|
|
|
|
let mut y = get_y(upper_left);
|
|
|
|
|
for a in &self.accounts {
|
|
|
|
|
y += self.print_account(grid,
|
|
|
|
|
(set_y(upper_left, y), bottom_right),
|
|
|
|
|
&a);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context.dirty_areas.push_back(area);
|
|
|
|
|
}
|
|
|
|
|
fn process_event(&mut self, event: &UIEvent, _context: &mut Context) {
|
|
|
|
|