listing: add {unseen,selected,attachment,thread_snoozed} flag config values

pull/144/head
Manos Pitsidianakis 2020-11-09 22:37:37 +02:00
parent b411daddaa
commit 64b62352d0
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
3 changed files with 114 additions and 24 deletions

View File

@ -118,6 +118,12 @@ macro_rules! row_attr {
}}; }};
} }
macro_rules! emoji_text_presentation_selector {
() => {
"\u{FE0E}"
};
}
/// A list of all mail (`Envelope`s) in a `Mailbox`. On `\n` it opens the `Envelope` content in a /// A list of all mail (`Envelope`s) in a `Mailbox`. On `\n` it opens the `Envelope` content in a
/// `ThreadView`. /// `ThreadView`.
#[derive(Debug)] #[derive(Debug)]
@ -932,30 +938,66 @@ impl CompactListing {
} }
let mut subject = e.subject().to_string(); let mut subject = e.subject().to_string();
subject.truncate_at_boundary(150); subject.truncate_at_boundary(150);
if thread.len() > 1 { EntryStrings {
EntryStrings { date: DateString(ConversationsListing::format_date(context, thread.date())),
date: DateString(ConversationsListing::format_date(context, thread.date())), subject: if thread.len() > 1 {
subject: SubjectString(format!("{} ({})", subject, thread.len(),)), SubjectString(format!("{} ({})", subject, thread.len(),))
flag: FlagString(format!( } else {
"{}{}", SubjectString(subject)
if thread.has_attachments() { "📎" } else { "" }, },
if thread.snoozed() { "💤" } else { "" } flag: FlagString(format!(
)), "{}{}{}{}",
from: FromString(address_list!((e.from()) as comma_sep_list)), if thread.has_attachments() {
tags: TagString(tags, colors), mailbox_settings!(
} context[self.cursor_pos.0][&self.cursor_pos.1]
} else { .listing
EntryStrings { .attachment_flag
date: DateString(ConversationsListing::format_date(context, thread.date())), )
subject: SubjectString(subject), .as_ref()
flag: FlagString(format!( .map(|s| s.as_str())
"{}{}", .unwrap_or(concat!("📎", emoji_text_presentation_selector!()))
if thread.has_attachments() { "📎" } else { "" }, } else {
if thread.snoozed() { "💤" } else { "" } ""
)), },
from: FromString(address_list!((e.from()) as comma_sep_list)), if thread.snoozed() {
tags: TagString(tags, colors), mailbox_settings!(
} context[self.cursor_pos.0][&self.cursor_pos.1]
.listing
.thread_snoozed_flag
)
.as_ref()
.map(|s| s.as_str())
.unwrap_or(concat!("💤", emoji_text_presentation_selector!()))
} else {
""
},
if thread.unseen() > 0 {
mailbox_settings!(
context[self.cursor_pos.0][&self.cursor_pos.1]
.listing
.unseen_flag
)
.as_ref()
.map(|s| s.as_str())
.unwrap_or("")
} else {
""
},
if self.selection.get(&hash).cloned().unwrap_or(false) {
mailbox_settings!(
context[self.cursor_pos.0][&self.cursor_pos.1]
.listing
.selected_flag
)
.as_ref()
.map(|s| s.as_str())
.unwrap_or(concat!("☑️", emoji_text_presentation_selector!()))
} else {
""
},
)),
from: FromString(address_list!((e.from()) as comma_sep_list)),
tags: TagString(tags, colors),
} }
} }

View File

@ -99,6 +99,26 @@ pub struct ListingSettings {
///Default: ' ' ///Default: ' '
#[serde(default = "default_divider")] #[serde(default = "default_divider")]
pub sidebar_divider: char, pub sidebar_divider: char,
/// Flag to show if thread entry contains unseen mail.
/// Default: "●"
#[serde(default)]
pub unseen_flag: Option<String>,
/// Flag to show if thread has been snoozed.
/// Default: "💤"
#[serde(default)]
pub thread_snoozed_flag: Option<String>,
/// Flag to show if thread entry has been selected.
/// Default: "☑️"
#[serde(default)]
pub selected_flag: Option<String>,
/// Flag to show if thread entry contains attachments.
/// Default: "📎"
#[serde(default)]
pub attachment_flag: Option<String>,
} }
const fn default_divider() -> char { const fn default_divider() -> char {
@ -119,6 +139,10 @@ impl Default for ListingSettings {
sidebar_mailbox_tree_has_sibling_leaf: None, sidebar_mailbox_tree_has_sibling_leaf: None,
sidebar_mailbox_tree_no_sibling_leaf: None, sidebar_mailbox_tree_no_sibling_leaf: None,
sidebar_divider: default_divider(), sidebar_divider: default_divider(),
unseen_flag: None,
thread_snoozed_flag: None,
selected_flag: None,
attachment_flag: None,
} }
} }
} }
@ -148,6 +172,10 @@ impl DotAddressable for ListingSettings {
.sidebar_mailbox_tree_no_sibling_leaf .sidebar_mailbox_tree_no_sibling_leaf
.lookup(field, tail), .lookup(field, tail),
"sidebar_divider" => self.sidebar_divider.lookup(field, tail), "sidebar_divider" => self.sidebar_divider.lookup(field, tail),
"unseen_flag" => self.unseen_flag.lookup(field, tail),
"thread_snoozed_flag" => self.thread_snoozed_flag.lookup(field, tail),
"selected_flag" => self.selected_flag.lookup(field, tail),
"attachment_flag" => self.attachment_flag.lookup(field, tail),
other => Err(MeliError::new(format!( other => Err(MeliError::new(format!(
"{} has no field named {}", "{} has no field named {}",
parent_field, other parent_field, other

View File

@ -138,6 +138,22 @@ pub struct ListingSettingsOverride {
#[doc = "Default: ' '"] #[doc = "Default: ' '"]
#[serde(default)] #[serde(default)]
pub sidebar_divider: Option<char>, pub sidebar_divider: Option<char>,
#[doc = " Flag to show if thread entry contains unseen mail."]
#[doc = " Default: \"\""]
#[serde(default)]
pub unseen_flag: Option<Option<String>>,
#[doc = " Flag to show if thread has been snoozed."]
#[doc = " Default: \"💤\""]
#[serde(default)]
pub thread_snoozed_flag: Option<Option<String>>,
#[doc = " Flag to show if thread entry has been selected."]
#[doc = " Default: \"\u{fe0f}\""]
#[serde(default)]
pub selected_flag: Option<Option<String>>,
#[doc = " Flag to show if thread entry contains attachments."]
#[doc = " Default: \"📎\""]
#[serde(default)]
pub attachment_flag: Option<Option<String>>,
} }
impl Default for ListingSettingsOverride { impl Default for ListingSettingsOverride {
fn default() -> Self { fn default() -> Self {
@ -153,6 +169,10 @@ impl Default for ListingSettingsOverride {
sidebar_mailbox_tree_has_sibling_leaf: None, sidebar_mailbox_tree_has_sibling_leaf: None,
sidebar_mailbox_tree_no_sibling_leaf: None, sidebar_mailbox_tree_no_sibling_leaf: None,
sidebar_divider: None, sidebar_divider: None,
unseen_flag: None,
thread_snoozed_flag: None,
selected_flag: None,
attachment_flag: None,
} }
} }
} }