mail/status: make AccountStatus public
And fix areas passed to write_string_to_grid() to have the same y coordinate in upper_left and bottom_right part.jmap-eventsource
parent
f0800f38a8
commit
da69eecafe
|
@ -314,13 +314,52 @@ impl StatusPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct AccountStatus {
|
||||||
|
cursor: (usize, usize),
|
||||||
|
account_pos: usize,
|
||||||
|
content: CellBuffer,
|
||||||
|
dirty: bool,
|
||||||
|
theme_default: ThemeAttribute,
|
||||||
|
id: ComponentId,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for AccountStatus {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
write!(f, "status")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AccountStatus {
|
||||||
|
pub fn new(account_pos: usize, theme_default: ThemeAttribute) -> AccountStatus {
|
||||||
|
let default_cell = {
|
||||||
|
let mut ret = Cell::with_char(' ');
|
||||||
|
ret.set_fg(theme_default.fg)
|
||||||
|
.set_bg(theme_default.bg)
|
||||||
|
.set_attrs(theme_default.attrs);
|
||||||
|
ret
|
||||||
|
};
|
||||||
|
let mut content = CellBuffer::new(120, 5, default_cell);
|
||||||
|
content.set_growable(true);
|
||||||
|
|
||||||
|
AccountStatus {
|
||||||
|
cursor: (0, 0),
|
||||||
|
account_pos,
|
||||||
|
content,
|
||||||
|
dirty: true,
|
||||||
|
theme_default,
|
||||||
|
id: ComponentId::new_v4(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Component for AccountStatus {
|
impl Component for AccountStatus {
|
||||||
fn draw(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) {
|
fn draw(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) {
|
||||||
if !self.dirty {
|
if !self.dirty {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
self.dirty = false;
|
self.dirty = false;
|
||||||
let (width, height) = self.content.size();
|
let (mut width, height) = self.content.size();
|
||||||
let a = &context.accounts[self.account_pos];
|
let a = &context.accounts[self.account_pos];
|
||||||
let (_x, _y) = write_string_to_grid(
|
let (_x, _y) = write_string_to_grid(
|
||||||
"(Press Esc to return)",
|
"(Press Esc to return)",
|
||||||
|
@ -328,9 +367,10 @@ impl Component for AccountStatus {
|
||||||
self.theme_default.fg,
|
self.theme_default.fg,
|
||||||
self.theme_default.bg,
|
self.theme_default.bg,
|
||||||
Attr::BOLD,
|
Attr::BOLD,
|
||||||
((1, 0), (width - 1, height - 1)),
|
((1, 0), (width - 1, 0)),
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
width = self.content.size().0;
|
||||||
let mut line = 2;
|
let mut line = 2;
|
||||||
|
|
||||||
let (_x, _y) = write_string_to_grid(
|
let (_x, _y) = write_string_to_grid(
|
||||||
|
@ -339,9 +379,10 @@ impl Component for AccountStatus {
|
||||||
self.theme_default.fg,
|
self.theme_default.fg,
|
||||||
self.theme_default.bg,
|
self.theme_default.bg,
|
||||||
Attr::BOLD,
|
Attr::BOLD,
|
||||||
((1, line), (width - 1, height - 1)),
|
((1, line), (width - 1, line)),
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
width = self.content.size().0;
|
||||||
write_string_to_grid(
|
write_string_to_grid(
|
||||||
if a.backend_capabilities.supports_tags {
|
if a.backend_capabilities.supports_tags {
|
||||||
"yes"
|
"yes"
|
||||||
|
@ -352,9 +393,10 @@ impl Component for AccountStatus {
|
||||||
self.theme_default.fg,
|
self.theme_default.fg,
|
||||||
self.theme_default.bg,
|
self.theme_default.bg,
|
||||||
self.theme_default.attrs,
|
self.theme_default.attrs,
|
||||||
((_x, _y), (width - 1, height - 1)),
|
((_x, _y), (width - 1, line)),
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
width = self.content.size().0;
|
||||||
line += 1;
|
line += 1;
|
||||||
let (_x, _y) = write_string_to_grid(
|
let (_x, _y) = write_string_to_grid(
|
||||||
"Search backend: ",
|
"Search backend: ",
|
||||||
|
@ -362,9 +404,10 @@ impl Component for AccountStatus {
|
||||||
self.theme_default.fg,
|
self.theme_default.fg,
|
||||||
self.theme_default.bg,
|
self.theme_default.bg,
|
||||||
Attr::BOLD,
|
Attr::BOLD,
|
||||||
((1, line), (width - 1, height - 1)),
|
((1, line), (width - 1, line)),
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
width = self.content.size().0;
|
||||||
write_string_to_grid(
|
write_string_to_grid(
|
||||||
&match (
|
&match (
|
||||||
a.settings.conf.search_backend(),
|
a.settings.conf.search_backend(),
|
||||||
|
@ -389,9 +432,10 @@ impl Component for AccountStatus {
|
||||||
self.theme_default.fg,
|
self.theme_default.fg,
|
||||||
self.theme_default.bg,
|
self.theme_default.bg,
|
||||||
self.theme_default.attrs,
|
self.theme_default.attrs,
|
||||||
((_x, _y), (width - 1, height - 1)),
|
((_x, _y), (width - 1, _y)),
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
width = self.content.size().0;
|
||||||
line += 1;
|
line += 1;
|
||||||
|
|
||||||
write_string_to_grid(
|
write_string_to_grid(
|
||||||
|
@ -400,15 +444,17 @@ impl Component for AccountStatus {
|
||||||
self.theme_default.fg,
|
self.theme_default.fg,
|
||||||
self.theme_default.bg,
|
self.theme_default.bg,
|
||||||
Attr::BOLD,
|
Attr::BOLD,
|
||||||
((1, line), (width - 1, height - 1)),
|
((1, line), (width - 1, line)),
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
width = self.content.size().0;
|
||||||
for f in a
|
for f in a
|
||||||
.mailbox_entries
|
.mailbox_entries
|
||||||
.values()
|
.values()
|
||||||
.map(|entry| &entry.ref_mailbox)
|
.map(|entry| &entry.ref_mailbox)
|
||||||
.filter(|f| f.special_usage() != SpecialUsageMailbox::Normal)
|
.filter(|f| f.special_usage() != SpecialUsageMailbox::Normal)
|
||||||
{
|
{
|
||||||
|
width = self.content.size().0;
|
||||||
line += 1;
|
line += 1;
|
||||||
write_string_to_grid(
|
write_string_to_grid(
|
||||||
&format!("{}: {}", f.path(), f.special_usage()),
|
&format!("{}: {}", f.path(), f.special_usage()),
|
||||||
|
@ -416,22 +462,25 @@ impl Component for AccountStatus {
|
||||||
self.theme_default.fg,
|
self.theme_default.fg,
|
||||||
self.theme_default.bg,
|
self.theme_default.bg,
|
||||||
self.theme_default.attrs,
|
self.theme_default.attrs,
|
||||||
((1, line), (width - 1, height - 1)),
|
((1, line), (width - 1, line)),
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
line += 2;
|
line += 2;
|
||||||
|
width = self.content.size().0;
|
||||||
write_string_to_grid(
|
write_string_to_grid(
|
||||||
"Subscribed mailboxes:",
|
"Subscribed mailboxes:",
|
||||||
&mut self.content,
|
&mut self.content,
|
||||||
self.theme_default.fg,
|
self.theme_default.fg,
|
||||||
self.theme_default.bg,
|
self.theme_default.bg,
|
||||||
Attr::BOLD,
|
Attr::BOLD,
|
||||||
((1, line), (width - 1, height - 1)),
|
((1, line), (width - 1, line)),
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
width = self.content.size().0;
|
||||||
line += 2;
|
line += 2;
|
||||||
for mailbox_node in a.list_mailboxes() {
|
for mailbox_node in a.list_mailboxes() {
|
||||||
|
width = self.content.size().0;
|
||||||
let f: &Mailbox = &a[&mailbox_node.hash].ref_mailbox;
|
let f: &Mailbox = &a[&mailbox_node.hash].ref_mailbox;
|
||||||
if f.is_subscribed() {
|
if f.is_subscribed() {
|
||||||
write_string_to_grid(
|
write_string_to_grid(
|
||||||
|
@ -440,7 +489,7 @@ impl Component for AccountStatus {
|
||||||
self.theme_default.fg,
|
self.theme_default.fg,
|
||||||
self.theme_default.bg,
|
self.theme_default.bg,
|
||||||
self.theme_default.attrs,
|
self.theme_default.attrs,
|
||||||
((1, line), (width - 1, height - 1)),
|
((1, line), (width - 1, line)),
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
line += 1;
|
line += 1;
|
||||||
|
@ -448,6 +497,7 @@ impl Component for AccountStatus {
|
||||||
}
|
}
|
||||||
|
|
||||||
line += 1;
|
line += 1;
|
||||||
|
width = self.content.size().0;
|
||||||
if let Some(ref extensions) = a.backend_capabilities.extensions {
|
if let Some(ref extensions) = a.backend_capabilities.extensions {
|
||||||
write_string_to_grid(
|
write_string_to_grid(
|
||||||
"Server Extensions:",
|
"Server Extensions:",
|
||||||
|
@ -455,9 +505,10 @@ impl Component for AccountStatus {
|
||||||
self.theme_default.fg,
|
self.theme_default.fg,
|
||||||
self.theme_default.bg,
|
self.theme_default.bg,
|
||||||
Attr::BOLD,
|
Attr::BOLD,
|
||||||
((1, line), (width - 1, height - 1)),
|
((1, line), (width - 1, line)),
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
width = self.content.size().0;
|
||||||
let max_name_width = std::cmp::max(
|
let max_name_width = std::cmp::max(
|
||||||
"Server Extensions:".len(),
|
"Server Extensions:".len(),
|
||||||
extensions
|
extensions
|
||||||
|
@ -466,15 +517,17 @@ impl Component for AccountStatus {
|
||||||
.max()
|
.max()
|
||||||
.unwrap_or(0),
|
.unwrap_or(0),
|
||||||
);
|
);
|
||||||
|
width = self.content.size().0;
|
||||||
write_string_to_grid(
|
write_string_to_grid(
|
||||||
"meli support:",
|
"meli support:",
|
||||||
&mut self.content,
|
&mut self.content,
|
||||||
self.theme_default.fg,
|
self.theme_default.fg,
|
||||||
self.theme_default.bg,
|
self.theme_default.bg,
|
||||||
self.theme_default.attrs,
|
self.theme_default.attrs,
|
||||||
((max_name_width + 6, line), (width - 1, height - 1)),
|
((max_name_width + 6, line), (width - 1, line)),
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
width = self.content.size().0;
|
||||||
line += 1;
|
line += 1;
|
||||||
for (name, status) in extensions.into_iter() {
|
for (name, status) in extensions.into_iter() {
|
||||||
let (width, height) = self.content.size();
|
let (width, height) = self.content.size();
|
||||||
|
@ -484,7 +537,7 @@ impl Component for AccountStatus {
|
||||||
self.theme_default.fg,
|
self.theme_default.fg,
|
||||||
self.theme_default.bg,
|
self.theme_default.bg,
|
||||||
self.theme_default.attrs,
|
self.theme_default.attrs,
|
||||||
((1, line), (width - 1, height - 1)),
|
((1, line), (width - 1, line)),
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -496,7 +549,7 @@ impl Component for AccountStatus {
|
||||||
Color::Red,
|
Color::Red,
|
||||||
self.theme_default.bg,
|
self.theme_default.bg,
|
||||||
self.theme_default.attrs,
|
self.theme_default.attrs,
|
||||||
((max_name_width + 6, line), (width - 1, height - 1)),
|
((max_name_width + 6, line), (width - 1, line)),
|
||||||
None,
|
None,
|
||||||
),
|
),
|
||||||
MailBackendExtensionStatus::Supported { comment: _ } => write_string_to_grid(
|
MailBackendExtensionStatus::Supported { comment: _ } => write_string_to_grid(
|
||||||
|
@ -505,7 +558,7 @@ impl Component for AccountStatus {
|
||||||
Color::Green,
|
Color::Green,
|
||||||
self.theme_default.bg,
|
self.theme_default.bg,
|
||||||
self.theme_default.attrs,
|
self.theme_default.attrs,
|
||||||
((max_name_width + 6, line), (width - 1, height - 1)),
|
((max_name_width + 6, line), (width - 1, line)),
|
||||||
None,
|
None,
|
||||||
),
|
),
|
||||||
MailBackendExtensionStatus::Enabled { comment: _ } => write_string_to_grid(
|
MailBackendExtensionStatus::Enabled { comment: _ } => write_string_to_grid(
|
||||||
|
@ -514,7 +567,7 @@ impl Component for AccountStatus {
|
||||||
Color::Green,
|
Color::Green,
|
||||||
self.theme_default.bg,
|
self.theme_default.bg,
|
||||||
self.theme_default.attrs,
|
self.theme_default.attrs,
|
||||||
((max_name_width + 6, line), (width - 1, height - 1)),
|
((max_name_width + 6, line), (width - 1, line)),
|
||||||
None,
|
None,
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
@ -529,7 +582,7 @@ impl Component for AccountStatus {
|
||||||
self.theme_default.fg,
|
self.theme_default.fg,
|
||||||
self.theme_default.bg,
|
self.theme_default.bg,
|
||||||
self.theme_default.attrs,
|
self.theme_default.attrs,
|
||||||
((x, y), (width - 1, height - 1)),
|
((x, y), (width - 1, y)),
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
let (x, y) = write_string_to_grid(
|
let (x, y) = write_string_to_grid(
|
||||||
|
@ -538,7 +591,7 @@ impl Component for AccountStatus {
|
||||||
self.theme_default.fg,
|
self.theme_default.fg,
|
||||||
self.theme_default.bg,
|
self.theme_default.bg,
|
||||||
self.theme_default.attrs,
|
self.theme_default.attrs,
|
||||||
((x, y), (width - 1, height - 1)),
|
((x, y), (width - 1, y)),
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
write_string_to_grid(
|
write_string_to_grid(
|
||||||
|
@ -547,7 +600,7 @@ impl Component for AccountStatus {
|
||||||
self.theme_default.fg,
|
self.theme_default.fg,
|
||||||
self.theme_default.bg,
|
self.theme_default.bg,
|
||||||
self.theme_default.attrs,
|
self.theme_default.attrs,
|
||||||
((x, y), (width - 1, height - 1)),
|
((x, y), (width - 1, y)),
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -558,17 +611,19 @@ impl Component for AccountStatus {
|
||||||
}
|
}
|
||||||
line += 2;
|
line += 2;
|
||||||
|
|
||||||
|
width = self.content.size().0;
|
||||||
write_string_to_grid(
|
write_string_to_grid(
|
||||||
"In-progress jobs:",
|
"In-progress jobs:",
|
||||||
&mut self.content,
|
&mut self.content,
|
||||||
self.theme_default.fg,
|
self.theme_default.fg,
|
||||||
self.theme_default.bg,
|
self.theme_default.bg,
|
||||||
Attr::BOLD,
|
Attr::BOLD,
|
||||||
((1, line), (width - 1, height - 1)),
|
((1, line), (width - 1, line)),
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
|
||||||
for (job_id, req) in a.active_jobs.iter() {
|
for (job_id, req) in a.active_jobs.iter() {
|
||||||
|
width = self.content.size().0;
|
||||||
use crate::conf::accounts::JobRequest;
|
use crate::conf::accounts::JobRequest;
|
||||||
let (x, y) = write_string_to_grid(
|
let (x, y) = write_string_to_grid(
|
||||||
&format!("{} {}", req, job_id),
|
&format!("{} {}", req, job_id),
|
||||||
|
@ -576,7 +631,7 @@ impl Component for AccountStatus {
|
||||||
self.theme_default.fg,
|
self.theme_default.fg,
|
||||||
self.theme_default.bg,
|
self.theme_default.bg,
|
||||||
self.theme_default.attrs,
|
self.theme_default.attrs,
|
||||||
((1, line), (width - 1, height - 1)),
|
((1, line), (width - 1, line)),
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
if let JobRequest::DeleteMailbox { mailbox_hash, .. }
|
if let JobRequest::DeleteMailbox { mailbox_hash, .. }
|
||||||
|
@ -595,7 +650,7 @@ impl Component for AccountStatus {
|
||||||
self.theme_default.fg,
|
self.theme_default.fg,
|
||||||
self.theme_default.bg,
|
self.theme_default.bg,
|
||||||
self.theme_default.attrs,
|
self.theme_default.attrs,
|
||||||
((x + 1, y), (width - 1, height - 1)),
|
((x + 1, y), (width - 1, y)),
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -672,42 +727,3 @@ impl Component for AccountStatus {
|
||||||
self.id = id;
|
self.id = id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AccountStatus {
|
|
||||||
pub fn new(account_pos: usize, theme_default: ThemeAttribute) -> AccountStatus {
|
|
||||||
let default_cell = {
|
|
||||||
let mut ret = Cell::with_char(' ');
|
|
||||||
ret.set_fg(theme_default.fg)
|
|
||||||
.set_bg(theme_default.bg)
|
|
||||||
.set_attrs(theme_default.attrs);
|
|
||||||
ret
|
|
||||||
};
|
|
||||||
let mut content = CellBuffer::new(120, 5, default_cell);
|
|
||||||
content.set_growable(true);
|
|
||||||
|
|
||||||
AccountStatus {
|
|
||||||
cursor: (0, 0),
|
|
||||||
account_pos,
|
|
||||||
content,
|
|
||||||
dirty: true,
|
|
||||||
theme_default,
|
|
||||||
id: ComponentId::new_v4(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
struct AccountStatus {
|
|
||||||
cursor: (usize, usize),
|
|
||||||
account_pos: usize,
|
|
||||||
content: CellBuffer,
|
|
||||||
dirty: bool,
|
|
||||||
theme_default: ThemeAttribute,
|
|
||||||
id: ComponentId,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Display for AccountStatus {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
write!(f, "status")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue