2018-08-07 15:01:15 +03:00
|
|
|
/*
|
|
|
|
* meli - ui crate.
|
|
|
|
*
|
|
|
|
* Copyright 2017-2018 Manos Pitsidianakis
|
|
|
|
*
|
|
|
|
* This file is part of meli.
|
|
|
|
*
|
|
|
|
* meli is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* meli is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with meli. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2018-07-20 12:15:06 +03:00
|
|
|
use super::*;
|
2018-08-03 13:46:08 +03:00
|
|
|
|
2019-09-14 12:43:19 +03:00
|
|
|
mod conversations;
|
|
|
|
pub use self::conversations::*;
|
|
|
|
|
2018-08-11 18:00:21 +03:00
|
|
|
mod compact;
|
|
|
|
pub use self::compact::*;
|
|
|
|
|
2018-09-07 09:44:37 +03:00
|
|
|
mod thread;
|
|
|
|
pub use self::thread::*;
|
2018-07-11 17:07:51 +03:00
|
|
|
|
2018-09-07 09:44:37 +03:00
|
|
|
mod plain;
|
|
|
|
pub use self::plain::*;
|
2018-07-11 17:07:51 +03:00
|
|
|
|
2019-06-21 12:02:11 +03:00
|
|
|
#[derive(Debug, Default, Clone)]
|
2019-10-20 11:14:29 +03:00
|
|
|
pub struct DataColumns {
|
|
|
|
pub columns: [CellBuffer; 12],
|
|
|
|
pub widths: [usize; 12], // widths of columns calculated in first draw and after size changes
|
2019-06-21 12:02:11 +03:00
|
|
|
}
|
|
|
|
|
2019-04-29 01:48:50 +03:00
|
|
|
#[derive(Debug)]
|
|
|
|
struct AccountMenuEntry {
|
|
|
|
name: String,
|
|
|
|
// Index in the config account vector.
|
|
|
|
index: usize,
|
|
|
|
}
|
2019-06-22 16:13:40 +03:00
|
|
|
#[derive(Debug, Default, Clone)]
|
|
|
|
pub(in crate::listing) struct CachedSearchStrings {
|
|
|
|
subject: String,
|
|
|
|
from: String,
|
|
|
|
body: String,
|
|
|
|
}
|
2019-04-29 01:48:50 +03:00
|
|
|
|
2019-10-20 11:14:29 +03:00
|
|
|
pub trait ListingTrait {
|
2019-04-03 16:58:42 +03:00
|
|
|
fn coordinates(&self) -> (usize, usize, Option<EnvelopeHash>);
|
2019-06-18 21:13:58 +03:00
|
|
|
fn set_coordinates(&mut self, _: (usize, usize, Option<EnvelopeHash>));
|
2019-06-21 12:02:11 +03:00
|
|
|
fn draw_list(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context);
|
|
|
|
fn highlight_line(&mut self, grid: &mut CellBuffer, area: Area, idx: usize, context: &Context);
|
2019-07-17 20:35:05 +03:00
|
|
|
fn filter(&mut self, _filter_term: &str, _context: &Context) {}
|
2019-10-12 17:41:06 +03:00
|
|
|
fn set_movement(&mut self, mvm: PageMovement);
|
2019-04-03 16:58:42 +03:00
|
|
|
}
|
|
|
|
|
2018-09-07 09:44:37 +03:00
|
|
|
#[derive(Debug)]
|
2019-04-29 01:48:50 +03:00
|
|
|
pub enum ListingComponent {
|
2018-09-07 09:44:37 +03:00
|
|
|
Plain(PlainListing),
|
|
|
|
Threaded(ThreadListing),
|
|
|
|
Compact(CompactListing),
|
2019-09-14 12:43:19 +03:00
|
|
|
Conversations(ConversationsListing),
|
2018-08-07 15:01:15 +03:00
|
|
|
}
|
2019-06-18 21:13:58 +03:00
|
|
|
use crate::ListingComponent::*;
|
2018-08-07 15:01:15 +03:00
|
|
|
|
2019-04-29 01:48:50 +03:00
|
|
|
impl ListingTrait for ListingComponent {
|
|
|
|
fn coordinates(&self) -> (usize, usize, Option<EnvelopeHash>) {
|
|
|
|
match &self {
|
|
|
|
Compact(ref l) => l.coordinates(),
|
|
|
|
Plain(ref l) => l.coordinates(),
|
|
|
|
Threaded(ref l) => l.coordinates(),
|
2019-09-14 12:43:19 +03:00
|
|
|
Conversations(ref l) => l.coordinates(),
|
2019-04-29 01:48:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
fn set_coordinates(&mut self, c: (usize, usize, Option<EnvelopeHash>)) {
|
2018-09-07 09:44:37 +03:00
|
|
|
match self {
|
2019-04-29 01:48:50 +03:00
|
|
|
Compact(ref mut l) => l.set_coordinates(c),
|
|
|
|
Plain(ref mut l) => l.set_coordinates(c),
|
|
|
|
Threaded(ref mut l) => l.set_coordinates(c),
|
2019-09-14 12:43:19 +03:00
|
|
|
Conversations(ref mut l) => l.set_coordinates(c),
|
2018-07-15 15:35:57 +03:00
|
|
|
}
|
|
|
|
}
|
2019-06-21 12:02:11 +03:00
|
|
|
fn draw_list(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) {
|
|
|
|
match self {
|
|
|
|
Compact(ref mut l) => l.draw_list(grid, area, context),
|
|
|
|
Plain(ref mut l) => l.draw_list(grid, area, context),
|
|
|
|
Threaded(ref mut l) => l.draw_list(grid, area, context),
|
2019-09-14 12:43:19 +03:00
|
|
|
Conversations(ref mut l) => l.draw_list(grid, area, context),
|
2019-06-21 12:02:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
fn highlight_line(&mut self, grid: &mut CellBuffer, area: Area, idx: usize, context: &Context) {
|
|
|
|
match self {
|
|
|
|
Compact(ref mut l) => l.highlight_line(grid, area, idx, context),
|
|
|
|
Plain(ref mut l) => l.highlight_line(grid, area, idx, context),
|
|
|
|
Threaded(ref mut l) => l.highlight_line(grid, area, idx, context),
|
2019-09-14 12:43:19 +03:00
|
|
|
Conversations(ref mut l) => l.highlight_line(grid, area, idx, context),
|
2019-06-21 12:02:11 +03:00
|
|
|
}
|
|
|
|
}
|
2019-10-12 17:41:06 +03:00
|
|
|
fn set_movement(&mut self, mvm: PageMovement) {
|
|
|
|
match self {
|
|
|
|
Compact(ref mut l) => l.set_movement(mvm),
|
|
|
|
Plain(ref mut l) => l.set_movement(mvm),
|
|
|
|
Threaded(ref mut l) => l.set_movement(mvm),
|
|
|
|
Conversations(ref mut l) => l.set_movement(mvm),
|
|
|
|
}
|
|
|
|
}
|
2018-09-07 09:44:37 +03:00
|
|
|
}
|
2018-08-06 11:05:09 +03:00
|
|
|
|
2019-09-09 21:38:37 +03:00
|
|
|
impl ListingComponent {
|
|
|
|
fn set_style(&mut self, new_style: IndexStyle) {
|
|
|
|
match new_style {
|
|
|
|
IndexStyle::Plain => {
|
|
|
|
if let Plain(_) = self {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let mut new_l = PlainListing::default();
|
|
|
|
let coors = self.coordinates();
|
|
|
|
new_l.set_coordinates((coors.0, coors.1, None));
|
|
|
|
*self = Plain(new_l);
|
|
|
|
}
|
|
|
|
IndexStyle::Threaded => {
|
|
|
|
if let Threaded(_) = self {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let mut new_l = ThreadListing::default();
|
|
|
|
let coors = self.coordinates();
|
|
|
|
new_l.set_coordinates((coors.0, coors.1, None));
|
|
|
|
*self = Threaded(new_l);
|
|
|
|
}
|
|
|
|
IndexStyle::Compact => {
|
|
|
|
if let Compact(_) = self {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let mut new_l = CompactListing::default();
|
|
|
|
let coors = self.coordinates();
|
|
|
|
new_l.set_coordinates((coors.0, coors.1, None));
|
|
|
|
*self = Compact(new_l);
|
|
|
|
}
|
2019-09-14 12:43:19 +03:00
|
|
|
IndexStyle::Conversations => {
|
|
|
|
if let Conversations(_) = self {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let mut new_l = ConversationsListing::default();
|
|
|
|
let coors = self.coordinates();
|
|
|
|
new_l.set_coordinates((coors.0, coors.1, None));
|
|
|
|
*self = Conversations(new_l);
|
|
|
|
}
|
2019-09-09 21:38:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-29 01:48:50 +03:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Listing {
|
|
|
|
component: ListingComponent,
|
|
|
|
accounts: Vec<AccountMenuEntry>,
|
|
|
|
dirty: bool,
|
|
|
|
visible: bool,
|
2019-04-29 10:54:40 +03:00
|
|
|
cursor_pos: (usize, usize),
|
2019-04-29 01:48:50 +03:00
|
|
|
id: ComponentId,
|
|
|
|
|
|
|
|
show_divider: bool,
|
|
|
|
menu_visibility: bool,
|
|
|
|
/// This is the width of the right container to the entire width.
|
|
|
|
ratio: usize, // right/(container width) * 100
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for Listing {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
match self.component {
|
|
|
|
Compact(ref l) => write!(f, "{}", l),
|
|
|
|
Plain(ref l) => write!(f, "{}", l),
|
|
|
|
Threaded(ref l) => write!(f, "{}", l),
|
2019-09-14 12:43:19 +03:00
|
|
|
Conversations(ref l) => write!(f, "{}", l),
|
2019-04-29 01:48:50 +03:00
|
|
|
}
|
2018-07-22 11:14:23 +03:00
|
|
|
}
|
2018-07-11 17:07:51 +03:00
|
|
|
}
|
|
|
|
|
2018-09-07 09:44:37 +03:00
|
|
|
impl Component for Listing {
|
2018-07-14 15:04:42 +03:00
|
|
|
fn draw(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) {
|
2019-10-24 20:30:17 +03:00
|
|
|
for a in context.accounts.iter_mut() {
|
|
|
|
a.is_online();
|
|
|
|
}
|
|
|
|
|
2019-04-29 01:48:50 +03:00
|
|
|
if !self.is_dirty() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if !is_valid_area!(area) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let upper_left = upper_left!(area);
|
|
|
|
let bottom_right = bottom_right!(area);
|
|
|
|
let total_cols = get_x(bottom_right) - get_x(upper_left);
|
|
|
|
|
2019-05-13 22:05:00 +03:00
|
|
|
let right_component_width = if self.menu_visibility {
|
|
|
|
(self.ratio * total_cols) / 100
|
|
|
|
} else {
|
|
|
|
total_cols
|
2019-04-29 01:48:50 +03:00
|
|
|
};
|
|
|
|
let mid = get_x(bottom_right) - right_component_width;
|
2019-05-07 01:56:07 +03:00
|
|
|
if self.dirty && mid != get_x(upper_left) {
|
|
|
|
if self.show_divider {
|
|
|
|
for i in get_y(upper_left)..=get_y(bottom_right) {
|
|
|
|
grid[(mid, i)].set_ch(VERT_BOUNDARY);
|
|
|
|
grid[(mid, i)].set_fg(Color::Default);
|
|
|
|
grid[(mid, i)].set_bg(Color::Default);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for i in get_y(upper_left)..=get_y(bottom_right) {
|
|
|
|
grid[(mid, i)].set_fg(Color::Default);
|
|
|
|
grid[(mid, i)].set_bg(Color::Default);
|
|
|
|
}
|
2019-04-29 01:48:50 +03:00
|
|
|
}
|
|
|
|
context
|
|
|
|
.dirty_areas
|
|
|
|
.push_back(((mid, get_y(upper_left)), (mid, get_y(bottom_right))));
|
|
|
|
}
|
2019-06-21 12:02:11 +03:00
|
|
|
self.dirty = false;
|
2019-10-24 20:30:17 +03:00
|
|
|
|
2019-04-29 01:48:50 +03:00
|
|
|
if right_component_width == total_cols {
|
2019-10-24 20:30:17 +03:00
|
|
|
if !context.accounts[self.cursor_pos.0].is_online() {
|
|
|
|
clear_area(grid, area);
|
|
|
|
write_string_to_grid(
|
|
|
|
"offline",
|
|
|
|
grid,
|
|
|
|
Color::Byte(243),
|
|
|
|
Color::Default,
|
|
|
|
Attr::Default,
|
|
|
|
area,
|
|
|
|
false,
|
|
|
|
);
|
|
|
|
context.dirty_areas.push_back(area);
|
|
|
|
return;
|
|
|
|
}
|
2019-04-29 01:48:50 +03:00
|
|
|
match self.component {
|
|
|
|
Compact(ref mut l) => l.draw(grid, area, context),
|
|
|
|
Plain(ref mut l) => l.draw(grid, area, context),
|
|
|
|
Threaded(ref mut l) => l.draw(grid, area, context),
|
2019-09-14 12:43:19 +03:00
|
|
|
Conversations(ref mut l) => l.draw(grid, area, context),
|
2019-04-29 01:48:50 +03:00
|
|
|
}
|
|
|
|
} else if right_component_width == 0 {
|
|
|
|
self.draw_menu(grid, area, context);
|
|
|
|
} else {
|
|
|
|
self.draw_menu(grid, (upper_left, (mid, get_y(bottom_right))), context);
|
2019-10-24 20:30:17 +03:00
|
|
|
if !context.accounts[self.cursor_pos.0].is_online() {
|
|
|
|
clear_area(grid, (set_x(upper_left, mid + 1), bottom_right));
|
|
|
|
write_string_to_grid(
|
|
|
|
"offline",
|
|
|
|
grid,
|
|
|
|
Color::Byte(243),
|
|
|
|
Color::Default,
|
|
|
|
Attr::Default,
|
|
|
|
(set_x(upper_left, mid + 1), bottom_right),
|
|
|
|
false,
|
|
|
|
);
|
|
|
|
context.dirty_areas.push_back(area);
|
|
|
|
return;
|
|
|
|
}
|
2019-04-29 01:48:50 +03:00
|
|
|
match self.component {
|
|
|
|
Compact(ref mut l) => {
|
|
|
|
l.draw(grid, (set_x(upper_left, mid + 1), bottom_right), context)
|
|
|
|
}
|
|
|
|
Plain(ref mut l) => {
|
|
|
|
l.draw(grid, (set_x(upper_left, mid + 1), bottom_right), context)
|
|
|
|
}
|
|
|
|
Threaded(ref mut l) => {
|
|
|
|
l.draw(grid, (set_x(upper_left, mid + 1), bottom_right), context)
|
|
|
|
}
|
2019-09-14 12:43:19 +03:00
|
|
|
Conversations(ref mut l) => {
|
|
|
|
l.draw(grid, (set_x(upper_left, mid + 1), bottom_right), context)
|
|
|
|
}
|
2019-04-29 01:48:50 +03:00
|
|
|
}
|
2018-07-11 17:07:51 +03:00
|
|
|
}
|
|
|
|
}
|
2019-02-26 17:50:47 +02:00
|
|
|
fn process_event(&mut self, event: &mut UIEvent, context: &mut Context) -> bool {
|
2019-04-29 01:48:50 +03:00
|
|
|
if match self.component {
|
|
|
|
Plain(ref mut l) => l.process_event(event, context),
|
|
|
|
Compact(ref mut l) => l.process_event(event, context),
|
|
|
|
Threaded(ref mut l) => l.process_event(event, context),
|
2019-09-14 12:43:19 +03:00
|
|
|
Conversations(ref mut l) => l.process_event(event, context),
|
2018-09-07 09:44:37 +03:00
|
|
|
} {
|
|
|
|
return true;
|
2018-08-23 14:39:54 +03:00
|
|
|
}
|
2018-09-07 09:44:37 +03:00
|
|
|
|
2019-05-10 22:00:56 +03:00
|
|
|
let shortcuts = &self.get_shortcuts(context)[Listing::DESCRIPTION];
|
2019-04-10 23:37:20 +03:00
|
|
|
match *event {
|
2019-04-29 10:54:40 +03:00
|
|
|
UIEvent::Input(ref k)
|
|
|
|
if k == shortcuts["next_folder"] || k == shortcuts["prev_folder"] =>
|
|
|
|
{
|
|
|
|
let folder_length = context.accounts[self.cursor_pos.0].len();
|
2019-04-29 01:48:50 +03:00
|
|
|
match k {
|
2019-04-29 10:54:40 +03:00
|
|
|
k if k == shortcuts["next_folder"] && folder_length > 0 => {
|
|
|
|
if self.cursor_pos.1 < folder_length - 1 {
|
|
|
|
self.cursor_pos.1 += 1;
|
|
|
|
self.component.set_coordinates((
|
|
|
|
self.cursor_pos.0,
|
|
|
|
self.cursor_pos.1,
|
|
|
|
None,
|
|
|
|
));
|
2019-04-29 01:48:50 +03:00
|
|
|
self.set_dirty();
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2019-04-29 10:54:40 +03:00
|
|
|
k if k == shortcuts["prev_folder"] => {
|
|
|
|
if self.cursor_pos.1 > 0 {
|
|
|
|
self.cursor_pos.1 -= 1;
|
|
|
|
self.component.set_coordinates((
|
|
|
|
self.cursor_pos.0,
|
|
|
|
self.cursor_pos.1,
|
|
|
|
None,
|
|
|
|
));
|
2019-04-29 01:48:50 +03:00
|
|
|
self.set_dirty();
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => return false,
|
|
|
|
}
|
2019-04-29 10:54:40 +03:00
|
|
|
let folder_hash =
|
|
|
|
context.accounts[self.cursor_pos.0].folders_order[self.cursor_pos.1];
|
2019-09-09 21:38:37 +03:00
|
|
|
/* Check if per-folder configuration overrides general configuration */
|
|
|
|
if let Some(index_style) = context
|
|
|
|
.accounts
|
|
|
|
.get(self.cursor_pos.0)
|
2019-09-16 14:09:08 +03:00
|
|
|
.and_then(|account| account.folder_confs(folder_hash).conf_override.index_style)
|
2019-09-09 21:38:37 +03:00
|
|
|
{
|
|
|
|
self.component.set_style(index_style);
|
2019-09-20 09:15:13 +03:00
|
|
|
} else if let Some(index_style) = context
|
|
|
|
.accounts
|
|
|
|
.get(self.cursor_pos.0)
|
|
|
|
.and_then(|account| Some(account.settings.conf.index_style()))
|
|
|
|
{
|
|
|
|
self.component.set_style(index_style);
|
|
|
|
}
|
2019-09-15 09:41:52 +03:00
|
|
|
context
|
|
|
|
.replies
|
|
|
|
.push_back(UIEvent::StatusEvent(StatusEvent::UpdateStatus(
|
|
|
|
self.get_status(context).unwrap(),
|
|
|
|
)));
|
2019-04-29 01:48:50 +03:00
|
|
|
return true;
|
|
|
|
}
|
2019-04-29 10:54:40 +03:00
|
|
|
UIEvent::Input(ref k)
|
|
|
|
if k == shortcuts["next_account"] || k == shortcuts["prev_account"] =>
|
|
|
|
{
|
2019-04-29 01:48:50 +03:00
|
|
|
match k {
|
2019-04-29 10:54:40 +03:00
|
|
|
k if k == shortcuts["next_account"] => {
|
|
|
|
if self.cursor_pos.0 < self.accounts.len() - 1 {
|
|
|
|
self.cursor_pos = (self.cursor_pos.0 + 1, 0);
|
|
|
|
self.component.set_coordinates((self.cursor_pos.0, 0, None));
|
2019-04-29 01:48:50 +03:00
|
|
|
self.set_dirty();
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2019-04-29 10:54:40 +03:00
|
|
|
k if k == shortcuts["prev_account"] => {
|
|
|
|
if self.cursor_pos.0 > 0 {
|
|
|
|
self.cursor_pos = (self.cursor_pos.0 - 1, 0);
|
|
|
|
self.component.set_coordinates((self.cursor_pos.0, 0, None));
|
2019-04-29 01:48:50 +03:00
|
|
|
self.set_dirty();
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => return false,
|
|
|
|
}
|
2019-10-24 20:30:17 +03:00
|
|
|
|
|
|
|
/* Account might have no folders yet if it's offline */
|
|
|
|
if let Some(&folder_hash) = context.accounts[self.cursor_pos.0]
|
|
|
|
.folders_order
|
|
|
|
.get(self.cursor_pos.1)
|
2019-09-20 09:15:13 +03:00
|
|
|
{
|
2019-10-24 20:30:17 +03:00
|
|
|
/* Check if per-folder configuration overrides general configuration */
|
|
|
|
if let Some(index_style) =
|
|
|
|
context.accounts.get(self.cursor_pos.0).and_then(|account| {
|
|
|
|
account.folder_confs(folder_hash).conf_override.index_style
|
|
|
|
})
|
|
|
|
{
|
|
|
|
self.component.set_style(index_style);
|
|
|
|
} else if let Some(index_style) = context
|
|
|
|
.accounts
|
|
|
|
.get(self.cursor_pos.0)
|
|
|
|
.and_then(|account| Some(account.settings.conf.index_style()))
|
|
|
|
{
|
|
|
|
self.component.set_style(index_style);
|
|
|
|
}
|
2019-09-20 09:15:13 +03:00
|
|
|
}
|
2019-09-15 09:41:52 +03:00
|
|
|
context
|
|
|
|
.replies
|
|
|
|
.push_back(UIEvent::StatusEvent(StatusEvent::UpdateStatus(
|
|
|
|
self.get_status(context).unwrap(),
|
|
|
|
)));
|
2019-04-29 01:48:50 +03:00
|
|
|
return true;
|
|
|
|
}
|
2019-04-10 23:37:20 +03:00
|
|
|
UIEvent::Action(ref action) => match action {
|
2018-09-07 09:44:37 +03:00
|
|
|
Action::Listing(ListingAction::SetPlain) => {
|
2019-09-09 21:38:37 +03:00
|
|
|
self.component.set_style(IndexStyle::Plain);
|
2018-08-23 14:39:54 +03:00
|
|
|
return true;
|
2018-08-07 15:01:15 +03:00
|
|
|
}
|
2018-09-07 09:44:37 +03:00
|
|
|
Action::Listing(ListingAction::SetThreaded) => {
|
2019-09-09 21:38:37 +03:00
|
|
|
self.component.set_style(IndexStyle::Threaded);
|
2018-08-23 14:39:54 +03:00
|
|
|
return true;
|
2018-08-14 17:36:45 +03:00
|
|
|
}
|
2018-09-07 09:44:37 +03:00
|
|
|
Action::Listing(ListingAction::SetCompact) => {
|
2019-09-09 21:38:37 +03:00
|
|
|
self.component.set_style(IndexStyle::Compact);
|
2018-08-23 14:39:54 +03:00
|
|
|
return true;
|
2018-09-04 01:49:29 +03:00
|
|
|
}
|
2019-09-14 12:43:19 +03:00
|
|
|
Action::Listing(ListingAction::SetConversations) => {
|
|
|
|
self.component.set_style(IndexStyle::Conversations);
|
|
|
|
return true;
|
|
|
|
}
|
2018-09-04 01:49:29 +03:00
|
|
|
_ => {}
|
2018-07-22 14:05:41 +03:00
|
|
|
},
|
2019-04-29 01:48:50 +03:00
|
|
|
UIEvent::RefreshMailbox((idxa, folder_hash)) => {
|
2019-04-29 10:54:40 +03:00
|
|
|
self.cursor_pos = (
|
2019-04-29 01:48:50 +03:00
|
|
|
idxa,
|
|
|
|
context.accounts[idxa]
|
|
|
|
.folders_order
|
|
|
|
.iter()
|
|
|
|
.position(|&h| h == folder_hash)
|
|
|
|
.unwrap_or(0),
|
|
|
|
);
|
2019-09-15 09:41:52 +03:00
|
|
|
context
|
|
|
|
.replies
|
|
|
|
.push_back(UIEvent::StatusEvent(StatusEvent::UpdateStatus(
|
|
|
|
self.get_status(context).unwrap(),
|
|
|
|
)));
|
2019-04-29 01:48:50 +03:00
|
|
|
self.dirty = true;
|
|
|
|
}
|
|
|
|
UIEvent::ChangeMode(UIMode::Normal) => {
|
|
|
|
self.dirty = true;
|
|
|
|
}
|
|
|
|
UIEvent::Resize => {
|
|
|
|
self.dirty = true;
|
|
|
|
}
|
2019-10-12 17:41:06 +03:00
|
|
|
UIEvent::Input(ref key) if *key == shortcuts["prev_page"] => {
|
|
|
|
self.component.set_movement(PageMovement::PageUp);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
UIEvent::Input(ref key) if *key == shortcuts["next_page"] => {
|
|
|
|
self.component.set_movement(PageMovement::PageDown);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
UIEvent::Input(ref key) if *key == Key::Home => {
|
|
|
|
self.component.set_movement(PageMovement::Home);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
UIEvent::Input(ref key) if *key == Key::End => {
|
|
|
|
self.component.set_movement(PageMovement::End);
|
|
|
|
return true;
|
|
|
|
}
|
2019-10-12 17:47:36 +03:00
|
|
|
UIEvent::Input(ref k) if k == shortcuts["toggle_menu_visibility"] => {
|
2019-04-29 01:48:50 +03:00
|
|
|
self.menu_visibility = !self.menu_visibility;
|
|
|
|
self.set_dirty();
|
|
|
|
}
|
2019-04-29 10:54:40 +03:00
|
|
|
UIEvent::Input(ref k) if k == shortcuts["new_mail"] => {
|
|
|
|
context
|
|
|
|
.replies
|
2019-06-18 22:13:54 +03:00
|
|
|
.push_back(UIEvent::Action(Tab(NewDraft(self.cursor_pos.0, None))));
|
2019-04-29 10:54:40 +03:00
|
|
|
return true;
|
|
|
|
}
|
2019-10-12 17:52:18 +03:00
|
|
|
UIEvent::Input(ref key) if *key == shortcuts["search"] => {
|
|
|
|
context
|
|
|
|
.replies
|
|
|
|
.push_back(UIEvent::ExInput(Key::Paste("filter ".to_string())));
|
|
|
|
context
|
|
|
|
.replies
|
|
|
|
.push_back(UIEvent::ChangeMode(UIMode::Execute));
|
|
|
|
return true;
|
|
|
|
}
|
2019-10-12 17:47:36 +03:00
|
|
|
UIEvent::Input(ref key) if *key == shortcuts["set_seen"] => {
|
|
|
|
let mut event = UIEvent::Action(Action::Listing(ListingAction::SetSeen));
|
|
|
|
if match self.component {
|
|
|
|
Plain(ref mut l) => l.process_event(&mut event, context),
|
|
|
|
Compact(ref mut l) => l.process_event(&mut event, context),
|
|
|
|
Threaded(ref mut l) => l.process_event(&mut event, context),
|
|
|
|
Conversations(ref mut l) => l.process_event(&mut event, context),
|
|
|
|
} {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2019-04-29 01:48:50 +03:00
|
|
|
UIEvent::StartupCheck(_) => {
|
|
|
|
self.dirty = true;
|
2019-09-15 09:41:52 +03:00
|
|
|
context
|
|
|
|
.replies
|
|
|
|
.push_back(UIEvent::StatusEvent(StatusEvent::UpdateStatus(
|
|
|
|
self.get_status(context).unwrap(),
|
|
|
|
)));
|
2019-04-29 01:48:50 +03:00
|
|
|
}
|
|
|
|
UIEvent::MailboxUpdate(_) => {
|
|
|
|
self.dirty = true;
|
2019-09-15 09:41:52 +03:00
|
|
|
context
|
|
|
|
.replies
|
|
|
|
.push_back(UIEvent::StatusEvent(StatusEvent::UpdateStatus(
|
|
|
|
self.get_status(context).unwrap(),
|
|
|
|
)));
|
2019-04-29 01:48:50 +03:00
|
|
|
}
|
2018-07-27 21:37:56 +03:00
|
|
|
_ => {}
|
2018-07-11 17:07:51 +03:00
|
|
|
}
|
2018-08-23 14:39:54 +03:00
|
|
|
false
|
2018-07-11 17:07:51 +03:00
|
|
|
}
|
2018-07-14 15:04:42 +03:00
|
|
|
fn is_dirty(&self) -> bool {
|
2019-04-29 01:48:50 +03:00
|
|
|
self.dirty
|
|
|
|
|| match self.component {
|
|
|
|
Compact(ref l) => l.is_dirty(),
|
|
|
|
Plain(ref l) => l.is_dirty(),
|
|
|
|
Threaded(ref l) => l.is_dirty(),
|
2019-09-14 12:43:19 +03:00
|
|
|
Conversations(ref l) => l.is_dirty(),
|
2019-04-29 01:48:50 +03:00
|
|
|
}
|
2018-07-14 15:04:42 +03:00
|
|
|
}
|
2018-08-11 18:00:21 +03:00
|
|
|
fn set_dirty(&mut self) {
|
2019-04-29 01:48:50 +03:00
|
|
|
self.dirty = true;
|
|
|
|
match self.component {
|
|
|
|
Compact(ref mut l) => l.set_dirty(),
|
|
|
|
Plain(ref mut l) => l.set_dirty(),
|
|
|
|
Threaded(ref mut l) => l.set_dirty(),
|
2019-09-14 12:43:19 +03:00
|
|
|
Conversations(ref mut l) => l.set_dirty(),
|
2018-09-07 09:44:37 +03:00
|
|
|
}
|
2018-08-11 18:00:21 +03:00
|
|
|
}
|
2019-03-02 19:25:11 +02:00
|
|
|
|
2019-05-10 22:00:56 +03:00
|
|
|
fn get_shortcuts(&self, context: &Context) -> ShortcutMaps {
|
2019-04-29 01:48:50 +03:00
|
|
|
let mut map = match self.component {
|
|
|
|
Compact(ref l) => l.get_shortcuts(context),
|
|
|
|
Plain(ref l) => l.get_shortcuts(context),
|
|
|
|
Threaded(ref l) => l.get_shortcuts(context),
|
2019-09-14 12:43:19 +03:00
|
|
|
Conversations(ref l) => l.get_shortcuts(context),
|
2019-04-29 01:48:50 +03:00
|
|
|
};
|
2019-04-29 10:54:40 +03:00
|
|
|
let config_map = context.settings.shortcuts.listing.key_values();
|
|
|
|
map.insert(
|
2019-05-10 22:00:56 +03:00
|
|
|
Listing::DESCRIPTION.to_string(),
|
2019-10-12 17:47:36 +03:00
|
|
|
config_map
|
|
|
|
.into_iter()
|
|
|
|
.map(|(k, v)| (k, v.clone()))
|
|
|
|
.collect(),
|
2019-04-29 10:54:40 +03:00
|
|
|
);
|
2019-04-29 01:48:50 +03:00
|
|
|
|
|
|
|
map
|
2019-03-02 19:25:11 +02:00
|
|
|
}
|
2019-04-10 22:01:02 +03:00
|
|
|
|
|
|
|
fn id(&self) -> ComponentId {
|
2019-04-29 01:48:50 +03:00
|
|
|
match self.component {
|
|
|
|
Compact(ref l) => l.id(),
|
|
|
|
Plain(ref l) => l.id(),
|
|
|
|
Threaded(ref l) => l.id(),
|
2019-09-14 12:43:19 +03:00
|
|
|
Conversations(ref l) => l.id(),
|
2019-04-10 22:01:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
fn set_id(&mut self, id: ComponentId) {
|
2019-04-29 01:48:50 +03:00
|
|
|
match self.component {
|
|
|
|
Compact(ref mut l) => l.set_id(id),
|
|
|
|
Plain(ref mut l) => l.set_id(id),
|
|
|
|
Threaded(ref mut l) => l.set_id(id),
|
2019-09-14 12:43:19 +03:00
|
|
|
Conversations(ref mut l) => l.set_id(id),
|
2019-04-10 22:01:02 +03:00
|
|
|
}
|
|
|
|
}
|
2019-09-15 09:41:52 +03:00
|
|
|
|
|
|
|
fn get_status(&self, context: &Context) -> Option<String> {
|
|
|
|
Some({
|
|
|
|
let folder_hash = if let Some(h) = context.accounts[self.cursor_pos.0]
|
|
|
|
.folders_order
|
|
|
|
.get(self.cursor_pos.1)
|
|
|
|
{
|
|
|
|
*h
|
|
|
|
} else {
|
|
|
|
return Some(String::new());
|
|
|
|
};
|
|
|
|
if !context.accounts[self.cursor_pos.0].folders[&folder_hash].is_available() {
|
|
|
|
return Some(String::new());
|
|
|
|
}
|
|
|
|
let account = &context.accounts[self.cursor_pos.0];
|
|
|
|
let m = if account[self.cursor_pos.1].is_available() {
|
|
|
|
account[self.cursor_pos.1].unwrap()
|
|
|
|
} else {
|
|
|
|
return Some(String::new());
|
|
|
|
};
|
|
|
|
format!(
|
|
|
|
"Mailbox: {}, Messages: {}, New: {}",
|
|
|
|
m.folder.name(),
|
|
|
|
m.envelopes.len(),
|
|
|
|
m.envelopes
|
|
|
|
.iter()
|
|
|
|
.map(|h| &account.collection[&h])
|
|
|
|
.filter(|e| !e.is_seen())
|
|
|
|
.count()
|
|
|
|
)
|
|
|
|
})
|
|
|
|
}
|
2018-07-11 17:07:51 +03:00
|
|
|
}
|
2019-02-18 23:14:06 +02:00
|
|
|
|
2019-04-29 01:48:50 +03:00
|
|
|
impl From<IndexStyle> for ListingComponent {
|
2019-02-18 23:14:06 +02:00
|
|
|
fn from(index_style: IndexStyle) -> Self {
|
|
|
|
match index_style {
|
2019-04-29 01:48:50 +03:00
|
|
|
IndexStyle::Plain => Plain(Default::default()),
|
|
|
|
IndexStyle::Threaded => Threaded(Default::default()),
|
|
|
|
IndexStyle::Compact => Compact(Default::default()),
|
2019-09-14 12:43:19 +03:00
|
|
|
IndexStyle::Conversations => Conversations(Default::default()),
|
2019-04-29 01:48:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Listing {
|
2019-05-10 22:00:56 +03:00
|
|
|
const DESCRIPTION: &'static str = "listing";
|
2019-04-29 01:48:50 +03:00
|
|
|
pub fn new(accounts: &[Account]) -> Self {
|
2019-09-09 21:38:37 +03:00
|
|
|
let account_entries = accounts
|
2019-04-29 01:48:50 +03:00
|
|
|
.iter()
|
|
|
|
.enumerate()
|
|
|
|
.map(|(i, a)| AccountMenuEntry {
|
|
|
|
name: a.name().to_string(),
|
|
|
|
index: i,
|
|
|
|
})
|
|
|
|
.collect();
|
2019-09-09 21:38:37 +03:00
|
|
|
/* Check if per-folder configuration overrides general configuration */
|
|
|
|
let component = if let Some(index_style) = accounts.get(0).and_then(|account| {
|
2019-09-16 14:09:08 +03:00
|
|
|
account.folders_order.get(0).and_then(|folder_hash| {
|
|
|
|
account.folder_confs(*folder_hash).conf_override.index_style
|
|
|
|
})
|
2019-09-09 21:38:37 +03:00
|
|
|
}) {
|
|
|
|
ListingComponent::from(index_style)
|
2019-09-20 09:15:13 +03:00
|
|
|
} else if let Some(index_style) = accounts
|
|
|
|
.get(0)
|
|
|
|
.and_then(|account| Some(account.settings.conf.index_style()))
|
|
|
|
{
|
|
|
|
ListingComponent::from(index_style)
|
2019-09-09 21:38:37 +03:00
|
|
|
} else {
|
2019-09-14 12:43:19 +03:00
|
|
|
Conversations(Default::default())
|
2019-09-09 21:38:37 +03:00
|
|
|
};
|
2019-04-29 01:48:50 +03:00
|
|
|
Listing {
|
2019-09-09 21:38:37 +03:00
|
|
|
component,
|
|
|
|
accounts: account_entries,
|
2019-04-29 01:48:50 +03:00
|
|
|
visible: true,
|
|
|
|
dirty: true,
|
2019-04-29 10:54:40 +03:00
|
|
|
cursor_pos: (0, 0),
|
2019-04-29 01:48:50 +03:00
|
|
|
id: ComponentId::new_v4(),
|
|
|
|
show_divider: false,
|
|
|
|
menu_visibility: true,
|
|
|
|
ratio: 90,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn draw_menu(&mut self, grid: &mut CellBuffer, mut area: Area, context: &mut Context) {
|
|
|
|
if !self.is_dirty() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
clear_area(grid, area);
|
2019-05-07 01:56:07 +03:00
|
|
|
/* visually divide menu and listing */
|
|
|
|
area = (area.0, pos_dec(area.1, (1, 0)));
|
2019-04-29 01:48:50 +03:00
|
|
|
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);
|
2019-08-18 15:46:01 +03:00
|
|
|
y += 3;
|
2019-04-29 01:48:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
context.dirty_areas.push_back(area);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Print a single account in the menu area.
|
|
|
|
*/
|
|
|
|
fn print_account(
|
|
|
|
&self,
|
|
|
|
grid: &mut CellBuffer,
|
|
|
|
area: Area,
|
|
|
|
a: &AccountMenuEntry,
|
|
|
|
context: &mut Context,
|
|
|
|
) -> usize {
|
2019-05-01 19:20:33 +03:00
|
|
|
if !is_valid_area!(area) {
|
|
|
|
debug!("BUG: invalid area in print_account");
|
2019-04-29 01:48:50 +03:00
|
|
|
}
|
|
|
|
// Each entry and its index in the account
|
|
|
|
let entries: FnvHashMap<FolderHash, Folder> = context.accounts[a.index]
|
|
|
|
.list_folders()
|
|
|
|
.into_iter()
|
|
|
|
.map(|f| (f.hash(), f))
|
|
|
|
.collect();
|
|
|
|
let folders_order: FnvHashMap<FolderHash, usize> = context.accounts[a.index]
|
|
|
|
.folders_order()
|
|
|
|
.iter()
|
|
|
|
.enumerate()
|
|
|
|
.map(|(i, &fh)| (fh, i))
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
let upper_left = upper_left!(area);
|
|
|
|
let bottom_right = bottom_right!(area);
|
|
|
|
|
2019-08-18 15:46:01 +03:00
|
|
|
let must_highlight_account: bool = self.cursor_pos.0 == a.index;
|
2019-04-29 01:48:50 +03:00
|
|
|
|
|
|
|
let mut inc = 0;
|
2019-08-18 15:46:01 +03:00
|
|
|
let mut depth = 0;
|
|
|
|
let mut lines: Vec<(usize, usize, FolderHash, Option<usize>)> = Vec::new();
|
2019-04-29 01:48:50 +03:00
|
|
|
|
2019-08-18 15:46:01 +03:00
|
|
|
/* Gather the folder tree structure in `lines` recursively */
|
2019-04-29 01:48:50 +03:00
|
|
|
fn print(
|
|
|
|
folder_idx: FolderHash,
|
2019-08-18 15:46:01 +03:00
|
|
|
depth: &mut usize,
|
2019-04-29 01:48:50 +03:00
|
|
|
inc: &mut usize,
|
|
|
|
entries: &FnvHashMap<FolderHash, Folder>,
|
|
|
|
folders_order: &FnvHashMap<FolderHash, usize>,
|
2019-08-18 15:46:01 +03:00
|
|
|
lines: &mut Vec<(usize, usize, FolderHash, Option<usize>)>,
|
2019-04-29 01:48:50 +03:00
|
|
|
index: usize, //account index
|
|
|
|
context: &mut Context,
|
|
|
|
) {
|
|
|
|
match context.accounts[index].status(entries[&folder_idx].hash()) {
|
|
|
|
Ok(_) => {
|
2019-05-26 02:34:03 +03:00
|
|
|
let account = &context.accounts[index];
|
|
|
|
let count = account[entries[&folder_idx].hash()]
|
2019-04-29 01:48:50 +03:00
|
|
|
.unwrap()
|
2019-05-26 02:34:03 +03:00
|
|
|
.envelopes
|
|
|
|
.iter()
|
2019-07-28 18:52:45 +03:00
|
|
|
.filter_map(|h| {
|
|
|
|
if account.collection[&h].is_seen() {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(())
|
|
|
|
}
|
|
|
|
})
|
2019-04-29 01:48:50 +03:00
|
|
|
.count();
|
2019-08-18 15:46:01 +03:00
|
|
|
lines.push((*depth, *inc, folder_idx, Some(count)));
|
2019-04-29 01:48:50 +03:00
|
|
|
}
|
|
|
|
Err(_) => {
|
2019-08-18 15:46:01 +03:00
|
|
|
lines.push((*depth, *inc, folder_idx, None));
|
2019-04-29 01:48:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
*inc += 1;
|
|
|
|
let mut children: Vec<FolderHash> = entries[&folder_idx].children().to_vec();
|
|
|
|
children
|
|
|
|
.sort_unstable_by(|a, b| folders_order[a].partial_cmp(&folders_order[b]).unwrap());
|
2019-08-18 15:46:01 +03:00
|
|
|
*depth += 1;
|
2019-05-07 21:52:11 +03:00
|
|
|
for child in children {
|
2019-08-18 15:46:01 +03:00
|
|
|
print(
|
|
|
|
child,
|
|
|
|
depth,
|
|
|
|
inc,
|
|
|
|
entries,
|
|
|
|
folders_order,
|
|
|
|
lines,
|
|
|
|
index,
|
|
|
|
context,
|
|
|
|
);
|
2019-04-29 01:48:50 +03:00
|
|
|
}
|
2019-08-18 15:46:01 +03:00
|
|
|
*depth -= 1;
|
2019-04-29 01:48:50 +03:00
|
|
|
}
|
2019-09-06 12:48:17 +03:00
|
|
|
let mut keys = entries.keys().cloned().collect::<Vec<FolderHash>>();
|
|
|
|
keys.sort_unstable_by(|a, b| folders_order[a].partial_cmp(&folders_order[b]).unwrap());
|
2019-08-18 15:46:01 +03:00
|
|
|
|
|
|
|
/* Start with roots */
|
2019-09-06 12:48:17 +03:00
|
|
|
for f in keys {
|
|
|
|
if entries[&f].parent().is_none() {
|
2019-04-29 01:48:50 +03:00
|
|
|
print(
|
2019-09-06 12:48:17 +03:00
|
|
|
f,
|
2019-04-29 01:48:50 +03:00
|
|
|
&mut depth,
|
|
|
|
&mut inc,
|
|
|
|
&entries,
|
|
|
|
&folders_order,
|
2019-08-18 15:46:01 +03:00
|
|
|
&mut lines,
|
2019-04-29 01:48:50 +03:00
|
|
|
a.index,
|
|
|
|
context,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-18 15:46:01 +03:00
|
|
|
/* Print account name first */
|
|
|
|
write_string_to_grid(
|
|
|
|
&a.name,
|
|
|
|
grid,
|
|
|
|
Color::Default,
|
|
|
|
Color::Default,
|
|
|
|
Attr::Bold,
|
|
|
|
area,
|
|
|
|
false,
|
|
|
|
);
|
|
|
|
|
|
|
|
if lines.is_empty() {
|
2019-10-24 20:30:17 +03:00
|
|
|
write_string_to_grid(
|
|
|
|
"offline",
|
|
|
|
grid,
|
|
|
|
Color::Byte(243),
|
|
|
|
Color::Default,
|
|
|
|
Attr::Default,
|
|
|
|
(pos_inc(upper_left, (0, 1)), bottom_right),
|
|
|
|
false,
|
|
|
|
);
|
2019-04-29 01:48:50 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2019-08-18 15:46:01 +03:00
|
|
|
|
|
|
|
let lines_len = lines.len();
|
2019-04-29 01:48:50 +03:00
|
|
|
let mut idx = 0;
|
2019-08-18 15:46:01 +03:00
|
|
|
|
|
|
|
for y in get_y(upper_left) + 1..get_y(bottom_right) {
|
2019-04-29 01:48:50 +03:00
|
|
|
if idx == lines_len {
|
|
|
|
break;
|
|
|
|
}
|
2019-08-18 15:46:01 +03:00
|
|
|
let (fg_color, bg_color) = if must_highlight_account {
|
|
|
|
if self.cursor_pos.1 == idx {
|
2019-04-29 01:48:50 +03:00
|
|
|
(Color::Byte(233), Color::Byte(15))
|
|
|
|
} else {
|
|
|
|
(Color::Byte(15), Color::Byte(233))
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
(Color::Default, Color::Default)
|
|
|
|
};
|
|
|
|
|
2019-08-18 15:46:01 +03:00
|
|
|
let (depth, inc, folder_idx, count) = lines[idx];
|
|
|
|
/* Calculate how many columns the folder index tags should occupy with right alignment,
|
|
|
|
* eg.
|
|
|
|
* 1
|
|
|
|
* 2
|
|
|
|
* ...
|
|
|
|
* 9
|
|
|
|
* 10
|
|
|
|
*/
|
|
|
|
let total_folder_no_digits = {
|
|
|
|
let mut len = lines_len;
|
|
|
|
let mut ctr = 1;
|
|
|
|
while len > 9 {
|
|
|
|
ctr += 1;
|
|
|
|
len /= 10;
|
|
|
|
}
|
|
|
|
ctr
|
|
|
|
};
|
|
|
|
let (x, _) = write_string_to_grid(
|
|
|
|
&format!("{:>width$}", inc, width = total_folder_no_digits),
|
2019-04-29 01:48:50 +03:00
|
|
|
grid,
|
2019-08-18 15:46:01 +03:00
|
|
|
Color::Byte(243),
|
|
|
|
bg_color,
|
|
|
|
Attr::Default,
|
2019-04-29 01:48:50 +03:00
|
|
|
(set_y(upper_left, y), bottom_right),
|
|
|
|
false,
|
|
|
|
);
|
2019-08-18 15:46:01 +03:00
|
|
|
let (x, _) = write_string_to_grid(
|
|
|
|
&" ".repeat(depth + 1),
|
|
|
|
grid,
|
|
|
|
fg_color,
|
|
|
|
bg_color,
|
|
|
|
Attr::Default,
|
|
|
|
((x, y), bottom_right),
|
|
|
|
false,
|
|
|
|
);
|
|
|
|
let (x, _) = write_string_to_grid(
|
|
|
|
entries[&folder_idx].name(),
|
|
|
|
grid,
|
|
|
|
fg_color,
|
|
|
|
bg_color,
|
|
|
|
Attr::Default,
|
|
|
|
((x, y), bottom_right),
|
|
|
|
false,
|
|
|
|
);
|
|
|
|
|
|
|
|
/* Unread message count */
|
|
|
|
let count_string = if let Some(c) = count {
|
|
|
|
if c > 0 {
|
|
|
|
format!(" {}", c)
|
|
|
|
} else {
|
|
|
|
String::new()
|
2019-04-29 01:48:50 +03:00
|
|
|
}
|
2019-08-18 15:46:01 +03:00
|
|
|
} else {
|
|
|
|
" ...".to_string()
|
|
|
|
};
|
|
|
|
|
|
|
|
let (x, _) = write_string_to_grid(
|
|
|
|
&count_string,
|
|
|
|
grid,
|
|
|
|
fg_color,
|
|
|
|
bg_color,
|
|
|
|
if count.unwrap_or(0) > 0 {
|
|
|
|
Attr::Bold
|
|
|
|
} else {
|
|
|
|
Attr::Default
|
|
|
|
},
|
|
|
|
(
|
|
|
|
(
|
|
|
|
/* Hide part of folder name if need be to fit the message count */
|
|
|
|
std::cmp::min(x, get_x(bottom_right).saturating_sub(count_string.len())),
|
|
|
|
y,
|
|
|
|
),
|
|
|
|
bottom_right,
|
|
|
|
),
|
|
|
|
false,
|
|
|
|
);
|
|
|
|
change_colors(grid, ((x, y), set_y(bottom_right, y)), fg_color, bg_color);
|
2019-04-29 01:48:50 +03:00
|
|
|
idx += 1;
|
|
|
|
}
|
|
|
|
if idx == 0 {
|
|
|
|
0
|
|
|
|
} else {
|
|
|
|
idx - 1
|
2019-02-18 23:14:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|