From 99fbac3806455b2c4dd8180719515129b01ed22f Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Thu, 23 Jul 2020 13:39:58 +0300 Subject: [PATCH] Remove unused variables/functions --- melib/src/collection.rs | 2 - src/components/contacts/contact_list.rs | 4 +- src/components/mail/listing/compact.rs | 13 ++---- src/components/mail/listing/plain.rs | 13 +++--- src/components/mail/listing/thread.rs | 60 +++++-------------------- src/conf/accounts.rs | 2 +- src/plugins/backend.rs | 2 +- 7 files changed, 24 insertions(+), 72 deletions(-) diff --git a/melib/src/collection.rs b/melib/src/collection.rs index 1b911257..bbf0ac5d 100644 --- a/melib/src/collection.rs +++ b/melib/src/collection.rs @@ -21,7 +21,6 @@ use super::*; use crate::backends::MailboxHash; -use core::ops::{Index, IndexMut}; use smallvec::SmallVec; use std::ops::{Deref, DerefMut}; use std::sync::{Arc, RwLock, RwLockReadGuard, RwLockWriteGuard}; @@ -490,7 +489,6 @@ impl Collection { } } - pub struct RwRef<'g, K: std::cmp::Eq + std::hash::Hash, V> { guard: RwLockReadGuard<'g, HashMap>, hash: K, diff --git a/src/components/contacts/contact_list.rs b/src/components/contacts/contact_list.rs index 6f34a8cc..ab745e0f 100644 --- a/src/components/contacts/contact_list.rs +++ b/src/components/contacts/contact_list.rs @@ -24,8 +24,6 @@ use crate::melib::text_processing::TextProcessing; use melib::CardId; use std::cmp; -const MAX_COLS: usize = 500; - #[derive(Debug, PartialEq)] enum ViewMode { List, @@ -220,7 +218,7 @@ impl ContactList { self.theme_default.fg, self.theme_default.bg, self.theme_default.attrs, - ((0, 0), (MAX_COLS - 1, 0)), + ((0, 0), (message.len() - 1, 0)), None, ); return; diff --git a/src/components/mail/listing/compact.rs b/src/components/mail/listing/compact.rs index e34a8196..3635e76b 100644 --- a/src/components/mail/listing/compact.rs +++ b/src/components/mail/listing/compact.rs @@ -27,8 +27,6 @@ use std::cmp; use std::convert::TryInto; use std::iter::FromIterator; -const MAX_COLS: usize = 500; - macro_rules! address_list { (($name:expr) as comma_sep_list) => {{ let mut ret: String = @@ -240,7 +238,7 @@ impl MailListingTrait for CompactListing { self.color_cache.theme_default.fg, self.color_cache.theme_default.bg, self.color_cache.theme_default.attrs, - ((0, 0), (MAX_COLS - 1, 0)), + ((0, 0), (message.len() - 1, 0)), None, ); return; @@ -435,7 +433,7 @@ impl MailListingTrait for CompactListing { self.color_cache.theme_default.fg, self.color_cache.theme_default.bg, self.color_cache.theme_default.attrs, - ((0, 0), (MAX_COLS - 1, 0)), + ((0, 0), (message.len() - 1, 0)), None, ); } @@ -1337,13 +1335,10 @@ impl CompactListing { "Encountered an error while searching for `{}`: {}.", search_term, err ); - log( - format!("Failed to search for term {}: {}", search_term, err), - ERROR, - ); + log(message.clone(), ERROR); context.replies.push_back(UIEvent::Notification( Some("Could not perform search".to_string()), - err.to_string(), + message, Some(crate::types::NotificationType::ERROR), )); } diff --git a/src/components/mail/listing/plain.rs b/src/components/mail/listing/plain.rs index 21d16f8f..402b3e27 100644 --- a/src/components/mail/listing/plain.rs +++ b/src/components/mail/listing/plain.rs @@ -26,8 +26,6 @@ use crate::jobs::{oneshot, JobId, JoinHandle}; use std::cmp; use std::iter::FromIterator; -const MAX_COLS: usize = 500; - macro_rules! address_list { (($name:expr) as comma_sep_list) => {{ let mut ret: String = @@ -163,7 +161,7 @@ impl MailListingTrait for PlainListing { self.color_cache.theme_default.fg, self.color_cache.theme_default.bg, self.color_cache.theme_default.attrs, - ((0, 0), (MAX_COLS - 1, 0)), + ((0, 0), (message.len().saturating_sub(1), 0)), None, ); return; @@ -982,7 +980,7 @@ impl PlainListing { self.color_cache.theme_default.fg, self.color_cache.theme_default.bg, self.color_cache.theme_default.attrs, - ((0, 0), (MAX_COLS - 1, 0)), + ((0, 0), (message.len() - 1, 0)), None, ); } @@ -1296,10 +1294,9 @@ impl Component for PlainListing { let (chan, handle, job_id) = context.accounts[self.cursor_pos.0] .job_executor .spawn_specialized(job); - context.accounts[self.cursor_pos.0].active_jobs.insert( - job_id, - crate::conf::accounts::JobRequest::Search(handle), - ); + context.accounts[self.cursor_pos.0] + .active_jobs + .insert(job_id, crate::conf::accounts::JobRequest::Search(handle)); self.search_job = Some((filter_term.to_string(), chan, job_id)); } Err(err) => { diff --git a/src/components/mail/listing/thread.rs b/src/components/mail/listing/thread.rs index 10f7df66..0be1ba7c 100644 --- a/src/components/mail/listing/thread.rs +++ b/src/components/mail/listing/thread.rs @@ -24,8 +24,6 @@ use crate::components::utilities::PageMovement; use std::cmp; use std::convert::TryInto; -const MAX_COLS: usize = 500; - /// A list of all mail (`Envelope`s) in a `Mailbox`. On `\n` it opens the `Envelope` content in a /// `MailView`. #[derive(Debug)] @@ -106,18 +104,18 @@ impl MailListingTrait for ThreadListing { }; let message: String = context.accounts[self.cursor_pos.0][&self.cursor_pos.1].status(); + self.data_columns.columns[0] = + CellBuffer::new_with_context(message.len(), 1, default_cell, context); self.length = 0; - /* write_string_to_grid( message.as_str(), - &mut self.content, + &mut self.data_columns.columns[0], self.color_cache.theme_default.fg, self.color_cache.theme_default.bg, self.color_cache.theme_default.attrs, - ((0, 0), (MAX_COLS - 1, 0)), + ((0, 0), (message.len().saturating_sub(1), 0)), None, ); - */ return; } } @@ -155,18 +153,17 @@ impl MailListingTrait for ThreadListing { }; if threads.len() == 0 { let message = format!("Mailbox `{}` is empty.", account[&self.cursor_pos.1].name()); - /* - self.content = CellBuffer::new_with_context(message.len(), 1, default_cell, context); + self.data_columns.columns[0] = + CellBuffer::new_with_context(message.len(), 1, default_cell, context); write_string_to_grid( - &message, - &mut self.content, + message.as_str(), + &mut self.data_columns.columns[0], self.color_cache.theme_default.fg, self.color_cache.theme_default.bg, self.color_cache.theme_default.attrs, ((0, 0), (message.len() - 1, 0)), None, ); - */ return; } let mut rows = Vec::with_capacity(1024); @@ -186,9 +183,6 @@ impl MailListingTrait for ThreadListing { ); let mut indentations: Vec = Vec::with_capacity(6); - let mut thread_idx = 0; // needed for alternate thread colors - /* Draw threaded view. */ - let roots = items .filter_map(|r| threads.groups[&r].root().map(|r| r.root)) .collect::<_>(); @@ -200,9 +194,6 @@ impl MailListingTrait for ThreadListing { while let Some((indentation, thread_node_hash, has_sibling)) = iter.next() { let thread_node = &thread_nodes[&thread_node_hash]; - if indentation == 0 { - thread_idx += 1; - } if thread_node.has_message() { let envelope: EnvelopeRef = account.collection.get_env(thread_node.message().unwrap()); @@ -225,7 +216,6 @@ impl MailListingTrait for ThreadListing { let mut entry_strings = self.make_entry_string(&envelope, context); entry_strings.subject = SubjectString(ThreadListing::make_thread_entry( &envelope, - idx, indentation, thread_node_hash, &threads, @@ -693,7 +683,9 @@ impl ThreadListing { } } - fn highlight_line_self(&mut self, idx: usize, context: &Context) { + fn highlight_line_self(&mut self, _idx: usize, _context: &Context) { + /* + * FIXME if self.length == 0 { return; } @@ -703,23 +695,11 @@ impl ThreadListing { .collection .get_env(env_hash); - let fg_color = if !envelope.is_seen() { - Color::Byte(0) - } else { - Color::Default - }; - let bg_color = if !envelope.is_seen() { - Color::Byte(251) - } else if idx % 2 == 0 { - Color::Byte(236) - } else { - Color::Default - }; + */ } fn make_thread_entry( envelope: &Envelope, - idx: usize, indent: usize, node_idx: ThreadNodeHash, threads: &Threads, @@ -779,21 +759,6 @@ impl ThreadListing { .0 } - fn format_date(envelope: &Envelope) -> String { - let d = std::time::UNIX_EPOCH + std::time::Duration::from_secs(envelope.date()); - let now: std::time::Duration = std::time::SystemTime::now() - .duration_since(d) - .unwrap_or_else(|_| std::time::Duration::new(std::u64::MAX, 0)); - match now.as_secs() { - n if n < 10 * 60 * 60 => format!("{} hours ago{}", n / (60 * 60), " ".repeat(8)), - n if n < 24 * 60 * 60 => format!("{} hours ago{}", n / (60 * 60), " ".repeat(7)), - n if n < 4 * 24 * 60 * 60 => { - format!("{} days ago{}", n / (24 * 60 * 60), " ".repeat(9)) - } - _ => melib::datetime::timestamp_to_string(envelope.datetime(), None), - } - } - fn make_entry_string(&self, e: &Envelope, context: &Context) -> EntryStrings { let mut tags = String::new(); let mut colors: SmallVec<[_; 8]> = SmallVec::new(); @@ -855,7 +820,6 @@ impl ThreadListing { self.data_columns.columns[3].size().0, self.data_columns.columns[4].size().0, ); - let account = &context.accounts[self.cursor_pos.0]; for ((idx, is_seen, has_attachments, env_hash), strings) in self.rows.iter().skip(start).take(end - start + 1) diff --git a/src/conf/accounts.rs b/src/conf/accounts.rs index c6572417..01437a11 100644 --- a/src/conf/accounts.rs +++ b/src/conf/accounts.rs @@ -33,7 +33,7 @@ use melib::backends::{ use melib::email::*; use melib::error::{MeliError, Result}; use melib::text_processing::GlobMatch; -use melib::thread::{SortField, SortOrder, ThreadNode, ThreadNodeHash, Threads}; +use melib::thread::{SortField, SortOrder, Threads}; use melib::AddressBook; use melib::Collection; use smallvec::SmallVec; diff --git a/src/plugins/backend.rs b/src/plugins/backend.rs index fc6429cf..15833a5e 100644 --- a/src/plugins/backend.rs +++ b/src/plugins/backend.rs @@ -98,7 +98,7 @@ impl MailBackend for PluginBackend { } } - fn fetch(&mut self, mailbox_hash: MailboxHash) -> Result>>> { + fn fetch(&mut self, _mailbox_hash: MailboxHash) -> Result>>> { let mut w = AsyncBuilder::new(); let channel = self.channel.clone(); let handle = {