diff --git a/meli/src/components.rs b/meli/src/components.rs index 9377ccd1..a22be5a1 100644 --- a/meli/src/components.rs +++ b/meli/src/components.rs @@ -38,9 +38,6 @@ pub use mail::*; pub mod notifications; -pub mod utilities; -pub use utilities::*; - pub mod contacts; pub use contacts::*; @@ -119,9 +116,9 @@ pub enum PageMovement { #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct ScrollContext { - shown_lines: usize, - total_lines: usize, - has_more_lines: bool, + pub shown_lines: usize, + pub total_lines: usize, + pub has_more_lines: bool, } #[derive(Debug, Clone, Copy)] @@ -275,8 +272,8 @@ impl Default for ComponentAttr { #[derive(Eq, PartialEq, Debug, Clone)] pub struct ComponentPath { - id: ComponentId, - tail: SmallVec<[ComponentId; 8]>, + pub id: ComponentId, + pub tail: SmallVec<[ComponentId; 8]>, } impl ComponentPath { diff --git a/meli/src/conf/terminal.rs b/meli/src/conf/terminal.rs index 9ace3952..4af1a23f 100644 --- a/meli/src/conf/terminal.rs +++ b/meli/src/conf/terminal.rs @@ -121,7 +121,7 @@ pub enum ProgressSpinnerSequence { } const fn interval_ms_val() -> u64 { - crate::components::utilities::ProgressSpinner::INTERVAL_MS + crate::utilities::ProgressSpinner::INTERVAL_MS } impl DotAddressable for ProgressSpinnerSequence {} diff --git a/meli/src/lib.rs b/meli/src/lib.rs index 9dfe6eb8..ff2bbcf6 100644 --- a/meli/src/lib.rs +++ b/meli/src/lib.rs @@ -74,6 +74,9 @@ pub use crate::state::*; pub mod components; pub use crate::components::*; +pub mod utilities; +pub use crate::utilities::*; + #[macro_use] pub mod conf; pub use crate::conf::{ diff --git a/meli/src/managesieve.rs b/meli/src/managesieve.rs index fb504a85..43ce9cfa 100644 --- a/meli/src/managesieve.rs +++ b/meli/src/managesieve.rs @@ -19,50 +19,17 @@ * along with meli. If not, see . */ -extern crate melib; -use std::collections::VecDeque; - -use melib::*; -#[macro_use] -extern crate serde_derive; extern crate linkify; - +extern crate meli; +extern crate melib; +extern crate serde_derive; extern crate serde_json; extern crate smallvec; extern crate termion; -use melib::{imap::managesieve::ManageSieveConnection, Result}; - -#[macro_use] -pub mod types; -use crate::types::*; - -#[macro_use] -pub mod terminal; -use crate::terminal::*; - -#[macro_use] -pub mod command; -use crate::command::*; - -pub mod state; -use crate::state::*; - -pub mod components; -use crate::components::*; - -#[macro_use] -pub mod conf; -use crate::conf::*; - -#[cfg(feature = "sqlite3")] -pub mod sqlite3; - -pub mod jobs; -pub mod mailcap; -//pub mod plugins; - use futures::executor::block_on; +use meli::*; +use melib::{imap::managesieve::ManageSieveConnection, Result, *}; /// Opens an interactive shell on a managesieve server. Suggested use is with /// rlwrap(1) @@ -84,7 +51,7 @@ fn main() -> Result<()> { let (config_path, account_name) = (std::mem::take(&mut args[0]), std::mem::take(&mut args[1])); std::env::set_var("MELI_CONFIG", config_path); - let settings = conf::Settings::new()?; + let settings = meli::conf::Settings::new()?; if !settings.accounts.contains_key(&account_name) { eprintln!( "Account not found. available accounts: {}", diff --git a/meli/src/terminal/cells.rs b/meli/src/terminal/cells.rs index 96569b30..96103415 100644 --- a/meli/src/terminal/cells.rs +++ b/meli/src/terminal/cells.rs @@ -1370,20 +1370,20 @@ impl RowIterator { pub use boundaries::create_box; pub mod boundaries { use super::*; - pub(crate) const HORZ_BOUNDARY: char = '─'; - pub(crate) const VERT_BOUNDARY: char = '│'; - pub(crate) const _TOP_LEFT_CORNER: char = '┌'; - pub(crate) const _TOP_RIGHT_CORNER: char = '┐'; - pub(crate) const _BOTTOM_LEFT_CORNER: char = '└'; - pub(crate) const _BOTTOM_RIGHT_CORNER: char = '┘'; - pub(crate) const LIGHT_VERTICAL_AND_RIGHT: char = '├'; - pub(crate) const _LIGHT_VERTICAL_AND_LEFT: char = '┤'; - pub(crate) const _LIGHT_DOWN_AND_HORIZONTAL: char = '┬'; - pub(crate) const _LIGHT_UP_AND_HORIZONTAL: char = '┴'; - pub(crate) const _DOUBLE_DOWN_AND_RIGHT: char = '╔'; - pub(crate) const _DOUBLE_DOWN_AND_LEFT: char = '╗'; - pub(crate) const _DOUBLE_UP_AND_LEFT: char = '╝'; - pub(crate) const _DOUBLE_UP_AND_RIGHT: char = '╚'; + pub const HORZ_BOUNDARY: char = '─'; + pub const VERT_BOUNDARY: char = '│'; + pub const _TOP_LEFT_CORNER: char = '┌'; + pub const _TOP_RIGHT_CORNER: char = '┐'; + pub const _BOTTOM_LEFT_CORNER: char = '└'; + pub const _BOTTOM_RIGHT_CORNER: char = '┘'; + pub const LIGHT_VERTICAL_AND_RIGHT: char = '├'; + pub const _LIGHT_VERTICAL_AND_LEFT: char = '┤'; + pub const _LIGHT_DOWN_AND_HORIZONTAL: char = '┬'; + pub const _LIGHT_UP_AND_HORIZONTAL: char = '┴'; + pub const _DOUBLE_DOWN_AND_RIGHT: char = '╔'; + pub const _DOUBLE_DOWN_AND_LEFT: char = '╗'; + pub const _DOUBLE_UP_AND_LEFT: char = '╝'; + pub const _DOUBLE_UP_AND_RIGHT: char = '╚'; fn bin_to_ch(b: u32) -> char { match b { @@ -1618,12 +1618,12 @@ pub mod boundaries { bin_set } - pub(crate) enum BoxBoundary { + pub enum BoxBoundary { Horizontal, Vertical, } - pub(crate) fn set_and_join_box(grid: &mut CellBuffer, idx: Pos, ch: BoxBoundary) { + pub fn set_and_join_box(grid: &mut CellBuffer, idx: Pos, ch: BoxBoundary) { /* Connected sides: * * 1 diff --git a/meli/src/components/utilities.rs b/meli/src/utilities.rs similarity index 99% rename from meli/src/components/utilities.rs rename to meli/src/utilities.rs index cf1bd516..df4c4e9e 100644 --- a/meli/src/components/utilities.rs +++ b/meli/src/utilities.rs @@ -45,8 +45,10 @@ pub use self::dialogs::*; mod tables; use std::collections::HashSet; +use indexmap::IndexMap; + pub use self::tables::*; -use crate::jobs::JobId; +use crate::{jobs::JobId, melib::text_processing::TextProcessing}; #[derive(Default, Debug, Clone)] pub struct SearchPattern { @@ -80,8 +82,8 @@ pub struct StatusBar { cmd_history: Vec, } -impl fmt::Display for StatusBar { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { +impl std::fmt::Display for StatusBar { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "status bar") } } @@ -947,8 +949,8 @@ impl Tabbed { } } -impl fmt::Display for Tabbed { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { +impl std::fmt::Display for Tabbed { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "tabs") } } @@ -1631,9 +1633,9 @@ pub struct RawBuffer { dirty: bool, } -impl fmt::Display for RawBuffer { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - Display::fmt("Raw buffer", f) +impl std::fmt::Display for RawBuffer { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + std::fmt::Display::fmt("Raw buffer", f) } } diff --git a/meli/src/components/utilities/dialogs.rs b/meli/src/utilities/dialogs.rs similarity index 97% rename from meli/src/components/utilities/dialogs.rs rename to meli/src/utilities/dialogs.rs index 4919b7a2..78a8ed5a 100644 --- a/meli/src/components/utilities/dialogs.rs +++ b/meli/src/utilities/dialogs.rs @@ -45,8 +45,10 @@ enum SelectorCursor { /// component, check Selector::is_done to see if the user has finalised their /// choices. Collect the choices by consuming the Selector with /// Selector::collect() -pub struct Selector -{ +pub struct Selector< + T: 'static + PartialEq + std::fmt::Debug + Clone + Sync + Send, + F: 'static + Sync + Send, +> { /// allow only one selection single_only: bool, entries: Vec<(T, bool)>, @@ -76,31 +78,31 @@ pub type UIDialog = Selector< Option Option + 'static + Sync + Send>>, >; -impl fmt::Debug - for Selector +impl + std::fmt::Debug for Selector { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - Display::fmt("Selector", f) + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + std::fmt::Display::fmt("Selector", f) } } -impl fmt::Display - for Selector +impl + std::fmt::Display for Selector { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - Display::fmt("Selector", f) + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + std::fmt::Display::fmt("Selector", f) } } -impl PartialEq - for Selector +impl + PartialEq for Selector { fn eq(&self, other: &Selector) -> bool { self.entries == other.entries } } -impl Component for UIDialog { +impl Component for UIDialog { fn draw(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) { Selector::draw(self, grid, area, context); } @@ -752,7 +754,9 @@ impl Component for UIConfirmationDialog { } } -impl Selector { +impl + Selector +{ pub fn new( title: &str, mut entries: Vec<(T, String)>, @@ -927,7 +931,7 @@ impl Selec } } -impl UIDialog { +impl UIDialog { fn done(&mut self) -> Option { let Self { ref mut done_fn, diff --git a/meli/src/components/utilities/layouts.rs b/meli/src/utilities/layouts.rs similarity index 94% rename from meli/src/components/utilities/layouts.rs rename to meli/src/utilities/layouts.rs index 5ce7cfdf..32e115af 100644 --- a/meli/src/components/utilities/layouts.rs +++ b/meli/src/utilities/layouts.rs @@ -20,6 +20,9 @@ */ use super::*; +use crate::terminal::cells::boundaries::{ + HORZ_BOUNDARY, VERT_BOUNDARY, _LIGHT_DOWN_AND_HORIZONTAL, _LIGHT_UP_AND_HORIZONTAL, +}; /// A horizontally split in half container. #[derive(Debug)] @@ -31,9 +34,9 @@ pub struct HSplit { id: ComponentId, } -impl fmt::Display for HSplit { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - Display::fmt(&self.top, f) +impl std::fmt::Display for HSplit { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + std::fmt::Display::fmt(&self.top, f) } } @@ -124,10 +127,10 @@ pub struct VSplit { id: ComponentId, } -impl fmt::Display for VSplit { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { +impl std::fmt::Display for VSplit { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { // [ref:TODO]: display focused component - Display::fmt(&self.right, f) + std::fmt::Display::fmt(&self.right, f) } } diff --git a/meli/src/components/utilities/pager.rs b/meli/src/utilities/pager.rs similarity index 99% rename from meli/src/components/utilities/pager.rs rename to meli/src/utilities/pager.rs index 698e553e..53387943 100644 --- a/meli/src/components/utilities/pager.rs +++ b/meli/src/utilities/pager.rs @@ -19,7 +19,7 @@ * along with meli. If not, see . */ -use melib::text_processing::LineBreakText; +use melib::text_processing::{LineBreakText, Truncate}; use super::*; @@ -56,8 +56,8 @@ pub struct Pager { id: ComponentId, } -impl fmt::Display for Pager { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { +impl std::fmt::Display for Pager { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "pager") } } diff --git a/meli/src/components/utilities/tables.rs b/meli/src/utilities/tables.rs similarity index 100% rename from meli/src/components/utilities/tables.rs rename to meli/src/utilities/tables.rs diff --git a/meli/src/components/utilities/text.rs b/meli/src/utilities/text.rs similarity index 97% rename from meli/src/components/utilities/text.rs rename to meli/src/utilities/text.rs index d64512c1..d6362303 100644 --- a/meli/src/components/utilities/text.rs +++ b/meli/src/utilities/text.rs @@ -20,6 +20,7 @@ */ use super::*; +use crate::melib::text_processing::Truncate; pub struct TextField { inner: UText, @@ -27,8 +28,8 @@ pub struct TextField { id: ComponentId, } -impl Debug for TextField { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { +impl std::fmt::Debug for TextField { + fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result { fmt.debug_struct(stringify!(TextField)) .field("id", &self.id) .field("inner", &self.inner) @@ -320,8 +321,8 @@ impl Component for TextField { } } -impl fmt::Display for TextField { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { +impl std::fmt::Display for TextField { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", self.as_str(),) } } diff --git a/meli/src/components/utilities/widgets.rs b/meli/src/utilities/widgets.rs similarity index 97% rename from meli/src/components/utilities/widgets.rs rename to meli/src/utilities/widgets.rs index 83347665..c304e654 100644 --- a/meli/src/components/utilities/widgets.rs +++ b/meli/src/utilities/widgets.rs @@ -22,6 +22,7 @@ use std::{borrow::Cow, collections::HashMap, time::Duration}; use super::*; +use crate::melib::text_processing::TextProcessing; #[derive(Debug, PartialEq, Eq, Default)] enum FormFocus { @@ -38,11 +39,11 @@ pub enum Field { Choice(Vec>, Cursor, ComponentId), } -impl Debug for Field { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { +impl std::fmt::Debug for Field { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { match self { - Self::Text(ref t) => fmt::Debug::fmt(t, f), - k => fmt::Debug::fmt(k, f), + Self::Text(ref t) => std::fmt::Debug::fmt(t, f), + k => std::fmt::Debug::fmt(k, f), } } } @@ -181,8 +182,8 @@ impl Component for Field { } } -impl fmt::Display for Field { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { +impl std::fmt::Display for Field { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!( f, "{}", @@ -240,8 +241,10 @@ impl Default for Fo } } -impl fmt::Display for FormWidget { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { +impl std::fmt::Display + for FormWidget +{ + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "form") } } @@ -588,12 +591,12 @@ where id: ComponentId, } -impl fmt::Display for ButtonWidget +impl std::fmt::Display for ButtonWidget where T: 'static + std::fmt::Debug + Copy + Default + Send + Sync, { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - Display::fmt("", f) + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + std::fmt::Display::fmt("", f) } } @@ -763,9 +766,9 @@ pub struct AutoComplete { id: ComponentId, } -impl fmt::Display for AutoComplete { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - Display::fmt("AutoComplete", f) +impl std::fmt::Display for AutoComplete { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + std::fmt::Display::fmt("AutoComplete", f) } } @@ -1232,8 +1235,8 @@ impl ProgressSpinner { } } -impl fmt::Display for ProgressSpinner { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { +impl std::fmt::Display for ProgressSpinner { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "progress bar") } }