mirror of
https://github.com/soywod/himalaya.git
synced 2024-07-08 18:45:13 +00:00
remove display cell trait
This commit is contained in:
parent
04642859e8
commit
c3d5559234
|
@ -85,7 +85,7 @@ impl<'a> ImapConnector<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn list_mboxes(&mut self) -> Result<Vec<Mbox<'_>>> {
|
pub fn list_mboxes(&mut self) -> Result<Vec<Mbox>> {
|
||||||
let mboxes = self
|
let mboxes = self
|
||||||
.sess
|
.sess
|
||||||
.list(Some(""), Some("*"))?
|
.list(Some(""), Some("*"))?
|
||||||
|
|
111
src/mbox.rs
111
src/mbox.rs
|
@ -1,120 +1,39 @@
|
||||||
use imap;
|
use imap;
|
||||||
|
|
||||||
use crate::table::{self, DisplayCell, DisplayRow, DisplayTable};
|
use crate::table::{self, DisplayRow, DisplayTable};
|
||||||
|
|
||||||
pub struct Delim(String);
|
pub struct Mbox {
|
||||||
|
pub delim: String,
|
||||||
impl Delim {
|
pub name: String,
|
||||||
pub fn from_name(name: &imap::types::Name) -> Self {
|
pub attributes: Vec<String>,
|
||||||
Self(name.delimiter().unwrap_or("/").to_string())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DisplayCell for Delim {
|
impl Mbox {
|
||||||
fn styles(&self) -> &[table::Style] {
|
|
||||||
&[table::BLUE]
|
|
||||||
}
|
|
||||||
|
|
||||||
fn value(&self) -> String {
|
|
||||||
self.0.to_owned()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct Name(String);
|
|
||||||
|
|
||||||
impl Name {
|
|
||||||
pub fn from_name(name: &imap::types::Name) -> Self {
|
|
||||||
Self(name.name().to_string())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DisplayCell for Name {
|
|
||||||
fn styles(&self) -> &[table::Style] {
|
|
||||||
&[table::GREEN]
|
|
||||||
}
|
|
||||||
|
|
||||||
fn value(&self) -> String {
|
|
||||||
self.0.to_owned()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct Attributes<'a>(Vec<imap::types::NameAttribute<'a>>);
|
|
||||||
|
|
||||||
impl Attributes<'_> {
|
|
||||||
pub fn from_name(name: &imap::types::Name) -> Self {
|
|
||||||
let attrs = name.attributes().iter().fold(vec![], |mut attrs, attr| {
|
|
||||||
use imap::types::NameAttribute::*;
|
|
||||||
|
|
||||||
match attr {
|
|
||||||
NoInferiors => attrs.push(NoInferiors),
|
|
||||||
NoSelect => attrs.push(NoSelect),
|
|
||||||
Marked => attrs.push(Marked),
|
|
||||||
Unmarked => attrs.push(Unmarked),
|
|
||||||
_ => (),
|
|
||||||
};
|
|
||||||
|
|
||||||
attrs
|
|
||||||
});
|
|
||||||
|
|
||||||
Self(attrs)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DisplayCell for Attributes<'_> {
|
|
||||||
fn styles(&self) -> &[table::Style] {
|
|
||||||
&[table::YELLOW]
|
|
||||||
}
|
|
||||||
|
|
||||||
fn value(&self) -> String {
|
|
||||||
use imap::types::NameAttribute::*;
|
|
||||||
|
|
||||||
self.0
|
|
||||||
.iter()
|
|
||||||
.map(|attr| match attr {
|
|
||||||
NoInferiors => vec!["no inferiors"],
|
|
||||||
NoSelect => vec!["no select"],
|
|
||||||
Marked => vec!["marked"],
|
|
||||||
Unmarked => vec!["unmarked"],
|
|
||||||
_ => vec![],
|
|
||||||
})
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
.concat()
|
|
||||||
.join(", ")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct Mbox<'a> {
|
|
||||||
pub delim: Delim,
|
|
||||||
pub name: Name,
|
|
||||||
pub attributes: Attributes<'a>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Mbox<'_> {
|
|
||||||
pub fn from_name(name: &imap::types::Name) -> Self {
|
pub fn from_name(name: &imap::types::Name) -> Self {
|
||||||
Self {
|
Self {
|
||||||
delim: Delim::from_name(name),
|
delim: name.delimiter().unwrap_or_default().to_owned(),
|
||||||
name: Name::from_name(name),
|
name: name.name().to_owned(),
|
||||||
attributes: Attributes::from_name(name),
|
attributes: vec![], // TODO: set attributes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> DisplayRow for Mbox<'a> {
|
impl DisplayRow for Mbox {
|
||||||
fn to_row(&self) -> Vec<table::Cell> {
|
fn to_row(&self) -> Vec<table::Cell> {
|
||||||
vec![
|
vec![
|
||||||
self.delim.to_cell(),
|
table::Cell::new(&[table::BLUE], &self.delim),
|
||||||
self.name.to_cell(),
|
table::Cell::new(&[table::GREEN], &self.name),
|
||||||
self.attributes.to_cell(),
|
table::Cell::new(&[table::YELLOW], &self.attributes.join(", ")),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> DisplayTable<'a, Mbox<'a>> for Vec<Mbox<'a>> {
|
impl<'a> DisplayTable<'a, Mbox> for Vec<Mbox> {
|
||||||
fn cols() -> &'a [&'a str] {
|
fn cols() -> &'a [&'a str] {
|
||||||
&["delim", "name", "attributes"]
|
&["delim", "name", "attributes"]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rows(&self) -> &Vec<Mbox<'a>> {
|
fn rows(&self) -> &Vec<Mbox> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
11
src/table.rs
11
src/table.rs
|
@ -36,7 +36,7 @@ pub struct Cell {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Cell {
|
impl Cell {
|
||||||
pub fn new<'a>(styles: &'a [Style], value: &'a str) -> Cell {
|
pub fn new(styles: &[Style], value: &str) -> Cell {
|
||||||
Cell {
|
Cell {
|
||||||
styles: styles.to_vec(),
|
styles: styles.to_vec(),
|
||||||
value: value.to_string(),
|
value: value.to_string(),
|
||||||
|
@ -65,15 +65,6 @@ impl Cell {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait DisplayCell {
|
|
||||||
fn styles(&self) -> &[Style];
|
|
||||||
fn value(&self) -> String;
|
|
||||||
|
|
||||||
fn to_cell(&self) -> Cell {
|
|
||||||
Cell::new(self.styles(), &self.value())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait DisplayRow {
|
pub trait DisplayRow {
|
||||||
fn to_row(&self) -> Vec<Cell>;
|
fn to_row(&self) -> Vec<Cell>;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue