Browse Source

Run rustfmt

tags/pre-alpha-0.0
Manos Pitsidianakis 3 years ago
parent
commit
bf038428c2
Signed by: epilys GPG Key ID: 73627C2F690DF710
  1. 14
      melib/src/addressbook.rs
  2. 4
      melib/src/lib.rs
  3. 37
      melib/src/mailbox/backends/maildir/backend.rs
  4. 36
      melib/src/mailbox/collection.rs
  5. 36
      melib/src/mailbox/email.rs
  6. 156
      melib/src/mailbox/email/attachments.rs
  7. 16
      melib/src/mailbox/email/compose.rs
  8. 17
      melib/src/mailbox/email/parser.rs
  9. 0
      rustfmt.toml
  10. 16
      src/bin.rs
  11. 43
      ui/src/components.rs
  12. 90
      ui/src/components/contacts.rs
  13. 74
      ui/src/components/contacts/contact_list.rs
  14. 3
      ui/src/components/indexer.rs
  15. 2
      ui/src/components/indexer/index.rs
  16. 3
      ui/src/components/mail.rs
  17. 40
      ui/src/components/mail/accounts.rs
  18. 260
      ui/src/components/mail/compose.rs
  19. 1
      ui/src/components/mail/listing.rs
  20. 92
      ui/src/components/mail/listing/compact.rs
  21. 12
      ui/src/components/mail/listing/thread.rs
  22. 47
      ui/src/components/mail/view.rs
  23. 9
      ui/src/components/mail/view/envelope.rs
  24. 44
      ui/src/components/notifications.rs
  25. 129
      ui/src/components/utilities.rs
  26. 371
      ui/src/components/utilities/widgets.rs
  27. 13
      ui/src/conf.rs
  28. 24
      ui/src/conf/accounts.rs
  29. 17
      ui/src/conf/shortcuts.rs
  30. 8
      ui/src/execute/actions.rs
  31. 39
      ui/src/state.rs
  32. 2
      ui/src/terminal.rs
  33. 15
      ui/src/terminal/cells.rs
  34. 65
      ui/src/terminal/keys.rs
  35. 6
      ui/src/terminal/position.rs
  36. 2
      ui/src/terminal/wcwidth.rs

14
melib/src/addressbook.rs

