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
/// `ThreadView`.
#[derive(Debug)]
@ -932,32 +938,68 @@ impl CompactListing {
}
let mut subject = e.subject().to_string();
subject.truncate_at_boundary(150);
if thread.len() > 1 {
EntryStrings {
date: DateString(ConversationsListing::format_date(context, thread.date())),
subject: SubjectString(format!("{} ({})", subject, thread.len(),)),
flag: FlagString(format!(
"{}{}",
if thread.has_attachments() { "πŸ“Ž" } else { "" },
if thread.snoozed() { "πŸ’€" } else { "" }
)),
from: FromString(address_list!((e.from()) as comma_sep_list)),
tags: TagString(tags, colors),
}
subject: if thread.len() > 1 {
SubjectString(format!("{} ({})", subject, thread.len(),))
} else {
EntryStrings {
date: DateString(ConversationsListing::format_date(context, thread.date())),
subject: SubjectString(subject),
SubjectString(subject)
},
flag: FlagString(format!(
"{}{}",
if thread.has_attachments() { "πŸ“Ž" } else { "" },
if thread.snoozed() { "πŸ’€" } else { "" }
"{}{}{}{}",
if thread.has_attachments() {
mailbox_settings!(
context[self.cursor_pos.0][&self.cursor_pos.1]
.listing
.attachment_flag
)
.as_ref()
.map(|s| s.as_str())
.unwrap_or(concat!("πŸ“Ž", emoji_text_presentation_selector!()))
} else {
""
},
if thread.snoozed() {
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),
}
}
}
fn get_thread_under_cursor(&self, cursor: usize) -> ThreadHash {
if self.filter_term.is_empty() {

View File

@ -99,6 +99,26 @@ pub struct ListingSettings {
///Default: ' '
#[serde(default = "default_divider")]
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 {
@ -119,6 +139,10 @@ impl Default for ListingSettings {
sidebar_mailbox_tree_has_sibling_leaf: None,
sidebar_mailbox_tree_no_sibling_leaf: None,
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
.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!(
"{} has no field named {}",
parent_field, other

View File

@ -138,6 +138,22 @@ pub struct ListingSettingsOverride {
#[doc = "Default: ' '"]
#[serde(default)]
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 {
fn default() -> Self {
@ -153,6 +169,10 @@ impl Default for ListingSettingsOverride {
sidebar_mailbox_tree_has_sibling_leaf: None,
sidebar_mailbox_tree_no_sibling_leaf: None,
sidebar_divider: None,
unseen_flag: None,
thread_snoozed_flag: None,
selected_flag: None,
attachment_flag: None,
}
}
}