From 17df485e1988af1078f02f0221290ce19eae2482 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20DOUIN?= Date: Sat, 24 Apr 2021 23:31:26 +0200 Subject: [PATCH] vim table containing emoji (#122) --- CHANGELOG.md | 2 ++ src/msg/model.rs | 25 ++++++++++++++++++++++--- vim/autoload/himalaya/msg.vim | 2 +- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ea7387..f431d63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Improve config compatibility on Windows [#111](https://github.com/soywod/himalaya/pull/111) +- Vim table containing emoji [#122] ## [0.2.6] - 2021-04-17 @@ -198,5 +199,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [#89]: https://github.com/soywod/himalaya/issues/89 [#96]: https://github.com/soywod/himalaya/issues/96 [#100]: https://github.com/soywod/himalaya/issues/100 +[#122]: https://github.com/soywod/himalaya/issues/122 [#125]: https://github.com/soywod/himalaya/issues/125 [#126]: https://github.com/soywod/himalaya/issues/126 diff --git a/src/msg/model.rs b/src/msg/model.rs index 0349899..a6527e2 100644 --- a/src/msg/model.rs +++ b/src/msg/model.rs @@ -9,6 +9,7 @@ use serde::{ }; use std::{borrow::Cow, fmt, fs, path::PathBuf, result}; use tree_magic; +use unicode_width::UnicodeWidthStr; use uuid::Uuid; use crate::{ @@ -196,19 +197,37 @@ impl<'a> ReadableMsg { // Message -#[derive(Debug, Serialize)] +#[derive(Debug)] pub struct Msg<'m> { pub uid: u32, pub flags: Flags<'m>, pub subject: String, pub sender: String, pub date: String, - #[serde(skip_serializing)] pub attachments: Vec, - #[serde(skip_serializing)] pub raw: Vec, } +impl<'a> Serialize for Msg<'a> { + fn serialize(&self, serializer: T) -> result::Result + where + T: ser::Serializer, + { + let mut state = serializer.serialize_struct("Msg", 7)?; + state.serialize_field("uid", &self.uid)?; + state.serialize_field("flags", &self.flags)?; + state.serialize_field("subject", &self.subject)?; + state.serialize_field( + "subject_len", + &UnicodeWidthStr::width(self.subject.as_str()), + )?; + state.serialize_field("sender", &self.sender)?; + state.serialize_field("sender_len", &UnicodeWidthStr::width(self.sender.as_str()))?; + state.serialize_field("date", &self.date)?; + state.end() + } +} + impl<'m> From> for Msg<'m> { fn from(raw: Vec) -> Self { Self { diff --git a/vim/autoload/himalaya/msg.vim b/vim/autoload/himalaya/msg.vim index 60208f1..793178f 100644 --- a/vim/autoload/himalaya/msg.vim +++ b/vim/autoload/himalaya/msg.vim @@ -229,7 +229,7 @@ function! s:get_max_widths(msgs, columns) let max_widths = map(copy(a:columns), "strlen(s:config.labels[v:val])") for msg in a:msgs - let widths = map(copy(a:columns), "strlen(msg[v:val])") + let widths = map(copy(a:columns), "has_key(msg, v:val . '_len') ? msg[v:val . '_len'] : strlen(msg[v:val])") call map(max_widths, "max([widths[v:key], v:val])") endfor