@ -19,8 +19,8 @@
* along with meli. If not, see <http://www.gnu.org/licenses/>.
*/
use chrono::{DateTime, Local};
use uuid::Uuid;
use fnv::FnvHashMap;
use uuid::Uuid;
use std::ops::Deref;
@ -31,7 +31,7 @@ pub struct AddressBook {
display_name: String,
created: DateTime<Local>,
last_edited: DateTime<Local>,
cards: FnvHashMap<CardId, Card>
cards: FnvHashMap<CardId, Card>,
}
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
@ -44,7 +44,6 @@ pub struct Card {
name_prefix: String,
name_suffix: String,
//address
birthday: Option<DateTime<Local>>,
email: String,
url: String,
@ -74,7 +73,11 @@ impl AddressBook {
self.cards.contains_key(&card_id)
}
pub fn search(&self, term: &str) -> Vec<String> {
self.cards.values().filter(|c| c.email.contains(term)).map(|c| c.email.clone()).collect()
self.cards
.values()
.filter(|c| c.email.contains(term))
.map(|c| c.email.clone())
.collect()
}
}
@ -86,7 +89,6 @@ impl Deref for AddressBook {
}
}
impl Card {
pub fn new() -> Card {
Card {
@ -98,7 +100,6 @@ impl Card {
name_prefix: String::new(),
name_suffix: String::new(),
//address
birthday: None,
email: String::new(),
url: String::new(),
@ -182,7 +183,6 @@ impl Card {
pub fn extra_property(&self, key: &str) -> Option<&str> {
self.extra_properties.get(key).map(|v| v.as_str())
}
}
impl From<FnvHashMap<String, String>> for Card {

4
melib/src/lib.rs

@ -18,11 +18,11 @@
* You should have received a copy of the GNU General Public License
* along with meli. If not, see <http://www.gnu.org/licenses/>.
*/
pub mod addressbook;
pub mod async;
pub mod conf;
pub mod error;
pub mod mailbox;
pub mod addressbook;
#[macro_use]
extern crate serde_derive;
@ -38,8 +38,8 @@ extern crate chan;
#[macro_use]
extern crate bitflags;
extern crate uuid;
extern crate fnv;
extern crate uuid;
pub use conf::*;
pub use mailbox::*;

37
melib/src/mailbox/backends/maildir/backend.rs

@ -27,7 +27,7 @@ extern crate xdg;
use super::{MaildirFolder, MaildirOp};
use async::*;
use conf::AccountSettings;
use error::{Result, MeliError};
use error::{MeliError, Result};
use mailbox::backends::{
BackendFolder, BackendOp, Folder, FolderHash, MailBackend, RefreshEvent, RefreshEventConsumer,
RefreshEventKind::*,
@ -132,16 +132,16 @@ fn get_file_hash(file: &Path) -> EnvelopeHash {
}
fn move_to_cur(p: PathBuf) -> PathBuf {
let mut new = p.clone();
{
let file_name = p.file_name().unwrap();
new.pop();
new.pop();
let mut new = p.clone();
{
let file_name = p.file_name().unwrap();
new.pop();
new.pop();
new.push("cur");
new.push(file_name);
new.set_extension(":2,");
}
new.push("cur");
new.push(file_name);
new.set_extension(":2,");
}
eprintln!("moved to cur: {}", new.display());
fs::rename(p, &new).unwrap();
new
@ -347,7 +347,10 @@ impl MailBackend for MaildirType {
}
}
Err(MeliError::new(format!("'{}' is not a valid folder.", folder)))
Err(MeliError::new(format!(
"'{}' is not a valid folder.",
folder
)))
}
}
@ -447,13 +450,13 @@ impl MaildirType {
let thunk = move || {
let mut path = path.clone();
let cache_dir = cache_dir.clone();
path.push("new");
for d in path.read_dir()? {
if let Ok(p) = d {
move_to_cur(p.path());
}
path.push("new");
for d in path.read_dir()? {
if let Ok(p) = d {
move_to_cur(p.path());
}
path.pop();
}
path.pop();
path.push("cur");
let iter = path.read_dir()?;

36
melib/src/mailbox/collection.rs

@ -56,24 +56,24 @@ impl Collection {
let threads = Threads::new(&mut envelopes);
/*let cache_dir =
xdg::BaseDirectories::with_profile("meli", format!("{}_Thread", folder.hash()))
.unwrap();
if let Some(cached) = cache_dir.find_cache_file("threads") {
let reader = io::BufReader::new(fs::File::open(cached).unwrap());
let result: result::Result<Threads, _> = bincode::deserialize_from(reader);
let ret = if let Ok(mut cached_t) = result {
use std::iter::FromIterator;
eprintln!("loaded cache, our hash set is {:?}\n and the cached one is {:?}", FnvHashSet::from_iter(envelopes.keys().cloned()), cached_t.hash_set);
cached_t.amend(&mut envelopes);
cached_t
} else {
Threads::new(&mut envelopes)
};
ret
} else {
Threads::new(&mut envelopes)
};
*/
xdg::BaseDirectories::with_profile("meli", format!("{}_Thread", folder.hash()))
.unwrap();
if let Some(cached) = cache_dir.find_cache_file("threads") {
let reader = io::BufReader::new(fs::File::open(cached).unwrap());
let result: result::Result<Threads, _> = bincode::deserialize_from(reader);
let ret = if let Ok(mut cached_t) = result {
use std::iter::FromIterator;
eprintln!("loaded cache, our hash set is {:?}\n and the cached one is {:?}", FnvHashSet::from_iter(envelopes.keys().cloned()), cached_t.hash_set);
cached_t.amend(&mut envelopes);
cached_t
} else {
Threads::new(&mut envelopes)
};
ret
} else {
Threads::new(&mut envelopes)
};
*/
Collection {
folder: folder.clone(),

36
melib/src/mailbox/email.rs

@ -74,7 +74,7 @@ impl Address {
Address::Group(g) => g.display_name.display(&g.raw),
}
}
pub fn get_email(&self) -> String {
match self {
Address::Mailbox(m) => m.address_spec.display(&m.raw),
@ -94,11 +94,11 @@ impl PartialEq for Address {
s.address_spec.display(&s.raw) == o.address_spec.display(&o.raw)
}
(Address::Group(s), Address::Group(o)) => {
s.display_name.display(&s.raw) == o.display_name.display(&o.raw) && s
.mailbox_list
.iter()
.zip(o.mailbox_list.iter())
.fold(true, |b, (s, o)| b && (s == o))
s.display_name.display(&s.raw) == o.display_name.display(&o.raw)
&& s.mailbox_list
.iter()
.zip(o.mailbox_list.iter())
.fold(true, |b, (s, o)| b && (s == o))
}
}
}
@ -616,22 +616,22 @@ impl Envelope {
pub fn message_id_raw(&self) -> Cow<str> {
String::from_utf8_lossy(self.message_id.raw())
}
fn set_date(&mut self, new_val: &[u8]) {
fn set_date(&mut self, new_val: &[u8]) {
self.date = String::from_utf8_lossy(new_val).into_owned();
}
fn set_bcc(&mut self, new_val: Vec<Address>) {
fn set_bcc(&mut self, new_val: Vec<Address>) {
self.bcc = new_val;
}
fn set_cc(&mut self, new_val: Vec<Address>) {
fn set_cc(&mut self, new_val: Vec<Address>) {
self.cc = new_val;
}
fn set_from(&mut self, new_val: Vec<Address>) {
fn set_from(&mut self, new_val: Vec<Address>) {
self.from = new_val;
}
fn set_to(&mut self, new_val: Vec<Address>) {
fn set_to(&mut self, new_val: Vec<Address>) {
self.to = new_val;
}
fn set_in_reply_to(&mut self, new_val: &[u8]) {
fn set_in_reply_to(&mut self, new_val: &[u8]) {
let slice = match parser::message_id(new_val).to_full_result() {
Ok(v) => v,
Err(_) => {
@ -641,10 +641,10 @@ impl Envelope {
};
self.in_reply_to = Some(MessageID::new(new_val, slice));
}
fn set_subject(&mut self, new_val: Vec<u8>) {
fn set_subject(&mut self, new_val: Vec<u8>) {
self.subject = Some(new_val);
}
fn set_message_id(&mut self, new_val: &[u8]) {
fn set_message_id(&mut self, new_val: &[u8]) {
let slice = match parser::message_id(new_val).to_full_result() {
Ok(v) => v,
Err(_) => {
@ -653,7 +653,7 @@ impl Envelope {
};
self.message_id = MessageID::new(new_val, slice);
}
fn push_references(&mut self, new_val: &[u8]) {
fn push_references(&mut self, new_val: &[u8]) {
let slice = match parser::message_id(new_val).to_full_result() {
Ok(v) => v,
Err(_) => {
@ -685,7 +685,7 @@ impl Envelope {
}
}
}
fn set_references(&mut self, new_val: &[u8]) {
fn set_references(&mut self, new_val: &[u8]) {
match self.references {
Some(ref mut s) => {
s.raw = new_val.into();
@ -713,10 +713,10 @@ impl Envelope {
pub fn thread(&self) -> usize {
self.thread
}
pub fn set_thread(&mut self, new_val: usize) {
pub fn set_thread(&mut self, new_val: usize) {
self.thread = new_val;
}
pub fn set_datetime(&mut self, new_val: chrono::DateTime<chrono::FixedOffset>) {
pub fn set_datetime(&mut self, new_val: chrono::DateTime<chrono::FixedOffset>) {
self.timestamp = new_val.timestamp() as UnixTimestamp;
}
pub fn set_flag(&mut self, f: Flag, mut operation: Box<BackendOp>) -> Result<()> {

156
melib/src/mailbox/email/attachments.rs

@ -71,73 +71,77 @@ impl AttachmentBuilder {
}
pub fn content_type(&mut self, value: &[u8]) -> &Self {
match parser::content_type(value).to_full_result() {
Ok((ct, cst, params)) => if ct.eq_ignore_ascii_case(b"multipart") {
let mut boundary = None;
for (n, v) in params {
if n.eq_ignore_ascii_case(b"boundary") {
boundary = Some(v);
break;
Ok((ct, cst, params)) => {
if ct.eq_ignore_ascii_case(b"multipart") {
let mut boundary = None;
for (n, v) in params {
if n.eq_ignore_ascii_case(b"boundary") {
boundary = Some(v);
break;
}
}
}
assert!(boundary.is_some());
let _boundary = boundary.unwrap();
let offset = (_boundary.as_ptr() as usize).wrapping_sub(value.as_ptr() as usize);
let boundary = SliceBuild::new(offset, _boundary.len());
let subattachments = Self::subattachments(&self.raw, boundary.get(&value));
assert!(!subattachments.is_empty());
self.content_type = ContentType::Multipart {
boundary,
kind: if cst.eq_ignore_ascii_case(b"mixed") {
MultipartType::Mixed
} else if cst.eq_ignore_ascii_case(b"alternative") {
MultipartType::Alternative
} else if cst.eq_ignore_ascii_case(b"digest") {
MultipartType::Digest
} else {
Default::default()
},
subattachments,
};
} else if ct.eq_ignore_ascii_case(b"text") {
self.content_type = ContentType::Text {
kind: Text::Plain,
charset: Charset::UTF8,
};
for (n, v) in params {
if n.eq_ignore_ascii_case(b"charset") {
assert!(boundary.is_some());
let _boundary = boundary.unwrap();
let offset =
(_boundary.as_ptr() as usize).wrapping_sub(value.as_ptr() as usize);
let boundary = SliceBuild::new(offset, _boundary.len());
let subattachments = Self::subattachments(&self.raw, boundary.get(&value));
assert!(!subattachments.is_empty());
self.content_type = ContentType::Multipart {
boundary,
kind: if cst.eq_ignore_ascii_case(b"mixed") {
MultipartType::Mixed
} else if cst.eq_ignore_ascii_case(b"alternative") {
MultipartType::Alternative
} else if cst.eq_ignore_ascii_case(b"digest") {
MultipartType::Digest
} else {
Default::default()
},
subattachments,
};
} else if ct.eq_ignore_ascii_case(b"text") {
self.content_type = ContentType::Text {
kind: Text::Plain,
charset: Charset::UTF8,
};
for (n, v) in params {
if n.eq_ignore_ascii_case(b"charset") {
if let ContentType::Text {
charset: ref mut c, ..
} = self.content_type
{
*c = Charset::from(v);
}
break;
}
}
if cst.eq_ignore_ascii_case(b"html") {
if let ContentType::Text {
charset: ref mut c, ..
kind: ref mut k, ..
} = self.content_type
{
*c = Charset::from(v);
*k = Text::Html;
}
} else if !cst.eq_ignore_ascii_case(b"plain") {
if let ContentType::Text {
kind: ref mut k, ..
} = self.content_type
{
*k = Text::Other { tag: cst.into() };
}
break;
}
}
if cst.eq_ignore_ascii_case(b"html") {
if let ContentType::Text {
kind: ref mut k, ..
} = self.content_type
{
*k = Text::Html;
}
} else if !cst.eq_ignore_ascii_case(b"plain") {
if let ContentType::Text {
kind: ref mut k, ..
} = self.content_type
{
*k = Text::Other { tag: cst.into() };
}
} else if ct.eq_ignore_ascii_case(b"message") && cst.eq_ignore_ascii_case(b"rfc822")
{
self.content_type = ContentType::MessageRfc822;
} else {
let mut tag: Vec<u8> = Vec::with_capacity(ct.len() + cst.len() + 1);
tag.extend(ct);
tag.push(b'/');
tag.extend(cst);
self.content_type = ContentType::Unsupported { tag };
}
} else if ct.eq_ignore_ascii_case(b"message") && cst.eq_ignore_ascii_case(b"rfc822") {
self.content_type = ContentType::MessageRfc822;
} else {
let mut tag: Vec<u8> = Vec::with_capacity(ct.len() + cst.len() + 1);
tag.extend(ct);
tag.push(b'/');
tag.extend(cst);
self.content_type = ContentType::Unsupported { tag };
},
}
Err(v) => {
eprintln!("parsing error in content_type: {:?} {:?}", value, v);
}
@ -405,23 +409,25 @@ fn decode_rec_helper(a: &Attachment, filter: &Option<Filter>) -> Vec<u8> {
kind: ref multipart_type,
subattachments: ref sub_att_vec,
..
} => if *multipart_type == MultipartType::Alternative {
for a in sub_att_vec {
if let ContentType::Text {
kind: Text::Plain, ..
} = a.content_type
{
return decode_helper(a, filter);
} => {
if *multipart_type == MultipartType::Alternative {
for a in sub_att_vec {
if let ContentType::Text {
kind: Text::Plain, ..
} = a.content_type
{
return decode_helper(a, filter);
}
}
decode_helper(a, filter)
} else {
let mut vec = Vec::new();
for a in sub_att_vec {
vec.extend(decode_rec_helper(a, filter));
}
vec
}
decode_helper(a, filter)
} else {
let mut vec = Vec::new();
for a in sub_att_vec {
vec.extend(decode_rec_helper(a, filter));
}
vec
},
}
};
if let Some(filter) = filter {
filter(a, &mut ret);

16
melib/src/mailbox/email/compose.rs

@ -3,8 +3,8 @@ use chrono::{DateTime, Local};
use data_encoding::BASE64_MIME;
use std::str;
mod random;
mod mime;
mod random;
//use self::mime::*;
@ -70,13 +70,16 @@ impl str::FromStr for Draft {
if ignore_header(k) {
continue;
}
if ret.headers.insert(
String::from_utf8(k.to_vec())?,
String::from_utf8(v.to_vec())?,
).is_none() {
if ret
.headers
.insert(
String::from_utf8(k.to_vec())?,
String::from_utf8(v.to_vec())?,
)
.is_none()
{
ret.header_order.push(String::from_utf8(k.to_vec())?);
}
}
let body = Envelope::new(0).body_bytes(s.as_bytes());
@ -191,7 +194,6 @@ impl Draft {
}
Ok(ret)
}
}

17
melib/src/mailbox/email/parser.rs

@ -135,16 +135,19 @@ named!(
named!(
header_no_val<(&[u8], &[u8])>,
do_parse!(
name: complete!(name) >>
tag!(b":") >>
opt!(is_a!(" \t")) >>
tag!(b"\n") >>
( { (name, b"") } )));
do_parse!(
name: complete!(name)
>> tag!(b":")
>> opt!(is_a!(" \t"))
>> tag!(b"\n")
>> ({ (name, b"") })
)
);
named!(
header<(&[u8], &[u8])>,
alt_complete!(header_no_val | header_has_val));
alt_complete!(header_no_val | header_has_val)
);
/* Parse all headers -> Vec<(&str, Vec<&str>)> */
named!(pub headers<std::vec::Vec<(&[u8], &[u8])>>,
many1!(complete!(header)));

0
rustfmt.toml

16
src/bin.rs

@ -48,9 +48,9 @@ fn main() {
//let _stdout = stdout();
//let mut _stdout = _stdout.lock();
/*
let _stderr = stderr();
let mut _stderr = _stderr.lock();
*/
let _stderr = stderr();
let mut _stderr = _stderr.lock();
*/
/* Catch SIGWINCH to handle terminal resizing */
let signal = chan_signal::notify(&[Signal::WINCH]);
@ -66,7 +66,11 @@ fn main() {
let menu = Entity::from(Box::new(AccountMenu::new(&state.context.accounts)));
let listing = listing::Listing::from(IndexStyle::Compact);
let b = Entity::from(Box::new(listing));
let tabs = Box::new(Tabbed::new(vec![Box::new(VSplit::new(menu, b, 90, true)), Box::new(AccountsPanel::new(&state.context)), Box::new(ContactList::default())]));
let tabs = Box::new(Tabbed::new(vec![
Box::new(VSplit::new(menu, b, 90, true)),
Box::new(AccountsPanel::new(&state.context)),
Box::new(ContactList::default()),
]));
let window = Entity::from(tabs);
let status_bar = Entity::from(Box::new(StatusBar::new(window)));
@ -75,7 +79,9 @@ fn main() {
let xdg_notifications =
Entity::from(Box::new(ui::components::notifications::XDGNotifications {}));
state.register_entity(xdg_notifications);
state.register_entity(Entity::from(Box::new(ui::components::notifications::NotificationFilter {})));
state.register_entity(Entity::from(Box::new(
ui::components::notifications::NotificationFilter {},
)));
/* Keep track of the input mode. See ui::UIMode for details */
'main: loop {

43
ui/src/components.rs

@ -20,10 +20,10 @@
*/
/*!
Components are ways to handle application data. They can draw on the terminal and receive events, but also do other stuff as well. (For example, see the `notifications` module.)
Components are ways to handle application data. They can draw on the terminal and receive events, but also do other stuff as well. (For example, see the `notifications` module.)
See the `Component` Trait for more details.
*/
See the `Component` Trait for more details.
*/
use super::*;
@ -76,8 +76,6 @@ const _DOUBLE_DOWN_AND_LEFT: char = 'โ•—';
const _DOUBLE_UP_AND_LEFT: char = 'โ•';
const _DOUBLE_UP_AND_RIGHT: char = 'โ•š';
type EntityId = Uuid;
/// `Entity` is a container for Components.
@ -157,7 +155,9 @@ pub trait Component: Display + Debug + Send {
fn kill(&mut self, _id: EntityId) {}
fn set_id(&mut self, _id: EntityId) {}
fn get_shortcuts(&self, context: &Context) -> ShortcutMap { Default::default() }
fn get_shortcuts(&self, context: &Context) -> ShortcutMap {
Default::default()
}
}
/*
@ -429,20 +429,23 @@ pub(crate) fn set_and_join_box(grid: &mut CellBuffer, idx: Pos, ch: char) {
}
pub fn create_box(grid: &mut CellBuffer, area: Area) {
let upper_left = upper_left!(area);
let bottom_right = bottom_right!(area);
if !is_valid_area!(area) {
return;
}
let upper_left = upper_left!(area);
let bottom_right = bottom_right!(area);
for x in get_x(upper_left)..get_x(bottom_right) {
grid[(x, get_y(upper_left))].set_ch(HORZ_BOUNDARY);
grid[(x, get_y(bottom_right))].set_ch(HORZ_BOUNDARY);
}
for x in get_x(upper_left)..get_x(bottom_right) {
grid[(x, get_y(upper_left))].set_ch(HORZ_BOUNDARY);
grid[(x, get_y(bottom_right))].set_ch(HORZ_BOUNDARY);
}
for y in get_y(upper_left)..get_y(bottom_right) {
grid[(get_x(upper_left), y)].set_ch(VERT_BOUNDARY);
grid[(get_x(bottom_right), y)].set_ch(VERT_BOUNDARY);
}
set_and_join_box(grid, upper_left, HORZ_BOUNDARY);
set_and_join_box(grid, set_x(upper_left, get_x(bottom_right)), HORZ_BOUNDARY);
set_and_join_box(grid, set_y(upper_left, get_y(bottom_right)), VERT_BOUNDARY);
set_and_join_box(grid, bottom_right, VERT_BOUNDARY);
for y in get_y(upper_left)..get_y(bottom_right) {
grid[(get_x(upper_left), y)].set_ch(VERT_BOUNDARY);
grid[(get_x(bottom_right), y)].set_ch(VERT_BOUNDARY);
}
set_and_join_box(grid, upper_left, HORZ_BOUNDARY);
set_and_join_box(grid, set_x(upper_left, get_x(bottom_right)), HORZ_BOUNDARY);
set_and_join_box(grid, set_y(upper_left, get_y(bottom_right)), VERT_BOUNDARY);
set_and_join_box(grid, bottom_right, VERT_BOUNDARY);
}

90
ui/src/components/contacts.rs

@ -78,7 +78,7 @@ impl ContactManager {
Color::Default,
((0, 0), (width, 0)),
false,
);
);
let (x, _) = write_string_to_grid(
"Last edited: ",
&mut self.content,
@ -86,7 +86,7 @@ impl ContactManager {
Color::Default,
((x, 0), (width, 0)),
false,
);
);
write_string_to_grid(
&self.card.last_edited(),
&mut self.content,
@ -94,15 +94,23 @@ impl ContactManager {
Color::Default,
((x, 0), (width, 0)),
false,
);
);
self.form = FormWidget::new("Save".into());
self.form.add_button(("Cancel".into(), false));
self.form.push(("First Name".into(), self.card.firstname().to_string()));
self.form.push(("Last Name".into(), self.card.lastname().to_string()));
self.form.push(("Additional Name".into(), self.card.additionalname().to_string()));
self.form.push(("Name Prefix".into(), self.card.name_prefix().to_string()));
self.form.push(("Name Suffix".into(), self.card.name_suffix().to_string()));
self.form.push(("E-mail".into(), self.card.email().to_string()));
self.form
.push(("First Name".into(), self.card.firstname().to_string()));
self.form
.push(("Last Name".into(), self.card.lastname().to_string()));
self.form.push((
"Additional Name".into(),
self.card.additionalname().to_string(),
));
self.form
.push(("Name Prefix".into(), self.card.name_prefix().to_string()));
self.form
.push(("Name Suffix".into(), self.card.name_suffix().to_string()));
self.form
.push(("E-mail".into(), self.card.email().to_string()));
self.form.push(("url".into(), self.card.url().to_string()));
self.form.push(("key".into(), self.card.key().to_string()));
}
@ -120,55 +128,71 @@ impl Component for ContactManager {
let upper_left = upper_left!(area);
let bottom_right = bottom_right!(area);
self.form.draw(grid, (set_y(upper_left, get_y(upper_left) + 1), bottom_right), context);
self.form.draw(
grid,
(set_y(upper_left, get_y(upper_left) + 1), bottom_right),
context,
);
context.dirty_areas.push_back(area);
}
fn process_event(&mut self, event: &mut UIEvent, context: &mut Context) -> bool {
if self.form.process_event(event, context) {
match self.form.buttons_result() {
None => {},
None => {}
Some(true) => {
let mut fields = std::mem::replace(&mut self.form, FormWidget::default()).collect().unwrap();
let fields: FnvHashMap<String, String> = fields.into_iter().map(|(s, v)| {
(s, match v {
Field::Text(v, _, _) | Field::TextArea(v, _) => v,
Field::Choice(mut v, c) => v.remove(c),
})}).collect();
let mut fields = std::mem::replace(&mut self.form, FormWidget::default())
.collect()
.unwrap();
let fields: FnvHashMap<String, String> = fields
.into_iter()
.map(|(s, v)| {
(
s,
match v {
Field::Text(v, _, _) | Field::TextArea(v, _) => v,
Field::Choice(mut v, c) => v.remove(c),
},
)
})
.collect();
let mut new_card = Card::from(fields);
new_card.set_id(*self.card.id());
context.accounts[self.account_pos].address_book.add_card(new_card);
context.accounts[self.account_pos]
.address_book
.add_card(new_card);
context.replies.push_back(UIEvent {
id: 0,
event_type: UIEventType::StatusEvent(StatusEvent::DisplayMessage("Saved.".into())),
event_type: UIEventType::StatusEvent(StatusEvent::DisplayMessage(
"Saved.".into(),
)),
});
context.replies.push_back(UIEvent {
id: 0,
event_type: UIEventType::EntityKill(self.id),
});
},
}
Some(false) => {
context.replies.push_back(UIEvent {
id: 0,
event_type: UIEventType::EntityKill(self.id),
});
},
}
}
return true;
}
/*
match event.event_type {
UIEventType::Input(Key::Char('\n')) => {
context.replies.push_back(UIEvent {
id: 0,
event_type: UIEventType::EntityKill(self.id),
});
return true;
},
_ => {},
}
*/
match event.event_type {
UIEventType::Input(Key::Char('\n')) => {
context.replies.push_back(UIEvent {
id: 0,
event_type: UIEventType::EntityKill(self.id),
});
return true;
},
_ => {},
}
*/
false
}

74
ui/src/components/contacts/contact_list.rs

@ -20,7 +20,7 @@ pub struct ContactList {
content: CellBuffer,
id_positions: Vec<CardId>,
mode: ViewMode,
dirty: bool,
view: Option<Entity>,
@ -60,29 +60,30 @@ impl ContactList {
..Self::new()
}
}
fn initialize(&mut self, context: &mut Context) {
let account = &mut context.accounts[self.account_pos];
let book = &mut account.address_book;
self.length = book.len();
self.content.resize(MAX_COLS, book.len(), Cell::with_char(' '));
self.content
.resize(MAX_COLS, book.len(), Cell::with_char(' '));
self.id_positions.clear();
if self.id_positions.capacity() < book.len() {
self.id_positions.reserve(book.len());
self.id_positions.reserve(book.len());
}
for (i, c) in book.values().enumerate() {
self.id_positions.push(*c.id());
write_string_to_grid(
c.email(),
&mut self.content,
Color::Default,
Color::Default,
((0, i), (MAX_COLS - 1, book.len() - 1)),
false
);
false,
);
}
}
}
@ -105,7 +106,15 @@ impl Component for ContactList {
if self.dirty {
self.initialize(context);
clear_area(grid, area);
copy_area(grid, &self.content, area, ((0, 0), (MAX_COLS - 1, self.content.size().1.saturating_sub(1))));
copy_area(
grid,
&self.content,
area,
(
(0, 0),
(MAX_COLS - 1, self.content.size().1.saturating_sub(1)),
),
);
context.dirty_areas.push_back(area);
self.dirty = false;
}
@ -116,11 +125,27 @@ impl Component for ContactList {
/* Reset previously highlighted line */
let fg_color = Color::Default;
let bg_color = Color::Default;
change_colors(grid, (pos_inc(upper_left, (0, self.cursor_pos)), set_y(bottom_right, get_y(upper_left) + self.cursor_pos)), fg_color, bg_color);
change_colors(
grid,
(
pos_inc(upper_left, (0, self.cursor_pos)),
set_y(bottom_right, get_y(upper_left) + self.cursor_pos),
),
fg_color,
bg_color,
);
/* Highlight current line */
let bg_color = Color::Byte(246);
change_colors(grid, (pos_inc(upper_left, (0, self.new_cursor_pos)), set_y(bottom_right, get_y(upper_left) + self.new_cursor_pos)), fg_color, bg_color);
change_colors(
grid,
(
pos_inc(upper_left, (0, self.new_cursor_pos)),
set_y(bottom_right, get_y(upper_left) + self.new_cursor_pos),
),
fg_color,
bg_color,
);
self.cursor_pos = self.new_cursor_pos;
}
@ -139,10 +164,10 @@ impl Component for ContactList {
self.mode = ViewMode::View(*entity.id());
self.view = Some(entity);
return true;
},
}
UIEventType::Input(ref key) if *key == shortcuts["edit_contact"] && self.length > 0 => {
let account = &mut context.accounts[self.account_pos];
let book = &mut account.address_book;
@ -154,9 +179,9 @@ impl Component for ContactList {
self.mode = ViewMode::View(*entity.id());
self.view = Some(entity);
return true;
},
}
UIEventType::Input(Key::Char('n')) => {
let card = Card::new();
let mut manager = ContactManager::default();
@ -165,27 +190,26 @@ impl Component for ContactList {
let entity = Entity::from(Box::new(manager));
self.mode = ViewMode::View(*entity.id());
self.view = Some(entity);
return true;
},
}
UIEventType::Input(Key::Up) => {
self.set_dirty();
self.new_cursor_pos = self.cursor_pos.saturating_sub(1);
return true;
},
}
UIEventType::Input(Key::Down) if self.cursor_pos < self.length.saturating_sub(1) => {
self.set_dirty();
self.new_cursor_pos += 1;
return true;
},
}
UIEventType::EntityKill(ref kill_id) if self.mode == ViewMode::View(*kill_id) => {
self.mode = ViewMode::List;
self.view.take();
self.set_dirty();
return true;
},
_ => {},
}
_ => {}
}
false
}
@ -205,7 +229,11 @@ impl Component for ContactList {
self.mode = ViewMode::Close(uuid);
}
fn get_shortcuts(&self, context: &Context) -> ShortcutMap {
let mut map = self.view.as_ref().map(|p| p.get_shortcuts(context)).unwrap_or_default();
let mut map = self
.view
.as_ref()
.map(|p| p.get_shortcuts(context))
.unwrap_or_default();
let config_map = context.settings.shortcuts.contact_list.key_values();
map.insert("create_contact", (*config_map["create_contact"]).clone());

3
ui/src/components/indexer.rs

@ -58,8 +58,7 @@ impl Default for Indexer {
}
impl Indexer {
fn draw_menu(&mut self, _grid: &mut CellBuffer, _area: Area, _context: &mut Context) {
}
fn draw_menu(&mut self, _grid: &mut CellBuffer, _area: Area, _context: &mut Context) {}
}
impl Component for Indexer {

2
ui/src/components/indexer/index.rs

@ -42,7 +42,7 @@ impl Index {
let bg_color = if self.cursor_pos == idx {
Color::Byte(246)
/* } else if idx % 2 == 0 {
Color::Byte(236)*/
Color::Byte(236)*/
} else {
Color::Default
};

3
ui/src/components/mail.rs

@ -73,7 +73,8 @@ impl AccountMenu {
}
entries
},
}).collect();
})
.collect();
AccountMenu {
accounts,
dirty: true,

40
ui/src/components/mail/accounts.rs

@ -35,7 +35,6 @@ impl fmt::Display for AccountsPanel {
}
}
impl Component for AccountsPanel {
fn draw(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) {
if self.dirty {
@ -46,26 +45,26 @@ impl Component for AccountsPanel {
Color::Default,
((2, 3), (120 - 1, 3)),
true,
);
);
for (i, a) in context.accounts.iter().enumerate() {
create_box(&mut self.content, ((2,5+i*10 ), (120-1, 15+i*10)));
create_box(&mut self.content, ((2, 5 + i * 10), (120 - 1, 15 + i * 10)));
let (x, y) = write_string_to_grid(
a.name(),
&mut self.content,
Color::Default,
Color::Default,
((3, 5 + i*10), (120 - 2, 5 + i*10)),
((3, 5 + i * 10), (120 - 2, 5 + i * 10)),
true,
);
);
write_string_to_grid(
" โ–’โ–ˆโ–ˆโ–’ ",
&mut self.content,
Color::Byte(32),
Color::Default,
((x, y), (120 - 2, 5 + i*10)),
((x, y), (120 - 2, 5 + i * 10)),
true,
);
);
write_string_to_grid(
&a.runtime_settings.account().identity,
&mut self.content,
@ -73,10 +72,10 @@ impl Component for AccountsPanel {
Color::Default,
((4, y + 2), (120 - 2, y + 2)),
true,
);
);
if i == self.cursor {
for h in 1..8 {
self.content[(2, h+y+1)].set_ch('*');
self.content[(2, h + y + 1)].set_ch('*');
}
}
write_string_to_grid(
@ -86,7 +85,7 @@ impl Component for AccountsPanel {
Color::Default,
((5, y + 3), (120 - 2, y + 3)),
true,
);
);
write_string_to_grid(
"- Contacts",
&mut self.content,
@ -94,7 +93,7 @@ impl Component for AccountsPanel {
Color::Default,
((5, y + 4), (120 - 2, y + 4)),
true,
);
);
write_string_to_grid(
"- Mailing Lists",
&mut self.content,
@ -102,10 +101,7 @@ impl Component for AccountsPanel {
Color::Default,
((5, y + 5), (120 - 2, y + 5)),
true,
);
);
}
self.dirty = false;
}
@ -121,22 +117,24 @@ impl Component for AccountsPanel {
self.cursor = self.cursor.saturating_sub(1);
self.dirty = true;
return true;
},
}
UIEventType::Input(Key::Down) => {
if self.cursor + 1 < context.accounts.len() {
self.cursor += 1;
self.dirty = true;
}
return true;
},
}
UIEventType::Input(Key::Char('\n')) => {
context.replies.push_back(UIEvent {
id: 0,
event_type: UIEventType::Action(Tab(TabOpen(Some(Box::new(ContactList::for_account(self.cursor)))
)))});
event_type: UIEventType::Action(Tab(TabOpen(Some(Box::new(
ContactList::for_account(self.cursor),
))))),
});
return true;
},
_ => {},
}
_ => {}
}
false

260
ui/src/components/mail/compose.rs

@ -24,7 +24,6 @@ use super::*;
use melib::Draft;
use std::str::FromStr;
#[derive(Debug, PartialEq)]
enum Cursor {
Headers,
@ -173,10 +172,15 @@ impl Composer {
let account_cursor = self.account_cursor;
for &k in &["Date", "From", "To", "Cc", "Bcc", "Subject"] {
if k == "To" {
self.form.push_cl((k.into(), headers[k].to_string(), Box::new(move |c, term| {
let book: &AddressBook = &c.accounts[account_cursor].address_book;
let results: Vec<String> = book.search(term);
results})));
self.form.push_cl((
k.into(),
headers[k].to_string(),
Box::new(move |c, term| {
let book: &AddressBook = &c.accounts[account_cursor].address_book;
let results: Vec<String> = book.search(term);
results
}),
));
} else {
self.form.push((k.into(), headers[k].to_string()));
}
@ -184,36 +188,36 @@ impl Composer {
}
/*
let (x, y) = if k == "From" {
write_string_to_grid(
"โ—€ ",
grid,
Color::Byte(251),
Color::Default,
((x, y), set_y(bottom_right, y)),
true,
)
} else {
(x, y)
};
let (x, y) = write_string_to_grid(
&headers[k],
grid,
Color::Default,
bg_color,
((x, y), set_y(bottom_right, y)),
true,
);
if k == "From" {
write_string_to_grid(
" โ–ถ",
grid,
Color::Byte(251),
Color::Default,
((x, y), set_y(bottom_right, y)),
true,
)
*/
let (x, y) = if k == "From" {
write_string_to_grid(
"โ—€ ",
grid,
Color::Byte(251),
Color::Default,