diff --git a/src/comp/mod.rs b/src/comp/mod.rs index 42e8dd69..4f773726 100644 --- a/src/comp/mod.rs +++ b/src/comp/mod.rs @@ -1 +1 @@ -pub(crate) mod cli; +pub mod cli; diff --git a/src/config/mod.rs b/src/config/mod.rs index 5cd17eda..92256774 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -1,2 +1,2 @@ -pub(crate) mod cli; +pub mod cli; pub mod model; diff --git a/src/flag/mod.rs b/src/flag/mod.rs index f7a32e1c..92256774 100644 --- a/src/flag/mod.rs +++ b/src/flag/mod.rs @@ -1,2 +1,2 @@ -pub(crate) mod cli; -pub(crate) mod model; +pub mod cli; +pub mod model; diff --git a/src/imap/mod.rs b/src/imap/mod.rs index 5cd17eda..92256774 100644 --- a/src/imap/mod.rs +++ b/src/imap/mod.rs @@ -1,2 +1,2 @@ -pub(crate) mod cli; +pub mod cli; pub mod model; diff --git a/src/main.rs b/src/main.rs index 1f02d5e3..40f61168 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,19 +4,7 @@ use error_chain::error_chain; use log::{debug, error, trace}; use std::{env, path::PathBuf, process::exit}; -mod app; -mod comp; -mod config; -mod flag; -mod imap; -mod input; -mod mbox; -mod msg; -mod output; -mod smtp; -mod table; - -use crate::{ +use himalaya::{ app::App, comp::cli::{comp_matches, comp_subcmds}, config::{cli::config_args, model::Config}, @@ -29,12 +17,12 @@ use crate::{ error_chain! { links { - CompletionCli(crate::comp::cli::Error, crate::comp::cli::ErrorKind); - Config(crate::config::model::Error, crate::config::model::ErrorKind); - FlagCli(crate::flag::cli::Error, crate::flag::cli::ErrorKind); - ImapCli(crate::imap::cli::Error, crate::imap::cli::ErrorKind); - MboxCli(crate::mbox::cli::Error, crate::mbox::cli::ErrorKind); - MsgCli(crate::msg::cli::Error, crate::msg::cli::ErrorKind); + CompletionCli(himalaya::comp::cli::Error, himalaya::comp::cli::ErrorKind); + Config(himalaya::config::model::Error, himalaya::config::model::ErrorKind); + FlagCli(himalaya::flag::cli::Error, himalaya::flag::cli::ErrorKind); + ImapCli(himalaya::imap::cli::Error, himalaya::imap::cli::ErrorKind); + MboxCli(himalaya::mbox::cli::Error, himalaya::mbox::cli::ErrorKind); + MsgCli(himalaya::msg::cli::Error, himalaya::msg::cli::ErrorKind); } } diff --git a/src/mbox/mod.rs b/src/mbox/mod.rs index f7a32e1c..92256774 100644 --- a/src/mbox/mod.rs +++ b/src/mbox/mod.rs @@ -1,2 +1,2 @@ -pub(crate) mod cli; -pub(crate) mod model; +pub mod cli; +pub mod model; diff --git a/src/msg/mod.rs b/src/msg/mod.rs index 5cd17eda..92256774 100644 --- a/src/msg/mod.rs +++ b/src/msg/mod.rs @@ -1,2 +1,2 @@ -pub(crate) mod cli; +pub mod cli; pub mod model; diff --git a/src/output/mod.rs b/src/output/mod.rs index 7bfbe321..d91021ca 100644 --- a/src/output/mod.rs +++ b/src/output/mod.rs @@ -1,3 +1,3 @@ -pub(crate) mod cli; -pub(crate) mod model; -pub(crate) mod utils; +pub mod cli; +pub mod model; +pub mod utils; diff --git a/src/table.rs b/src/table.rs index 9859f5f4..50a36e9a 100644 --- a/src/table.rs +++ b/src/table.rs @@ -1,3 +1,4 @@ +use log::{debug, trace}; use std::fmt; use unicode_width::UnicodeWidthStr; @@ -145,7 +146,7 @@ where fn max_width() -> usize { terminal_size::terminal_size() .map(|(w, _)| w.0 as usize) - .unwrap_or_default() + .unwrap_or(80) } fn build(items: &[Self]) -> Vec> { @@ -164,25 +165,38 @@ where }) .collect::>(), ); + trace!("cell_widths: {:?}", cell_widths); let spaces_plus_separators_len = cell_widths.len() * 2 - 1; let table_width = cell_widths.iter().sum::() + spaces_plus_separators_len; + trace!("table_width: {}", table_width); table .iter_mut() .map(|row| { + debug!("processing row: {:?}", row); row.0 .iter_mut() .enumerate() .map(|(i, cell)| { - let table_is_overflowing = table_width > Self::max_width(); + debug!("processing cell: {:?}", cell); + trace!("table_width: {}", table_width); + trace!("max_width: {}", Self::max_width()); + let table_is_overflowing = table_width > Self::max_width(); if table_is_overflowing && cell.is_shrinkable() { + trace!("table is overflowing and cell is shrinkable"); + let shrink_width = table_width - Self::max_width(); + trace!("shrink_width: {}", shrink_width); let cell_width = cell_widths[i] - shrink_width; let cell_is_overflowing = cell.unicode_width() > cell_width; + trace!("cell_width: {}", cell_width); + trace!("cell unicode_width: {}", cell.unicode_width()); if cell_is_overflowing { + trace!("cell is overflowing"); + let mut value = String::new(); let mut chars_width = 0; @@ -197,18 +211,30 @@ where } value.push_str("… "); - let repeat_count = cell_width - chars_width - 1; - value.push_str(&" ".repeat(repeat_count)); + trace!("chars_width: {}", chars_width); + trace!("shrinked value: {}", value); + let spaces_count = cell_width - chars_width - 1; + trace!( + "number of spaces added to shrinked value: {}", + spaces_count + ); + value.push_str(&" ".repeat(spaces_count)); cell.value = value; cell.to_string() } else { - let repeat_len = cell_width - cell.unicode_width() + 1; - cell.value.push_str(&" ".repeat(repeat_len)); + trace!("cell is not overflowing"); + let spaces_count = cell_width - cell.unicode_width() + 1; + trace!("number of spaces added to value: {}", spaces_count); + cell.value.push_str(&" ".repeat(spaces_count)); cell.to_string() } } else { - let repeat_count = cell_widths[i] - cell.unicode_width() + 1; - cell.value.push_str(&" ".repeat(repeat_count)); + trace!("table is not overflowing or cell is not shrinkable"); + trace!("cell_width: {}", cell_widths[i]); + trace!("cell unicode_width: {}", cell.unicode_width()); + let spaces_count = cell_widths[i] - cell.unicode_width() + 1; + trace!("number of spaces added to value: {}", spaces_count); + cell.value.push_str(&" ".repeat(spaces_count)); cell.to_string() } }) @@ -324,9 +350,10 @@ mod tests { Item::new(2, "loooooong", "desc"), Item::new(3, "shriiiiink", "desc"), Item::new(4, "shriiiiiiiiiink", "desc"), - Item::new(5, "😍😍😍😍", "desc"), - Item::new(6, "😍😍😍😍😍", "desc"), - Item::new(7, "!😍😍😍😍😍", "desc"), + Item::new(5, "", "desc"), + Item::new(6, "😍😍😍😍", "desc"), + Item::new(7, "😍😍😍😍😍", "desc"), + Item::new(8, "!😍😍😍😍😍", "desc"), ]; let table = vec![ @@ -335,9 +362,10 @@ mod tests { vec!["2 ", "loooooong ", "desc "], vec!["3 ", "shriiiii… ", "desc "], vec!["4 ", "shriiiii… ", "desc "], - vec!["5 ", "😍😍😍😍 ", "desc "], - vec!["6 ", "πŸ˜πŸ˜πŸ˜πŸ˜β€¦ ", "desc "], - vec!["7 ", "!πŸ˜πŸ˜πŸ˜β€¦ ", "desc "], + vec!["5 ", " ", "desc "], + vec!["6 ", "😍😍😍😍 ", "desc "], + vec!["7 ", "πŸ˜πŸ˜πŸ˜πŸ˜β€¦ ", "desc "], + vec!["8 ", "!πŸ˜πŸ˜πŸ˜β€¦ ", "desc "], ]; assert_eq!(table, Table::build(&items));