From 60af11bd47fb5c3895ae7b669d9b3dd152c68b2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20DOUIN?= Date: Sat, 16 Jan 2021 19:38:03 +0100 Subject: [PATCH] make table responsive --- CHANGELOG.md | 6 ++++ Cargo.lock | 11 +++++++ Cargo.toml | 1 + src/mbox.rs | 18 +++++++---- src/msg.rs | 35 +++++++++++++++------- src/table.rs | 85 ++++++++++++++++++++++++++++++++++++++-------------- 6 files changed, 118 insertions(+), 38 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b67364..f733484 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Write new email [#8] - Reply, reply all and forward [#9] [#10] [#11] - Download attachments [#14] +- Merge `Email` with `Msg` [#21] +- List command with pagination [#19] +- Icon in table when attachment is present [#16] [unreleased]: https://github.com/soywod/himalaya @@ -37,3 +40,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [#13]: https://github.com/soywod/himalaya/issues/13 [#14]: https://github.com/soywod/himalaya/issues/14 [#15]: https://github.com/soywod/himalaya/issues/15 +[#16]: https://github.com/soywod/himalaya/issues/16 +[#19]: https://github.com/soywod/himalaya/issues/19 +[#21]: https://github.com/soywod/himalaya/issues/21 diff --git a/Cargo.lock b/Cargo.lock index f360485..ac5b1d5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -280,6 +280,7 @@ dependencies = [ "rfc2047-decoder", "rustyline", "serde", + "terminal_size", "toml", ] @@ -946,6 +947,16 @@ dependencies = [ "winapi", ] +[[package]] +name = "terminal_size" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bd2d183bd3fac5f5fe38ddbeb4dc9aec4a39a9d7d59e7491d900302da01cbe1" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "textwrap" version = "0.11.0" diff --git a/Cargo.toml b/Cargo.toml index 05e0608..9e3b2dd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,4 +14,5 @@ native-tls = "0.2" rfc2047-decoder = "0.1.2" rustyline = "7.1.0" serde = { version = "1.0.118", features = ["derive"] } +terminal_size = "0.1.15" toml = "0.5.8" diff --git a/src/mbox.rs b/src/mbox.rs index ef01450..8f6290e 100644 --- a/src/mbox.rs +++ b/src/mbox.rs @@ -20,17 +20,25 @@ impl Mbox { impl DisplayRow for Mbox { fn to_row(&self) -> Vec { + use crate::table::*; + vec![ - table::Cell::new(&[table::BLUE], &self.delim), - table::Cell::new(&[table::GREEN], &self.name), - table::Cell::new(&[table::YELLOW], &self.attributes.join(", ")), + Cell::new(&[BLUE], &self.delim), + Cell::new(&[GREEN], &self.name), + FlexCell::new(&[YELLOW], &self.attributes.join(", ")), ] } } impl<'a> DisplayTable<'a, Mbox> for Vec { - fn cols() -> &'a [&'a str] { - &["delim", "name", "attributes"] + fn header_row() -> Vec { + use crate::table::*; + + vec![ + Cell::new(&[BOLD, UNDERLINE, WHITE], "DELIM"), + Cell::new(&[BOLD, UNDERLINE, WHITE], "NAME"), + FlexCell::new(&[BOLD, UNDERLINE, WHITE], "ATTRIBUTES"), + ] } fn rows(&self) -> &Vec { diff --git a/src/msg.rs b/src/msg.rs index 7cc790f..aa2ccbe 100644 --- a/src/msg.rs +++ b/src/msg.rs @@ -379,7 +379,10 @@ impl DisplayRow for Msg { let headers = parsed.get_headers(); let uid = &self.uid.to_string(); - let flags = String::new(); // TODO: render flags + let flags = match self.extract_attachments().map(|vec| vec.is_empty()) { + Ok(false) => "", + _ => " ", + }; let sender = headers .get_first_value("reply-to") .or(headers.get_first_value("from")) @@ -387,21 +390,33 @@ impl DisplayRow for Msg { let subject = headers.get_first_value("subject").unwrap_or_default(); let date = headers.get_first_value("date").unwrap_or_default(); - vec![ - table::Cell::new(&[table::RED], &uid), - table::Cell::new(&[table::WHITE], &flags), - table::Cell::new(&[table::BLUE], &sender), - table::Cell::new(&[table::GREEN], &subject), - table::Cell::new(&[table::YELLOW], &date), - ] + { + use crate::table::*; + + vec![ + Cell::new(&[RED], &uid), + Cell::new(&[WHITE], &flags), + Cell::new(&[BLUE], &sender), + FlexCell::new(&[GREEN], &subject), + Cell::new(&[YELLOW], &date), + ] + } } } } } impl<'a> DisplayTable<'a, Msg> for Vec { - fn cols() -> &'a [&'a str] { - &["uid", "flags", "sender", "subject", "date"] + fn header_row() -> Vec { + use crate::table::*; + + vec![ + Cell::new(&[BOLD, UNDERLINE, WHITE], "UID"), + Cell::new(&[BOLD, UNDERLINE, WHITE], "FLAGS"), + Cell::new(&[BOLD, UNDERLINE, WHITE], "SENDER"), + FlexCell::new(&[BOLD, UNDERLINE, WHITE], "SUBJECT"), + Cell::new(&[BOLD, UNDERLINE, WHITE], "DATE"), + ] } fn rows(&self) -> &Vec { diff --git a/src/table.rs b/src/table.rs index e247d04..5fce500 100644 --- a/src/table.rs +++ b/src/table.rs @@ -1,4 +1,5 @@ use std::fmt; +use terminal_size::terminal_size; #[derive(Clone, Debug)] pub struct Style(u8, u8, u8); @@ -33,13 +34,15 @@ impl fmt::Display for Style { pub struct Cell { pub styles: Vec