diff options
author | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-04-04 14:24:05 +0300 |
---|---|---|
committer | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-06-10 19:40:42 +0300 |
commit | ee4462881e2a0c9fdbb12fe0e33067e3052ef04d (patch) | |
tree | 0227eb4e1a2183b504ddc02be51288946a60f495 /ui/src | |
parent | 1c7aa0ec9c8b3c80f7844a315fc002294b198aa5 (diff) |
run cargo fmt
Diffstat (limited to 'ui/src')
-rw-r--r-- | ui/src/components/contacts/contact_list.rs | 22 | ||||
-rw-r--r-- | ui/src/components/mail/compose.rs | 25 | ||||
-rw-r--r-- | ui/src/components/mail/listing.rs | 6 | ||||
-rw-r--r-- | ui/src/components/mail/listing/compact.rs | 18 | ||||
-rw-r--r-- | ui/src/components/mail/listing/plain.rs | 11 | ||||
-rw-r--r-- | ui/src/components/mail/listing/thread.rs | 17 | ||||
-rw-r--r-- | ui/src/components/mail/view.rs | 75 | ||||
-rw-r--r-- | ui/src/components/mail/view/thread.rs | 72 | ||||
-rw-r--r-- | ui/src/components/utilities.rs | 8 | ||||
-rw-r--r-- | ui/src/conf/accounts.rs | 6 | ||||
-rw-r--r-- | ui/src/state.rs | 4 | ||||
-rw-r--r-- | ui/src/types.rs | 4 |
12 files changed, 164 insertions, 104 deletions
diff --git a/ui/src/components/contacts/contact_list.rs b/ui/src/components/contacts/contact_list.rs index 8932650d..3554b5b5 100644 --- a/ui/src/components/contacts/contact_list.rs +++ b/ui/src/components/contacts/contact_list.rs @@ -74,7 +74,12 @@ impl ContactList { if self.id_positions.capacity() < book.len() { self.id_positions.reserve(book.len()); } - let mut maxima = ("First Name".len(), "Last Name".len(), "E-mail".len(), "URL".len()); + let mut maxima = ( + "First Name".len(), + "Last Name".len(), + "E-mail".len(), + "URL".len(), + ); for c in book.values() { self.id_positions.push(*c.id()); @@ -94,7 +99,7 @@ impl ContactList { Color::Default, ((0, 0), (MAX_COLS - 1, self.length)), false, - ); + ); write_string_to_grid( "Last Name", &mut self.content, @@ -102,15 +107,15 @@ impl ContactList { Color::Default, ((maxima.0, 0), (MAX_COLS - 1, self.length)), false, - ); + ); write_string_to_grid( "E-mail", &mut self.content, Color::Default, Color::Default, - (( maxima.1, 0), (MAX_COLS - 1, self.length)), + ((maxima.1, 0), (MAX_COLS - 1, self.length)), false, - ); + ); write_string_to_grid( "URL", &mut self.content, @@ -118,7 +123,7 @@ impl ContactList { Color::Default, ((maxima.2, 0), (MAX_COLS - 1, self.length)), false, - ); + ); for (i, c) in book.values().enumerate() { self.id_positions.push(*c.id()); @@ -143,12 +148,13 @@ impl ContactList { &mut self.content, Color::Default, Color::Default, - (( maxima.1, i + 1), (MAX_COLS - 1, self.length)), + ((maxima.1, i + 1), (MAX_COLS - 1, self.length)), false, ); write_string_to_grid( c.url(), - &mut self.content, Color::Default, + &mut self.content, + Color::Default, Color::Default, ((maxima.2, i + 1), (MAX_COLS - 1, self.length)), false, diff --git a/ui/src/components/mail/compose.rs b/ui/src/components/mail/compose.rs index ac1f2929..268bd444 100644 --- a/ui/src/components/mail/compose.rs +++ b/ui/src/components/mail/compose.rs @@ -426,7 +426,7 @@ impl Component for Composer { fn process_event(&mut self, event: &mut UIEvent, context: &mut Context) -> bool { match (&mut self.mode, &mut self.reply_context, &event.event_type) { // don't pass Reply command to thread view in reply_context - (_, _, UIEventType::Input(Key::Char('R'))) => {}, + (_, _, UIEventType::Input(Key::Char('R'))) => {} (ViewMode::Overview, Some((_, ref mut view)), _) => { if view.process_event(event, context) { self.dirty = true; @@ -501,7 +501,10 @@ impl Component for Composer { } context.replies.push_back(UIEvent { id: 0, - event_type: UIEventType::Notification(Some("Could not save draft.".into()), e.into()) + event_type: UIEventType::Notification( + Some("Could not save draft.".into()), + e.into(), + ), }); } context.replies.push_back(UIEvent { @@ -607,8 +610,7 @@ impl Component for Composer { fn get_shortcuts(&self, context: &Context) -> ShortcutMap { let mut map = if self.mode.is_overview() { - self.pager - .get_shortcuts(context) + self.pager.get_shortcuts(context) } else { Default::default() }; @@ -619,21 +621,12 @@ impl Component for Composer { } if self.mode.is_overview() { - map.insert( - "Switch to edit mode", - Key::Char('o') - ); + map.insert("Switch to edit mode", Key::Char('o')); } if self.mode.is_edit() { - map.insert( - "Switch to overview", - Key::Char('v') - ); + map.insert("Switch to overview", Key::Char('v')); } - map.insert( - "Edit in $EDITOR", - Key::Char('e') - ); + map.insert("Edit in $EDITOR", Key::Char('e')); map } diff --git a/ui/src/components/mail/listing.rs b/ui/src/components/mail/listing.rs index 3f538483..9e2371d7 100644 --- a/ui/src/components/mail/listing.rs +++ b/ui/src/components/mail/listing.rs @@ -83,7 +83,7 @@ impl Component for Listing { Listing::Plain(_) => { return true; } - Listing::Threaded(l) => { + Listing::Threaded(l) => { let mut new_l = PlainListing::default(); new_l.set_coordinates(l.coordinates()); new_l @@ -102,7 +102,7 @@ impl Component for Listing { Listing::Threaded(_) => { return true; } - Listing::Plain(l) => { + Listing::Plain(l) => { let mut new_l = ThreadListing::default(); new_l.set_coordinates(l.coordinates()); new_l @@ -121,7 +121,7 @@ impl Component for Listing { Listing::Compact(_) => { return true; } - Listing::Threaded(l) => { + Listing::Threaded(l) => { let mut new_l = CompactListing::default(); new_l.set_coordinates(l.coordinates()); new_l diff --git a/ui/src/components/mail/listing/compact.rs b/ui/src/components/mail/listing/compact.rs index 17ab9e54..a748c372 100644 --- a/ui/src/components/mail/listing/compact.rs +++ b/ui/src/components/mail/listing/compact.rs @@ -275,7 +275,8 @@ impl CompactListing { /// Draw the list of `Envelope`s. fn draw_list(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) { - if self.cursor_pos.1 != self.new_cursor_pos.1 || self.cursor_pos.0 != self.new_cursor_pos.0 { + if self.cursor_pos.1 != self.new_cursor_pos.1 || self.cursor_pos.0 != self.new_cursor_pos.0 + { self.refresh_mailbox(context); } let upper_left = upper_left!(area); @@ -484,11 +485,15 @@ impl Component for CompactListing { UIEventType::RefreshMailbox(_) => { self.dirty = true; } - UIEventType::MailboxUpdate((ref idxa, ref idxf)) if *idxa == self.new_cursor_pos.0 && *idxf == self.new_cursor_pos.1 => { + UIEventType::MailboxUpdate((ref idxa, ref idxf)) + if *idxa == self.new_cursor_pos.0 && *idxf == self.new_cursor_pos.1 => + { self.refresh_mailbox(context); self.set_dirty(); } - UIEventType::StartupCheck(ref f) if context.mailbox_hashes[f] == (self.new_cursor_pos.0, self.new_cursor_pos.1) => { + UIEventType::StartupCheck(ref f) + if context.mailbox_hashes[f] == (self.new_cursor_pos.0, self.new_cursor_pos.1) => + { self.refresh_mailbox(context); self.set_dirty(); } @@ -534,7 +539,12 @@ impl Component for CompactListing { false } fn is_dirty(&self) -> bool { - self.dirty || if self.unfocused { self.view.is_dirty() } else { false } + self.dirty + || if self.unfocused { + self.view.is_dirty() + } else { + false + } } fn set_dirty(&mut self) { if self.unfocused { diff --git a/ui/src/components/mail/listing/plain.rs b/ui/src/components/mail/listing/plain.rs index 16368f95..27801887 100644 --- a/ui/src/components/mail/listing/plain.rs +++ b/ui/src/components/mail/listing/plain.rs @@ -252,7 +252,8 @@ impl PlainListing { /// Draw the list of `Envelope`s. fn draw_list(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) { - if self.cursor_pos.1 != self.new_cursor_pos.1 || self.cursor_pos.0 != self.new_cursor_pos.0 { + if self.cursor_pos.1 != self.new_cursor_pos.1 || self.cursor_pos.0 != self.new_cursor_pos.0 + { self.refresh_mailbox(context); } let upper_left = upper_left!(area); @@ -502,11 +503,15 @@ impl Component for PlainListing { self.dirty = true; self.view = None; } - UIEventType::MailboxUpdate((ref idxa, ref idxf)) if *idxa == self.new_cursor_pos.0 && *idxf == self.new_cursor_pos.1 => { + UIEventType::MailboxUpdate((ref idxa, ref idxf)) + if *idxa == self.new_cursor_pos.0 && *idxf == self.new_cursor_pos.1 => + { self.refresh_mailbox(context); self.set_dirty(); } - UIEventType::StartupCheck(ref f) if context.mailbox_hashes[f] == (self.new_cursor_pos.0, self.new_cursor_pos.1) => { + UIEventType::StartupCheck(ref f) + if context.mailbox_hashes[f] == (self.new_cursor_pos.0, self.new_cursor_pos.1) => + { self.refresh_mailbox(context); self.set_dirty(); } diff --git a/ui/src/components/mail/listing/thread.rs b/ui/src/components/mail/listing/thread.rs index 029e5a1c..d1f55aba 100644 --- a/ui/src/components/mail/listing/thread.rs +++ b/ui/src/components/mail/listing/thread.rs @@ -48,7 +48,11 @@ pub struct ThreadListing { impl ListingTrait for ThreadListing { fn coordinates(&self) -> (usize, usize, Option<EnvelopeHash>) { - (self.cursor_pos.0, self.cursor_pos.1, Some(self.locations[self.cursor_pos.2])) + ( + self.cursor_pos.0, + self.cursor_pos.1, + Some(self.locations[self.cursor_pos.2]), + ) } fn set_coordinates(&mut self, coordinates: (usize, usize, Option<EnvelopeHash>)) { self.new_cursor_pos = (coordinates.0, coordinates.1, 0); @@ -291,7 +295,8 @@ impl ThreadListing { /// Draw the list of `Envelope`s. fn draw_list(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) { - if self.cursor_pos.1 != self.new_cursor_pos.1 || self.cursor_pos.0 != self.new_cursor_pos.0 { + if self.cursor_pos.1 != self.new_cursor_pos.1 || self.cursor_pos.0 != self.new_cursor_pos.0 + { self.refresh_mailbox(context); } let upper_left = upper_left!(area); @@ -660,11 +665,15 @@ impl Component for ThreadListing { self.dirty = true; self.view = None; } - UIEventType::MailboxUpdate((ref idxa, ref idxf)) if *idxa == self.new_cursor_pos.0 && *idxf == self.new_cursor_pos.1 => { + UIEventType::MailboxUpdate((ref idxa, ref idxf)) + if *idxa == self.new_cursor_pos.0 && *idxf == self.new_cursor_pos.1 => + { self.refresh_mailbox(context); self.set_dirty(); } - UIEventType::StartupCheck(ref f) if context.mailbox_hashes[f] == (self.new_cursor_pos.0, self.new_cursor_pos.1) => { + UIEventType::StartupCheck(ref f) + if context.mailbox_hashes[f] == (self.new_cursor_pos.0, self.new_cursor_pos.1) => + { self.refresh_mailbox(context); self.set_dirty(); } diff --git a/ui/src/components/mail/view.rs b/ui/src/components/mail/view.rs index 5e74ecfe..d2549330 100644 --- a/ui/src/components/mail/view.rs +++ b/ui/src/components/mail/view.rs @@ -88,10 +88,7 @@ impl MailView { let account = &mut context.accounts[coordinates.0]; let (hash, is_seen) = { let mailbox = &mut account[coordinates.1].as_mut().unwrap(); - let envelope: &mut Envelope = &mut mailbox - .collection - .entry(coordinates.2) - .or_default(); + let envelope: &mut Envelope = &mut mailbox.collection.entry(coordinates.2).or_default(); (envelope.hash(), envelope.is_seen()) }; if !is_seen { @@ -104,10 +101,7 @@ impl MailView { backend.operation(hash, folder_hash) }; let mailbox = &mut account[coordinates.1].as_mut().unwrap(); - let envelope: &mut Envelope = &mut mailbox - .collection - .entry(coordinates.2) - .or_default(); + let envelope: &mut Envelope = &mut mailbox.collection.entry(coordinates.2).or_default(); envelope.set_seen(op).unwrap(); } MailView { @@ -428,34 +422,37 @@ impl Component for MailView { if let ViewMode::ContactSelector(_) = self.mode { if let ViewMode::ContactSelector(s) = std::mem::replace(&mut self.mode, ViewMode::Normal) + { + let account = &mut context.accounts[self.coordinates.0]; + let mut results = Vec::new(); { - let account = &mut context.accounts[self.coordinates.0]; - let mut results = Vec::new(); - { - let mailbox = &account[self.coordinates.1] - .as_ref() - .unwrap(); - let envelope: &Envelope = &mailbox.collection[&self.coordinates.2]; - for c in s.collect() { - let c = usize::from_ne_bytes({ - [c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7]] - }); - for (idx, env) in envelope.from().iter().chain(envelope.to().iter()).enumerate() { - if idx != c { - continue; - } - - let mut new_card: Card = Card::new(); - new_card.set_email(env.get_email()); - new_card.set_lastname(env.get_display_name()); - results.push(new_card); + let mailbox = &account[self.coordinates.1].as_ref().unwrap(); + let envelope: &Envelope = &mailbox.collection[&self.coordinates.2]; + for c in s.collect() { + let c = usize::from_ne_bytes({ + [c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7]] + }); + for (idx, env) in envelope + .from() + .iter() + .chain(envelope.to().iter()) + .enumerate() + { + if idx != c { + continue; } + + let mut new_card: Card = Card::new(); + new_card.set_email(env.get_email()); + new_card.set_lastname(env.get_display_name()); + results.push(new_card); } } - for c in results { - account.address_book.add_card(c); - } } + for c in results { + account.address_book.add_card(c); + } + } return true; } let accounts = &context.accounts; @@ -465,11 +462,13 @@ impl Component for MailView { let envelope: &Envelope = &mailbox.collection[&self.coordinates.2]; let mut entries = Vec::new(); - for (idx, env) in envelope.from().iter().chain(envelope.to().iter()).enumerate() { - entries.push(( - idx.to_ne_bytes().to_vec(), - format!("{}", env), - )); + for (idx, env) in envelope + .from() + .iter() + .chain(envelope.to().iter()) + .enumerate() + { + entries.push((idx.to_ne_bytes().to_vec(), format!("{}", env))); } self.mode = ViewMode::ContactSelector(Selector::new(entries, true)); self.dirty = true; @@ -651,7 +650,9 @@ impl Component for MailView { } self.dirty = true; } - UIEventType::EnvelopeRename(_, old_hash, new_hash) if old_hash == self.coordinates.2 => { + UIEventType::EnvelopeRename(_, old_hash, new_hash) + if old_hash == self.coordinates.2 => + { self.coordinates.2 = new_hash; self.set_dirty(); } diff --git a/ui/src/components/mail/view/thread.rs b/ui/src/components/mail/view/thread.rs index dfad1fd2..2edb0ed3 100644 --- a/ui/src/components/mail/view/thread.rs +++ b/ui/src/components/mail/view/thread.rs @@ -79,9 +79,11 @@ impl ThreadView { if self.entries.is_empty() { return; } - let old_focused_entry = if self.entries.len() > self.cursor_pos { + let old_focused_entry = if self.entries.len() > self.cursor_pos { Some(self.entries.remove(self.cursor_pos)) - } else { None }; + } else { + None + }; let old_expanded_entry = if self.entries.len() > self.expanded_pos { Some(self.entries.remove(self.expanded_pos)) @@ -93,21 +95,24 @@ impl ThreadView { let expanded_pos = self.expanded_pos; self.initiate(Some(expanded_pos), context); if let Some(old_focused_entry) = old_focused_entry { - if let Some(new_entry_idx) = self.entries.iter().position( - |e| e.msg_idx == old_focused_entry.msg_idx || - (e.index.1 == old_focused_entry.index.1 && e.index.2 == old_focused_entry.index.2)) { + if let Some(new_entry_idx) = self.entries.iter().position(|e| { + e.msg_idx == old_focused_entry.msg_idx + || (e.index.1 == old_focused_entry.index.1 + && e.index.2 == old_focused_entry.index.2) + }) { self.cursor_pos = new_entry_idx; } } if let Some(old_expanded_entry) = old_expanded_entry { - if let Some(new_entry_idx) = self.entries.iter().position( - |e| e.msg_idx == old_expanded_entry.msg_idx || - (e.index.1 == old_expanded_entry.index.1 && e.index.2 == old_expanded_entry.index.2)) { + if let Some(new_entry_idx) = self.entries.iter().position(|e| { + e.msg_idx == old_expanded_entry.msg_idx + || (e.index.1 == old_expanded_entry.index.1 + && e.index.2 == old_expanded_entry.index.2) + }) { self.expanded_pos = new_entry_idx; } } self.set_dirty(); - } fn initiate(&mut self, expanded_idx: Option<usize>, context: &Context) { /* stack to push thread messages in order in order to pop and print them later */ @@ -183,12 +188,14 @@ impl ThreadView { if content[index].ch() == ' ' { let mut ctr = 1; while content.get(e.index.0 * 4 + ctr, 2 * y - 1).is_some() { - if content[(e.index.0 * 4 + ctr, 2 * y - 1)].ch() != ' ' { break; } + if content[(e.index.0 * 4 + ctr, 2 * y - 1)].ch() != ' ' { + break; + } set_and_join_box( &mut content, (e.index.0 * 4 + ctr, 2 * y - 1), HORZ_BOUNDARY, - ); + ); ctr += 1; } set_and_join_box(&mut content, index, HORZ_BOUNDARY); @@ -197,11 +204,19 @@ impl ThreadView { write_string_to_grid( &strings[y], &mut content, - if e.seen { Color::Default } else { Color::Byte(0) }, - if e.seen { Color::Default } else { Color::Byte(251) }, + if e.seen { + Color::Default + } else { + Color::Byte(0) + }, + if e.seen { + Color::Default + } else { + Color::Byte(251) + }, ((e.index.0 * 4 + 1, 2 * y), (width - 1, height - 1)), true, - ); + ); if let Some(len) = highlight_reply_subjects[y] { let index = e.index.0 * 4 + 1 + strings[y].len() - len; let area = ((index, 2 * y), (width - 2, 2 * y)); @@ -225,12 +240,14 @@ impl ThreadView { if content[index].ch() == ' ' { let mut ctr = 1; while content.get(e.index.0 * 4 + ctr, 2 * y - 1).is_some() { - if content[(e.index.0 * 4 + ctr, 2 * y - 1)].ch() != ' ' { break; } + if content[(e.index.0 * 4 + ctr, 2 * y - 1)].ch() != ' ' { + break; + } set_and_join_box( &mut content, (e.index.0 * 4 + ctr, 2 * y - 1), HORZ_BOUNDARY, - ); + ); ctr += 1; } set_and_join_box(&mut content, index, HORZ_BOUNDARY); @@ -239,11 +256,19 @@ impl ThreadView { write_string_to_grid( &strings[y], &mut content, - if e.seen { Color::Default } else { Color::Byte(0) }, - if e.seen { Color::Default } else { Color::Byte(251) }, + if e.seen { + Color::Default + } else { + Color::Byte(0) + }, + if e.seen { + Color::Default + } else { + Color::Byte(251) + }, ((e.index.0 * 4 + 1, 2 * y), (width - 1, height - 1)), true, - ); + ); if let Some(len) = highlight_reply_subjects[y] { let index = e.index.0 * 4 + 1 + strings[y].len() - len; let area = ((index, 2 * y), (width - 2, 2 * y)); @@ -267,7 +292,12 @@ impl ThreadView { self.content = content; } - fn make_entry(&mut self, i: (usize, usize, usize), msg_idx: EnvelopeHash, seen: bool) -> ThreadEntry { + fn make_entry( + &mut self, + i: (usize, usize, usize), + msg_idx: EnvelopeHash, + seen: bool, + ) -> ThreadEntry { let (ind, _, _) = i; ThreadEntry { index: i, @@ -466,7 +496,6 @@ impl ThreadView { for x in get_x(upper_left)..=get_x(bottom_right) { set_and_join_box(grid, (x, y - 1), HORZ_BOUNDARY); } - } fn draw_horz(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) { let upper_left = upper_left!(area); @@ -577,7 +606,6 @@ impl ThreadView { self.initiated = true; } - if self.show_mailview { self.draw_list( grid, diff --git a/ui/src/components/utilities.rs b/ui/src/components/utilities.rs index bab024b6..53e6679c 100644 --- a/ui/src/components/utilities.rs +++ b/ui/src/components/utilities.rs @@ -200,7 +200,13 @@ impl Component for VSplit { } else { self.left.component.draw( grid, - (upper_left, (if self.show_divider { mid - 1 } else { mid }, get_y(bottom_right))), + ( + upper_left, + ( + if self.show_divider { mid - 1 } else { mid }, + get_y(bottom_right), + ), + ), context, ); self.right diff --git a/ui/src/conf/accounts.rs b/ui/src/conf/accounts.rs index aefa1cf3..56209299 100644 --- a/ui/src/conf/accounts.rs +++ b/ui/src/conf/accounts.rs @@ -23,13 +23,13 @@ * Account management from user configuration. */ -use melib::async_workers::{Async, AsyncStatus, AsyncBuilder}; use super::AccountConf; +use melib::async_workers::{Async, AsyncBuilder, AsyncStatus}; +use melib::error::Result; use melib::mailbox::backends::{ Backends, Folder, MailBackend, NotifyFn, RefreshEvent, RefreshEventConsumer, RefreshEventKind, }; use melib::mailbox::*; -use melib::error::Result; use melib::AddressBook; use std::fs; @@ -38,7 +38,7 @@ use std::mem; use std::ops::{Index, IndexMut}; use std::result; use std::sync::Arc; -use types::UIEventType::{self, Notification, EnvelopeUpdate, EnvelopeRename, EnvelopeRemove}; +use types::UIEventType::{self, EnvelopeRemove, EnvelopeRename, EnvelopeUpdate, Notification}; pub type Worker = Option<Async<Result<Mailbox>>>; diff --git a/ui/src/state.rs b/ui/src/state.rs index 723693b1..0ae49dca 100644 --- a/ui/src/state.rs +++ b/ui/src/state.rs @@ -282,7 +282,9 @@ impl State { .send(ThreadEvent::UIEvent(UIEventType::StartupCheck(hash))); self.context .sender - .send(ThreadEvent::UIEvent(UIEventType::MailboxUpdate((idxa, idxm)))); + .send(ThreadEvent::UIEvent(UIEventType::MailboxUpdate(( + idxa, idxm, + )))); self.context.replies.push_back(UIEvent { id: 0, event_type: notification, diff --git a/ui/src/types.rs b/ui/src/types.rs index 9f5b19ba..03a66210 100644 --- a/ui/src/types.rs +++ b/ui/src/types.rs @@ -26,9 +26,9 @@ pub use self::helpers::*; use super::execute::Action; use super::terminal::*; -use melib::RefreshEvent; -use melib::EnvelopeHash; use melib::backends::FolderHash; +use melib::EnvelopeHash; +use melib::RefreshEvent; use std; use std::fmt; use std::thread; |