Compare commits

...

8 Commits

Author SHA1 Message Date
Manos Pitsidianakis a4ebe3b7d4
conf.rs: Add ErrorKind::Platform
Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
3 weeks ago
Manos Pitsidianakis 57e3e643a1
conversations.rs: remove excessive right padding in flags
Flags had too many spaces on its right side padding. This commit removes
it.

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
3 weeks ago
Manos Pitsidianakis a8c7582fa3
melib/imap: fix ENVELOPE parsing in untagged responses
Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
3 weeks ago
Manos Pitsidianakis a9c3b151f1
listing.rs: impl highlight_self in all index styles
Add highlight_self to all listing styles (compact, conversations, plain,
thread).

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
3 weeks ago
Manos Pitsidianakis 1abce964c7
melib: add Envelope::recipient_any method
Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
3 weeks ago
Manos Pitsidianakis 735b44f286
Add 'highlight_self' theme attribute
Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
3 weeks ago
Manos Pitsidianakis 50ff16c44f
themes: add LIGHT, DARK constant theme keys
Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
3 weeks ago
Manos Pitsidianakis 9ca34a6864
Update MSRV to 1.70.0
Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
4 weeks ago

@ -9,7 +9,7 @@ PREFIX=~/.local make install
Available subcommands for `make` are listed with `make help`.
The Makefile *should* be POSIX portable and not require a specific `make` version.
`meli` requires rust version 1.68.2 or later and rust's package manager, Cargo.
`meli` requires rust version 1.70.0 or later and rust's package manager, Cargo.
Information on how to get it on your system can be found here: <https://doc.rust-lang.org/cargo/getting-started/installation.html>
With Cargo available, the project can be built with `make` and the resulting binary will then be found under `target/release/meli`.

@ -1,4 +1,4 @@
# meli ![Established, created in 2017](https://img.shields.io/badge/Est.-2017-blue) ![Minimum Supported Rust Version](https://img.shields.io/badge/MSRV-1.68.2-blue) [![GitHub license](https://img.shields.io/github/license/meli/meli)](https://github.com/meli/meli/blob/master/COPYING) [![Crates.io](https://img.shields.io/crates/v/meli)](https://crates.io/crates/meli) [![IRC channel](https://img.shields.io/badge/irc.oftc.net-%23meli-blue)](ircs://irc.oftc.net:6697/%23meli)
# meli ![Established, created in 2017](https://img.shields.io/badge/Est.-2017-blue) ![Minimum Supported Rust Version](https://img.shields.io/badge/MSRV-1.70.0-blue) [![GitHub license](https://img.shields.io/github/license/meli/meli)](https://github.com/meli/meli/blob/master/COPYING) [![Crates.io](https://img.shields.io/crates/v/meli)](https://crates.io/crates/meli) [![IRC channel](https://img.shields.io/badge/irc.oftc.net-%23meli-blue)](ircs://irc.oftc.net:6697/%23meli)
**BSD/Linux/macos terminal email client with support for multiple accounts and Maildir / mbox / notmuch / IMAP / JMAP / NNTP (Usenet).**

@ -3,7 +3,7 @@ name = "meli"
version = "0.8.5"
authors = ["Manos Pitsidianakis <manos@pitsidianak.is>"]
edition = "2021"
rust-version = "1.68.2"
rust-version = "1.70.0"
license = "GPL-3.0-or-later"
readme = "README.md"
description = "terminal e-mail client"

@ -29,6 +29,7 @@ use std::{
collections::HashSet,
io::Read,
process::{Command, Stdio},
sync::Arc,
};
use melib::{
@ -303,24 +304,23 @@ impl From<FileAccount> for AccountConf {
}
pub fn get_config_file() -> Result<PathBuf> {
if let Ok(path) = env::var("MELI_CONFIG") {
return Ok(PathBuf::from(path).expand());
}
let xdg_dirs = xdg::BaseDirectories::with_prefix("meli").map_err(|err| {
Error::new(format!(
"Could not detect XDG directories for user: {}",
err
))
.set_source(Some(std::sync::Arc::new(Box::new(err))))
Error::new("Could not detect XDG directories for user")
.set_source(Some(std::sync::Arc::new(Box::new(err))))
.set_kind(ErrorKind::NotSupported)
})?;
match env::var("MELI_CONFIG") {
Ok(path) => Ok(PathBuf::from(path).expand()),
Err(_) => Ok(xdg_dirs
.place_config_file("config.toml")
.chain_err_summary(|| {
format!(
"Cannot create configuration directory in {}",
xdg_dirs.get_config_home().display()
)
})?),
}
xdg_dirs
.place_config_file("config.toml")
.chain_err_summary(|| {
format!(
"Cannot create configuration directory in {}",
xdg_dirs.get_config_home().display()
)
})
.chain_err_kind(ErrorKind::OSError)
}
pub fn get_included_configs(conf_path: PathBuf) -> Result<Vec<PathBuf>> {
@ -336,7 +336,7 @@ changequote(`"', `"')dnl
let mut contents = String::new();
while let Some((parent, p)) = stack.pop() {
if !p.exists() || p.is_dir() {
return Err(format!(
return Err(Error::new(format!(
"Path {}{included}{in_parent} {msg}.",
p.display(),
included = if parent.is_some() {
@ -354,8 +354,8 @@ changequote(`"', `"')dnl
} else {
"is a directory, not a text file"
}
)
.into());
))
.set_kind(ErrorKind::Configuration));
}
contents.clear();
let mut file = std::fs::File::open(&p)?;
@ -368,11 +368,18 @@ changequote(`"', `"')dnl
.spawn()
{
Ok(handle) => handle,
Err(error) => match error.kind() {
Err(err) => match err.kind() {
io::ErrorKind::NotFound => {
return Err("`m4` executable not found. Please install.".into())
return Err(Error::new(
"`m4` executable not found in PATH. Please provide an m4 binary.",
)
.set_kind(ErrorKind::Platform))
}
_ => {
return Err(Error::new("Could not process configuration with `m4`")
.set_source(Some(Arc::new(err)))
.set_kind(ErrorKind::OSError))
}
_ => return Err(error.into()),
},
};
@ -426,7 +433,8 @@ impl FileSettings {
if !config_path.exists() {
let path_string = config_path.display().to_string();
if path_string.is_empty() {
return Err(Error::new("No configuration found."));
return Err(Error::new("Given configuration path is empty.")
.set_kind(ErrorKind::Configuration));
}
#[cfg(not(test))]
let ask = Ask {
@ -438,14 +446,17 @@ impl FileSettings {
#[cfg(not(test))]
if ask.run() {
create_config_file(&config_path)?;
return Err(Error::new(
"Edit the sample configuration and relaunch meli.",
));
return Err(
Error::new("Edit the sample configuration and relaunch meli.")
.set_kind(ErrorKind::Configuration),
);
}
#[cfg(test)]
return Ok(Self::default());
#[cfg(not(test))]
return Err(Error::new("No configuration file found."));
return Err(
Error::new("No configuration file found.").set_kind(ErrorKind::Configuration)
);
}
Self::validate(config_path, true, false)
@ -492,14 +503,13 @@ This is required so that you don't accidentally start meli and find out later th
"{}\n\nEdit the {} and relaunch meli.",
if interactive { "" } else { err_msg },
path.display()
)));
))
.set_kind(ErrorKind::Configuration));
}
let mut s: Self = toml::from_str(&s).map_err(|err| {
Error::new(format!(
"{}: Config file contains errors; {}",
path.display(),
err
))
Error::new(format!("{}: Config file contains errors", path.display()))
.set_source(Some(Arc::new(err)))
.set_kind(ErrorKind::Configuration)
})?;
let backends = melib::backends::Backends::new();
let Themes {
@ -525,10 +535,11 @@ This is required so that you don't accidentally start meli and find out later th
}
}
match s.terminal.theme.as_str() {
"dark" | "light" => {}
themes::DARK | themes::LIGHT => {}
t if s.terminal.themes.other_themes.contains_key(t) => {}
t => {
return Err(Error::new(format!("Theme `{}` was not found.", t)));
return Err(Error::new(format!("Theme `{}` was not found.", t))
.set_kind(ErrorKind::Configuration));
}
}
@ -576,7 +587,8 @@ This is required so that you don't accidentally start meli and find out later th
return Err(Error::new(format!(
"Unrecognised configuration values: {:?}",
s.extra
)));
))
.set_kind(ErrorKind::Configuration));
}
if clear_extras {
acc.extra.clear();

@ -47,11 +47,14 @@ use crate::{
Context,
};
pub const LIGHT: &str = "light";
pub const DARK: &str = "dark";
#[inline(always)]
pub fn value(context: &Context, key: &'static str) -> ThemeAttribute {
let theme = match context.settings.terminal.theme.as_str() {
"light" => &context.settings.terminal.themes.light,
"dark" => &context.settings.terminal.themes.dark,
self::LIGHT => &context.settings.terminal.themes.light,
self::DARK => &context.settings.terminal.themes.dark,
t => context
.settings
.terminal
@ -66,8 +69,8 @@ pub fn value(context: &Context, key: &'static str) -> ThemeAttribute {
#[inline(always)]
pub fn fg_color(context: &Context, key: &'static str) -> Color {
let theme = match context.settings.terminal.theme.as_str() {
"light" => &context.settings.terminal.themes.light,
"dark" => &context.settings.terminal.themes.dark,
self::LIGHT => &context.settings.terminal.themes.light,
self::DARK => &context.settings.terminal.themes.dark,
t => context
.settings
.terminal
@ -82,8 +85,8 @@ pub fn fg_color(context: &Context, key: &'static str) -> Color {
#[inline(always)]
pub fn bg_color(context: &Context, key: &'static str) -> Color {
let theme = match context.settings.terminal.theme.as_str() {
"light" => &context.settings.terminal.themes.light,
"dark" => &context.settings.terminal.themes.dark,
self::LIGHT => &context.settings.terminal.themes.light,
self::DARK => &context.settings.terminal.themes.dark,
t => context
.settings
.terminal
@ -98,8 +101,8 @@ pub fn bg_color(context: &Context, key: &'static str) -> Color {
#[inline(always)]
pub fn attrs(context: &Context, key: &'static str) -> Attr {
let theme = match context.settings.terminal.theme.as_str() {
"light" => &context.settings.terminal.themes.light,
"dark" => &context.settings.terminal.themes.dark,
self::LIGHT => &context.settings.terminal.themes.light,
self::DARK => &context.settings.terminal.themes.dark,
t => context
.settings
.terminal
@ -318,6 +321,7 @@ const DEFAULT_KEYS: &[&str] = &[
"mail.listing.attachment_flag",
"mail.listing.thread_snooze_flag",
"mail.listing.tag_default",
"mail.listing.highlight_self",
"pager.highlight_search",
"pager.highlight_search_current",
];
@ -648,8 +652,8 @@ mod regexp {
key: &'static str,
) -> SmallVec<[TextFormatter<'ctx>; 64]> {
let theme = match context.settings.terminal.theme.as_str() {
"light" => &context.settings.terminal.themes.light,
"dark" => &context.settings.terminal.themes.dark,
self::LIGHT => &context.settings.terminal.themes.light,
self::DARK => &context.settings.terminal.themes.dark,
t => context
.settings
.terminal
@ -1213,8 +1217,8 @@ impl Themes {
}
pub fn validate(&self) -> Result<()> {
let hash_set: HashSet<&'static str> = DEFAULT_KEYS.iter().copied().collect();
Self::validate_keys("light", &self.light, &hash_set)?;
Self::validate_keys("dark", &self.dark, &hash_set)?;
Self::validate_keys(self::LIGHT, &self.light, &hash_set)?;
Self::validate_keys(self::DARK, &self.dark, &hash_set)?;
for (name, t) in self.other_themes.iter() {
Self::validate_keys(name, t, &hash_set)?;
}
@ -1234,8 +1238,8 @@ impl Themes {
pub fn key_to_string(&self, key: &str, unlink: bool) -> String {
let theme = match key {
"light" => &self.light,
"dark" => &self.dark,
self::LIGHT => &self.light,
self::DARK => &self.dark,
t => self.other_themes.get(t).unwrap_or(&self.dark),
};
let mut ret = String::new();
@ -1270,10 +1274,10 @@ impl Themes {
impl std::fmt::Display for Themes {
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
let mut ret = String::new();
ret.push_str(&self.key_to_string("dark", true));
ret.push_str(&self.key_to_string(self::DARK, true));
ret.push_str("\n\n");
ret.push_str(&self.key_to_string("light", true));
ret.push_str(&self.key_to_string(self::LIGHT, true));
for name in self.other_themes.keys() {
ret.push_str("\n\n");
ret.push_str(&self.key_to_string(name, true));
@ -1727,6 +1731,15 @@ impl Default for Themes {
attrs: Attr::BOLD
}
);
add!(
"mail.listing.highlight_self",
light = {
fg: Color::BLUE,
},
dark = {
fg: Color::BLUE,
}
);
add!("pager.highlight_search", light = { fg: Color::White, bg: Color::Byte(6) /* Teal */, attrs: Attr::BOLD }, dark = { fg: Color::White, bg: Color::Byte(6) /* Teal */, attrs: Attr::BOLD });
add!("pager.highlight_search_current", light = { fg: Color::White, bg: Color::Byte(17) /* NavyBlue */, attrs: Attr::BOLD }, dark = { fg: Color::White, bg: Color::Byte(17) /* NavyBlue */, attrs: Attr::BOLD });
@ -1803,8 +1816,8 @@ impl Serialize for Themes {
other_themes.insert(name.to_string(), new_map);
}
other_themes.insert("light".to_string(), light);
other_themes.insert("dark".to_string(), dark);
other_themes.insert(self::LIGHT.to_string(), light);
other_themes.insert(self::DARK.to_string(), dark);
other_themes.serialize(serializer)
}
}

@ -268,6 +268,7 @@ pub struct ColorCache {
pub even_highlighted_selected: ThemeAttribute,
pub odd_highlighted_selected: ThemeAttribute,
pub tag_default: ThemeAttribute,
pub highlight_self: ThemeAttribute,
// Conversations
pub subject: ThemeAttribute,
@ -277,6 +278,12 @@ pub struct ColorCache {
impl ColorCache {
pub fn new(context: &Context, style: IndexStyle) -> Self {
let default = Self {
theme_default: crate::conf::value(context, "theme_default"),
tag_default: crate::conf::value(context, "mail.listing.tag_default"),
highlight_self: crate::conf::value(context, "mail.listing.highlight_self"),
..Self::default()
};
let mut ret = match style {
IndexStyle::Plain => Self {
even: crate::conf::value(context, "mail.listing.plain.even"),
@ -298,9 +305,7 @@ impl ColorCache {
"mail.listing.plain.even_highlighted_selected",
),
odd_selected: crate::conf::value(context, "mail.listing.plain.odd_selected"),
tag_default: crate::conf::value(context, "mail.listing.tag_default"),
theme_default: crate::conf::value(context, "theme_default"),
..Self::default()
..default
},
IndexStyle::Threaded => Self {
even_unseen: crate::conf::value(context, "mail.listing.plain.even_unseen"),
@ -322,9 +327,7 @@ impl ColorCache {
),
even: crate::conf::value(context, "mail.listing.plain.even"),
odd: crate::conf::value(context, "mail.listing.plain.odd"),
tag_default: crate::conf::value(context, "mail.listing.tag_default"),
theme_default: crate::conf::value(context, "theme_default"),
..Self::default()
..default
},
IndexStyle::Compact => Self {
even_unseen: crate::conf::value(context, "mail.listing.compact.even_unseen"),
@ -349,12 +352,9 @@ impl ColorCache {
),
even: crate::conf::value(context, "mail.listing.compact.even"),
odd: crate::conf::value(context, "mail.listing.compact.odd"),
tag_default: crate::conf::value(context, "mail.listing.tag_default"),
theme_default: crate::conf::value(context, "theme_default"),
..Self::default()
..default
},
IndexStyle::Conversations => Self {
theme_default: crate::conf::value(context, "mail.listing.conversations"),
subject: crate::conf::value(context, "mail.listing.conversations.subject"),
from: crate::conf::value(context, "mail.listing.conversations.from"),
date: crate::conf::value(context, "mail.listing.conversations.date"),
@ -365,13 +365,13 @@ impl ColorCache {
context,
"mail.listing.conversations.highlighted_selected",
),
tag_default: crate::conf::value(context, "mail.listing.tag_default"),
..Self::default()
..default
},
};
if !context.settings.terminal.use_color() {
ret.highlighted.attrs |= Attr::REVERSE;
ret.tag_default.attrs |= Attr::REVERSE;
ret.highlight_self.attrs |= Attr::REVERSE;
ret.even_highlighted.attrs |= Attr::REVERSE;
ret.odd_highlighted.attrs |= Attr::REVERSE;
ret.even_highlighted_selected.attrs |= Attr::REVERSE | Attr::DIM;
@ -388,6 +388,7 @@ pub struct EntryStrings {
pub flag: FlagString,
pub from: FromString,
pub tags: TagString,
pub unseen: bool,
pub highlight_self: bool,
}

@ -138,7 +138,7 @@ pub struct CompactListing {
sortcmd: bool,
subsort: (SortField, SortOrder),
/// Cache current view.
data_columns: DataColumns<4>,
data_columns: DataColumns<5>,
rows_drawn: SegmentTree,
rows: RowsState<(ThreadHash, EnvelopeHash)>,
@ -234,13 +234,13 @@ impl MailListingTrait for CompactListing {
let message: String =
context.accounts[&self.cursor_pos.0][&self.cursor_pos.1].status();
if self.data_columns.columns[0].resize_with_context(message.len(), 1, context) {
let area = self.data_columns.columns[0].area();
let area_col_0 = self.data_columns.columns[0].area();
self.data_columns.columns[0].grid_mut().write_string(
message.as_str(),
self.color_cache.theme_default.fg,
self.color_cache.theme_default.bg,
self.color_cache.theme_default.attrs,
area,
area_col_0,
None,
);
}
@ -299,18 +299,20 @@ impl MailListingTrait for CompactListing {
self.sort = context.accounts[&self.cursor_pos.0].settings.account.order
}
self.length = 0;
let mut min_width = (0, 0, 0, 0);
let mut min_width = (0, 0, 0, 0, 0);
#[allow(clippy::type_complexity)]
let mut row_widths: (
SmallVec<[u8; 1024]>,
SmallVec<[u8; 1024]>,
SmallVec<[u8; 1024]>,
SmallVec<[u8; 1024]>,
SmallVec<[u8; 1024]>,
) = (
SmallVec::new(),
SmallVec::new(),
SmallVec::new(),
SmallVec::new(),
SmallVec::new(),
);
let tags_lck = account.collection.tag_index.read().unwrap();
@ -325,6 +327,12 @@ impl MailListingTrait for CompactListing {
.settings
.account
.make_display_name();
let should_highlight_self = mailbox_settings!(
context[self.cursor_pos.0][&self.cursor_pos.1]
.listing
.highlight_self
)
.is_true();
'items_for_loop: for thread in items {
let thread_node = &threads.thread_nodes()[&threads.thread_ref(thread).root()];
let root_env_hash = if let Some(h) = thread_node.message().or_else(|| {
@ -401,11 +409,7 @@ impl MailListingTrait for CompactListing {
}
}
highlight_self |= envelope
.to()
.iter()
.chain(envelope.cc().iter())
.any(|a| a == &my_address);
highlight_self |= should_highlight_self && envelope.recipient_any(&my_address);
for addr in envelope.from().iter() {
if from_address_set.contains(addr.address_spec_raw()) {
continue;
@ -414,15 +418,6 @@ impl MailListingTrait for CompactListing {
from_address_list.push(addr.clone());
}
}
if !mailbox_settings!(
context[self.cursor_pos.0][&self.cursor_pos.1]
.listing
.highlight_self
)
.is_true()
{
highlight_self = false;
}
let row_attr = row_attr!(
self.color_cache,
@ -463,22 +458,25 @@ impl MailListingTrait for CompactListing {
.try_into()
.unwrap_or(255),
);
/* subject */
row_widths.3.push(
(entry_strings.flag.grapheme_width()
+ entry_strings.subject.grapheme_width()
+ 1
+ entry_strings.tags.grapheme_width())
.try_into()
.unwrap_or(255),
entry_strings
.flag
.grapheme_width()
.try_into()
.unwrap_or(255),
);
row_widths.4.push(
(entry_strings.subject.grapheme_width() + 1 + entry_strings.tags.grapheme_width())
.try_into()
.unwrap_or(255),
);
min_width.1 = min_width.1.max(entry_strings.date.grapheme_width()); /* date */
min_width.2 = min_width.2.max(entry_strings.from.grapheme_width()); /* from */
min_width.3 = min_width.3.max(
entry_strings.flag.grapheme_width()
+ entry_strings.subject.grapheme_width()
+ 1
+ entry_strings.tags.grapheme_width(),
entry_strings.flag.grapheme_width() + usize::from(entry_strings.highlight_self),
);
min_width.4 = min_width.4.max(
entry_strings.subject.grapheme_width() + 1 + entry_strings.tags.grapheme_width(),
); /* subject */
self.rows.insert_thread(
thread,
@ -494,12 +492,13 @@ impl MailListingTrait for CompactListing {
self.length += 1;
}
min_width.0 = self.length.saturating_sub(1).to_string().len();
min_width.0 = digits_of_num!(self.length.saturating_sub(1));
self.data_columns.elasticities[0].set_rigid();
self.data_columns.elasticities[1].set_rigid();
self.data_columns.elasticities[2].set_grow(15, Some(35));
self.data_columns.elasticities[3].set_rigid();
self.data_columns.elasticities[4].set_rigid();
self.data_columns
.cursor_config
.set_handle(true)
@ -517,12 +516,15 @@ impl MailListingTrait for CompactListing {
_ = self.data_columns.columns[1].resize_with_context(min_width.1, self.rows.len(), context);
/* from column */
_ = self.data_columns.columns[2].resize_with_context(min_width.2, self.rows.len(), context);
/* subject column */
// flags column
_ = self.data_columns.columns[3].resize_with_context(min_width.3, self.rows.len(), context);
// subject column
_ = self.data_columns.columns[4].resize_with_context(min_width.4, self.rows.len(), context);
self.data_columns.segment_tree[0] = row_widths.0.into();
self.data_columns.segment_tree[1] = row_widths.1.into();
self.data_columns.segment_tree[2] = row_widths.2.into();
self.data_columns.segment_tree[3] = row_widths.3.into();
self.data_columns.segment_tree[4] = row_widths.4.into();
self.rows_drawn = SegmentTree::from(
std::iter::repeat(1)
@ -534,13 +536,13 @@ impl MailListingTrait for CompactListing {
if self.length == 0 && self.filter_term.is_empty() {
let message: String = account[&self.cursor_pos.1].status();
if self.data_columns.columns[0].resize_with_context(message.len(), 1, context) {
let area = self.data_columns.columns[0].area();
let area_col_0 = self.data_columns.columns[0].area();
self.data_columns.columns[0].grid_mut().write_string(
&message,
self.color_cache.theme_default.fg,
self.color_cache.theme_default.bg,
self.color_cache.theme_default.attrs,
area,
area_col_0,
None,
);
}
@ -688,6 +690,10 @@ impl ListingTrait for CompactListing {
}
context.dirty_areas.push_back(new_area);
}
if *account_settings!(context[self.cursor_pos.0].listing.relative_list_indices) {
self.draw_relative_numbers(grid, area, top_idx, context);
context.dirty_areas.push_back(area);
}
if !self.force_draw {
return;
}
@ -707,6 +713,9 @@ impl ListingTrait for CompactListing {
/* copy table columns */
self.data_columns
.draw(grid, top_idx, self.cursor_pos.2, grid.bounds_iter(area));
if *account_settings!(context[self.cursor_pos.0].listing.relative_list_indices) {
self.draw_relative_numbers(grid, area, top_idx, context);
}
/* apply each row colors separately */
for i in top_idx..(top_idx + area.height()) {
if let Some(row_attr) = self.rows.row_attr_cache.get(&i) {
@ -987,6 +996,7 @@ impl CompactListing {
),
from: FromString(Address::display_name_slice(from)),
tags: TagString(tags_string, colors),
unseen: thread.unseen() > 0,
highlight_self,
}
}
@ -1033,6 +1043,12 @@ impl CompactListing {
let mut from_address_set: std::collections::HashSet<Vec<u8>> =
std::collections::HashSet::new();
let mut highlight_self: bool = false;
let should_highlight_self = mailbox_settings!(
context[self.cursor_pos.0][&self.cursor_pos.1]
.listing
.highlight_self
)
.is_true();
let my_address: Address = context.accounts[&self.cursor_pos.0]
.settings
.account
@ -1061,11 +1077,7 @@ impl CompactListing {
tags.insert(t);
}
}
highlight_self |= envelope
.to()
.iter()
.chain(envelope.cc().iter())
.any(|a| a == &my_address);
highlight_self |= should_highlight_self && envelope.recipient_any(&my_address);
for addr in envelope.from().iter() {
if from_address_set.contains(addr.address_spec_raw()) {
continue;
@ -1074,17 +1086,8 @@ impl CompactListing {
from_address_list.push(addr.clone());
}
}
if !mailbox_settings!(
context[self.cursor_pos.0][&self.cursor_pos.1]
.listing
.highlight_self
)
.is_true()
{
highlight_self = false;
}
let strings = self.make_entry_string(
let mut entry_strings = self.make_entry_string(
&envelope,
context,
&tags_lck,
@ -1095,161 +1098,22 @@ impl CompactListing {
highlight_self,
thread_hash,
);
entry_strings.highlight_self = should_highlight_self && {
let my_address: Address = context.accounts[&self.cursor_pos.0]
.settings
.account
.make_display_name();
envelope.recipient_any(&my_address)
};
drop(envelope);
let columns = &mut self.data_columns.columns;
let min_width = (
columns[0].area().width(),
columns[1].area().width(),
columns[2].area().width(),
columns[3].area().width(),
);
let (x, _) = {
let area = columns[0].area().nth_row(idx);
columns[0].grid_mut().write_string(
&idx.to_string(),
row_attr.fg,
row_attr.bg,
row_attr.attrs,
area,
None,
)
};
for c in {
let area = columns[0].area();
columns[0].grid_mut().row_iter(area, x..min_width.0, idx)
} {
columns[0].grid_mut()[c]
.set_bg(row_attr.bg)
.set_attrs(row_attr.attrs)
.set_ch(' ');
}
let (x, _) = {
let area = columns[1].area().nth_row(idx);
columns[1].grid_mut().write_string(
&strings.date,
row_attr.fg,
row_attr.bg,
row_attr.attrs,
area,
None,
)
};
for c in {
let area = columns[1].area();
columns[1].grid_mut().row_iter(area, x..min_width.1, idx)
} {
columns[1].grid_mut()[c]
.set_bg(row_attr.bg)
.set_attrs(row_attr.attrs)
.set_ch(' ');
}
let (x, _) = {
let area = columns[2].area().nth_row(idx);
columns[2].grid_mut().write_string(
&strings.from,
row_attr.fg,
row_attr.bg,
row_attr.attrs,
area,
None,
)
};
for c in {
let area = columns[2].area();
columns[2].grid_mut().row_iter(area, x..min_width.2, idx)
} {
columns[2].grid_mut()[c]
.set_bg(row_attr.bg)
.set_attrs(row_attr.attrs)
.set_ch(' ');
}
let (x, _) = {
let area = columns[3].area().nth_row(idx);
columns[3].grid_mut().write_string(
&strings.flag,
row_attr.fg,
row_attr.bg,
row_attr.attrs,
area,
None,
)
};
let (x, _) = {
let area = columns[3].area().nth_row(idx).skip_cols(x);
columns[3].grid_mut().write_string(
&strings.subject,
row_attr.fg,
row_attr.bg,
row_attr.attrs,
area,
None,
)
};
if let Some(c) = columns[3].grid_mut().get_mut(x, idx) {
c.set_bg(row_attr.bg).set_attrs(row_attr.attrs).set_ch(' ');
for n in 0..=4 {
let area = columns[n].area().nth_row(idx);
columns[n].grid_mut().clear_area(area, row_attr);
}
let x = {
let mut x = x + 1;
for (t, &color) in strings.tags.split_whitespace().zip(strings.tags.1.iter()) {
let color = color.unwrap_or(self.color_cache.tag_default.bg);
let _x = {
let area = columns[3].area().nth_row(idx).skip_cols(x + 1);
columns[3]
.grid_mut()
.write_string(
t,
self.color_cache.tag_default.fg,
color,
self.color_cache.tag_default.attrs,
area,
None,
)
.0
+ x
+ 1
};
for c in {
let area = columns[3].area();
columns[3].grid_mut().row_iter(area, x..(x + 1), idx)
} {
columns[3].grid_mut()[c].set_bg(color);
}
for c in {
let area = columns[3].area();
columns[3].grid_mut().row_iter(area, _x..(_x + 1), idx)
} {
columns[3].grid_mut()[c].set_bg(color).set_keep_bg(true);
}
for c in {
let area = columns[3].area();
columns[3].grid_mut().row_iter(area, (x + 1)..(_x + 1), idx)
} {
columns[3].grid_mut()[c]
.set_keep_fg(true)
.set_keep_bg(true)
.set_keep_attrs(true);
}
for c in {
let area = columns[3].area();
columns[3].grid_mut().row_iter(area, x..(x + 1), idx)
} {
columns[3].grid_mut()[c].set_keep_bg(true);
}
x = _x + 2;
}
x
};
for c in {
let area = columns[3].area();
columns[3].grid_mut().row_iter(area, x..min_width.3, idx)
} {
columns[3].grid_mut()[c]
.set_ch(' ')
.set_bg(row_attr.bg)
.set_attrs(row_attr.attrs);
}
*self.rows.entries.get_mut(idx).unwrap() = ((thread_hash, env_hash), strings);
self.rows_drawn.update(idx, 1);
*self.rows.entries.get_mut(idx).unwrap() = ((thread_hash, env_hash), entry_strings);
}
fn draw_rows(&mut self, context: &Context, start: usize, end: usize) {
@ -1268,6 +1132,7 @@ impl CompactListing {
self.data_columns.columns[1].area().width(),
self.data_columns.columns[2].area().width(),
self.data_columns.columns[3].area().width(),
self.data_columns.columns[3].area().width(),
);
let columns = &mut self.data_columns.columns;
@ -1358,128 +1223,105 @@ impl CompactListing {
}
}
}
let (x, _) = {
let area = columns[3].area().nth_row(idx);
columns[3].grid_mut().write_string(
{
let mut area_col_3 = columns[3].area().nth_row(idx);
area_col_3 = area_col_3.skip_cols(columns[3].grid_mut().write_string(
&strings.flag,
row_attr.fg,
row_attr.bg,
row_attr.attrs,
area,
area_col_3,
None,
)
};
let x = {
let mut area = columns[3].area().nth_row(idx).skip_cols(x);
));
if strings.highlight_self {
// [ref:hardcoded_color_value]: add highlight_self theme attr
let x = columns[3]
.grid_mut()
.write_string(
mailbox_settings!(
context[self.cursor_pos.0][&self.cursor_pos.1]
.listing
.highlight_self_flag
)
.as_ref()
.map(|s| s.as_str())
.unwrap_or(super::DEFAULT_HIGHLIGHT_SELF_FLAG),
Color::BLUE,
row_attr.bg,
row_attr.attrs | Attr::FORCE_TEXT,
area,
None,
let (x, _) = columns[3].grid_mut().write_string(
mailbox_settings!(
context[self.cursor_pos.0][&self.cursor_pos.1]
.listing
.highlight_self_flag
)
.0;
for row in columns[3].grid().bounds_iter(area.nth_row(0).take_cols(x)) {
for c in row {
columns[3].grid_mut()[c].set_keep_fg(true);
}
}
area = area.skip_cols(x + 1);
}
columns[3]
.grid_mut()
.write_string(
&strings.subject,
row_attr.fg,
.as_ref()
.map(|s| s.as_str())
.unwrap_or(super::DEFAULT_HIGHLIGHT_SELF_FLAG),
self.color_cache.highlight_self.fg,
row_attr.bg,
row_attr.attrs,
area,
row_attr.attrs | Attr::FORCE_TEXT,
area_col_3,
None,
)
.0
+ x
};
#[cfg(feature = "regexp")]
{
for text_formatter in crate::conf::text_format_regexps(context, "listing.subject") {
let t = columns[3].grid_mut().insert_tag(text_formatter.tag);
for (start, end) in text_formatter.regexp.find_iter(strings.subject.as_str()) {
columns[3].grid_mut().set_tag(t, (start, idx), (end, idx));
);
for c in columns[3].grid().row_iter(area_col_3, 0..x, 0) {
columns[3].grid_mut()[c].set_keep_fg(true);
}
area_col_3 = area_col_3.skip_cols(x + 1);
}
}
let mut x = x + 1;
for (t, &color) in strings.tags.split_whitespace().zip(strings.tags.1.iter()) {
let color = color.unwrap_or(self.color_cache.tag_default.bg);
let _x = {
let area = columns[3].area().nth_row(idx).skip_cols(x + 1);
columns[3]
.grid_mut()
.write_string(
t,
self.color_cache.tag_default.fg,
color,
self.color_cache.tag_default.attrs,
area,
None,
)
.0
+ x
+ 1
};
for c in {
let area = columns[3].area();
columns[3].grid_mut().row_iter(area, x..(x + 1), idx)
} {
columns[3].grid_mut()[c].set_bg(color);
for c in columns[3].grid().row_iter(area_col_3, 0..min_width.3, 0) {
columns[3].grid_mut()[c]
.set_bg(row_attr.bg)
.set_attrs(row_attr.attrs);
}
for c in {
let area = columns[3].area();
columns[3].grid_mut().row_iter(area, _x..(_x + 1), idx)
} {
columns[3].grid_mut()[c].set_bg(color).set_keep_bg(true);
}
{
let mut area_col_4 = columns[4].area().nth_row(idx);
area_col_4 = area_col_4.skip_cols(columns[4].grid_mut().write_string(
&strings.subject,
row_attr.fg,
row_attr.bg,
row_attr.attrs,
area_col_4,
None,
));
#[cfg(feature = "regexp")]
{
for text_formatter in
crate::conf::text_format_regexps(context, "listing.subject")
{
let t = columns[4].grid_mut().insert_tag(text_formatter.tag);
for (start, end) in
text_formatter.regexp.find_iter(strings.subject.as_str())
{
columns[4].grid_mut().set_tag(t, (start, idx), (end, idx));
}
}
}
for c in {
let area = columns[3].area();
columns[3].grid_mut().row_iter(area, (x + 1)..(_x + 1), idx)
} {
columns[3].grid_mut()[c]
.set_keep_fg(true)
.set_keep_bg(true)
.set_keep_attrs(true);
area_col_4 = area_col_4.skip_cols(1);
for (t, &color) in strings.tags.split_whitespace().zip(strings.tags.1.iter()) {
let color = color.unwrap_or(self.color_cache.tag_default.bg);
let (x, _) = columns[4].grid_mut().write_string(
t,
self.color_cache.tag_default.fg,
color,
self.color_cache.tag_default.attrs,
area_col_4,
None,
);
for c in columns[4].grid().row_iter(area_col_4, 0..(x + 1), 0) {
columns[4].grid_mut()[c]
.set_bg(color)
.set_keep_fg(true)
.set_keep_bg(true)
.set_keep_attrs(true);
}
area_col_4 = area_col_4.skip_cols(x + 1);
}
for c in {
let area = columns[3].area();
columns[3].grid_mut().row_iter(area, x..(x + 1), idx)
} {
columns[3].grid_mut()[c].set_keep_bg(true);
for c in columns[4].grid().row_iter(area_col_4, 0..min_width.4, 0) {
columns[4].grid_mut()[c]
.set_ch(' ')
.set_bg(row_attr.bg)
.set_attrs(row_attr.attrs);
}
x = _x + 2;
}
}
if self.length == 0 && self.filter_term.is_empty() {
let account = &context.accounts[&self.cursor_pos.0];
let message: String = account[&self.cursor_pos.1].status();
if self.data_columns.columns[0].resize_with_context(message.len(), 1, context) {
let area = self.data_columns.columns[0].area();
let area_col_0 = self.data_columns.columns[0].area();
self.data_columns.columns[0].grid_mut().write_string(
message.as_str(),
self.color_cache.theme_default.fg,
self.color_cache.theme_default.bg,
self.color_cache.theme_default.attrs,
area,
area_col_0,
None,
);
}
@ -1532,6 +1374,53 @@ impl CompactListing {
}
}
fn draw_relative_numbers(
&mut self,
grid: &mut CellBuffer,
area: Area,
top_idx: usize,
context: &Context,
) {
let width = self.data_columns.columns[0].area().width();
let area = area.take_cols(width);
let account = &context.accounts[&self.cursor_pos.0];
let threads = account.collection.get_threads(self.cursor_pos.1);
for i in 0..area.height() {
let idx = top_idx + i;
if idx >= self.length {
break;
}
let row_attr = if let Some(thread_hash) = self.get_thread_under_cursor(idx) {
let thread = threads.thread_ref(thread_hash);
row_attr!(
self.color_cache,
even: idx % 2 == 0,
unseen: thread.unseen() > 0,
highlighted: self.new_cursor_pos.2 == idx,
selected: self.rows.is_thread_selected(thread_hash)
)
} else {
row_attr!(self.color_cache, even: (top_idx + i) % 2 == 0, unseen: false, highlighted: true, selected: false)
};
grid.clear_area(area.nth_row(i), row_attr);
grid.write_string(
&if self.new_cursor_pos.2.saturating_sub(top_idx) == i {
self.new_cursor_pos.2.to_string()
} else {
(i as isize - (self.new_cursor_pos.2 - top_idx) as isize)
.abs()
.to_string()
},
row_attr.fg,
row_attr.bg,
row_attr.attrs,
area.nth_row(i),
None,
);
}
}
fn perform_movement(&mut self, height: Option<usize>) {
let rows = height.unwrap_or(1);
if let Some(mvm) = self.movement.take() {

@ -771,6 +771,7 @@ impl ConversationsListing {
),
from: FromString(Address::display_name_slice(from)),
tags: TagString(tags_string, colors),
unseen: thread.unseen() > 0,
highlight_self: false,
}
}
@ -877,10 +878,10 @@ impl ConversationsListing {
None,
);
if !strings.flag.is_empty() {
for c in grid.row_iter(area, x..(x + 3), 0) {
for c in grid.row_iter(area, x..(x + 1), 0) {
grid[c].set_bg(row_attr.bg);
}
x += 3;
x += 1;
}
let subject_attr = row_attr!(
subject,

@ -137,7 +137,7 @@ pub struct PlainListing {
subsort: (SortField, SortOrder),
rows: RowsState<(ThreadHash, EnvelopeHash)>,
/// Cache current view.
data_columns: DataColumns<4>,
data_columns: DataColumns<5>,
#[allow(clippy::type_complexity)]
search_job: Option<(String, JoinHandle<Result<SmallVec<[EnvelopeHash; 512]>>>)>,
@ -442,6 +442,10 @@ impl ListingTrait for PlainListing {
}
context.dirty_areas.push_back(new_area);
}
if *account_settings!(context[self.cursor_pos.0].listing.relative_list_indices) {
self.draw_relative_numbers(grid, area, top_idx);
context.dirty_areas.push_back(area);
}
if !self.force_draw {
return;
}
@ -461,6 +465,9 @@ impl ListingTrait for PlainListing {
/* copy table columns */
self.data_columns
.draw(grid, top_idx, self.cursor_pos.2, grid.bounds_iter(area));
if *account_settings!(context[self.cursor_pos.0].listing.relative_list_indices) {
self.draw_relative_numbers(grid, area, top_idx);
}
/* apply each row colors separately */
for i in top_idx..(top_idx + area.height()) {
if let Some(row_attr) = self.rows.row_attr_cache.get(&i) {
@ -696,6 +703,7 @@ impl PlainListing {
),
from: FromString(Address::display_name_slice(e.from())),
tags: TagString(tags, colors),
unseen: !e.is_seen(),
highlight_self: false,
}
}
@ -714,15 +722,28 @@ impl PlainListing {
SmallVec<[u8; 1024]>,
SmallVec<[u8; 1024]>,
SmallVec<[u8; 1024]>,
SmallVec<[u8; 1024]>,
) = (
SmallVec::new(),
SmallVec::new(),
SmallVec::new(),
SmallVec::new(),
SmallVec::new(),
);
let should_highlight_self = mailbox_settings!(
context[self.cursor_pos.0][&self.cursor_pos.1]
.listing
.highlight_self
)
.is_true();
let my_address: Address = context.accounts[&self.cursor_pos.0]
.settings
.account
.make_display_name();
for i in iter {
if !context.accounts[&self.cursor_pos.0].contains_key(i) {
if !context.accounts[&self.cursor_pos.0].contains_key(i)
|| !threads.envelope_to_thread.contains_key(&i)
{
log::debug!("key = {}", i);
log::debug!(
"name = {} {}",
@ -755,7 +776,9 @@ impl PlainListing {
);
self.rows.row_attr_cache.insert(self.length, row_attr);
let entry_strings = self.make_entry_string(&envelope, context);
let mut entry_strings = self.make_entry_string(&envelope, context);
entry_strings.highlight_self =
should_highlight_self && { envelope.recipient_any(&my_address) };
row_widths
.0
.push(digits_of_num!(self.length).try_into().unwrap_or(255));
@ -774,20 +797,22 @@ impl PlainListing {
.unwrap_or(255),
);
row_widths.3.push(
(entry_strings.flag.grapheme_width()
+ entry_strings.subject.grapheme_width()
+ 1
+ entry_strings.tags.grapheme_width())
.try_into()
.unwrap_or(255),
entry_strings
.flag
.grapheme_width()
.try_into()
.unwrap_or(255),
); /* flags */
row_widths.4.push(
(entry_strings.subject.grapheme_width() + 1 + entry_strings.tags.grapheme_width())
.try_into()
.unwrap_or(255),
);
min_width.1 = min_width.1.max(entry_strings.date.grapheme_width()); /* date */
min_width.2 = min_width.2.max(entry_strings.from.grapheme_width()); /* from */
min_width.3 = min_width.3.max(
entry_strings.flag.grapheme_width()
+ entry_strings.subject.grapheme_width()
+ 1
+ entry_strings.tags.grapheme_width(),
min_width.3 = min_width.3.max(entry_strings.flag.grapheme_width()); /* flags */
min_width.4 = min_width.4.max(
entry_strings.subject.grapheme_width() + 1 + entry_strings.tags.grapheme_width(),
); /* tags + subject */
self.rows.insert_thread(
threads.envelope_to_thread[&i],
@ -805,6 +830,7 @@ impl PlainListing {
self.data_columns.elasticities[1].set_rigid();
self.data_columns.elasticities[2].set_grow(15, Some(35));
self.data_columns.elasticities[3].set_rigid();
self.data_columns.elasticities[4].set_rigid();
self.data_columns
.cursor_config
.set_handle(true)
@ -822,12 +848,15 @@ impl PlainListing {
_ = self.data_columns.columns[1].resize_with_context(min_width.1, self.rows.len(), context);
/* from column */
_ = self.data_columns.columns[2].resize_with_context(min_width.2, self.rows.len(), context);
/* subject column */
// flags column
_ = self.data_columns.columns[3].resize_with_context(min_width.3, self.rows.len(), context);
// subject column
_ = self.data_columns.columns[4].resize_with_context(min_width.4, self.rows.len(), context);
self.data_columns.segment_tree[0] = row_widths.0.into();
self.data_columns.segment_tree[1] = row_widths.1.into();
self.data_columns.segment_tree[2] = row_widths.2.into();
self.data_columns.segment_tree[3] = row_widths.3.into();
self.data_columns.segment_tree[4] = row_widths.4.into();
let iter = if self.filter_term.is_empty() {
Box::new(self.local_collection.iter().cloned())
@ -853,137 +882,159 @@ impl PlainListing {
let row_attr = self.rows.row_attr_cache[&idx];
let (x, _) = {
let area = columns[0].area().nth_row(idx);
columns[0].grid_mut().write_string(
&idx.to_string(),
row_attr.fg,
row_attr.bg,
row_attr.attrs,
area,
None,
)
};
for c in {
let area = columns[0].area();
columns[0].grid_mut().row_iter(area, x..min_width.0, idx)
} {
columns[0].grid_mut()[c]
.set_bg(row_attr.bg)
.set_attrs(row_attr.attrs);
{
let mut area_col_0 = columns[0].area().nth_row(idx);
if !*account_settings!(context[self.cursor_pos.0].listing.relative_list_indices) {
area_col_0 = area_col_0.skip_cols(columns[0].grid_mut().write_string(
&idx.to_string(),
row_attr.fg,
row_attr.bg,
row_attr.attrs,
area_col_0,
None,
));
for c in columns[0].grid().row_iter(area_col_0, 0..min_width.0, 0) {
columns[0].grid_mut()[c]
.set_bg(row_attr.bg)
.set_attrs(row_attr.attrs);
}
}
}
let (x, _) = {
let area = columns[1].area().nth_row(idx);
columns[1].grid_mut().write_string(
{
let mut area_col_1 = columns[1].area().nth_row(idx);
area_col_1 = area_col_1.skip_cols(columns[1].grid_mut().write_string(
&strings.date,
row_attr.fg,
row_attr.bg,
row_attr.attrs,
area,
area_col_1,
None,
)
};
for c in {
let area = columns[1].area();
columns[1].grid_mut().row_iter(area, x..min_width.1, idx)
} {
columns[1].grid_mut()[c]
.set_bg(row_attr.bg)
.set_attrs(row_attr.attrs);
));
for c in columns[1].grid().row_iter(area_col_1, 0..min_width.1, 0) {
columns[1].grid_mut()[c]
.set_bg(row_attr.bg)
.set_attrs(row_attr.attrs);
}
}
let (x, _) = {
let area = columns[2].area().nth_row(idx);
columns[2].grid_mut().write_string(
{
let area_col_2 = columns[2].area().nth_row(idx);
let (skip_cols, _) = columns[2].grid_mut().write_string(
&strings.from,
row_attr.fg,
row_attr.bg,
row_attr.attrs,
area,
area_col_2,
None,
)
};
for c in {
let area = columns[2].area();
columns[2].grid_mut().row_iter(area, x..min_width.2, idx)
} {
columns[2].grid_mut()[c]
.set_bg(row_attr.bg)
.set_attrs(row_attr.attrs)
.set_ch(' ');
);
#[cfg(feature = "regexp")]
{
for text_formatter in crate::conf::text_format_regexps(context, "listing.from")
{
let t = columns[2].grid_mut().insert_tag(text_formatter.tag);
for (start, end) in text_formatter.regexp.find_iter(strings.from.as_str()) {
columns[2].grid_mut().set_tag(
t,
(start + skip_cols, idx),
(end + skip_cols, idx),
);
}
}
}
for c in columns[2]
.grid()
.row_iter(area_col_2, skip_cols..min_width.2, 0)
{
columns[2].grid_mut()[c]
.set_bg(row_attr.bg)
.set_attrs(row_attr.attrs);
}
}
let (x, _) = {
let area = columns[3].area().nth_row(idx);
columns[3].grid_mut().write_string(
{
let mut area_col_3 = columns[3].area().nth_row(idx);
area_col_3 = area_col_3.skip_cols(columns[3].grid_mut().write_string(
&strings.flag,
row_attr.fg,
row_attr.bg,
row_attr.attrs,
area,
area_col_3,
None,
)
};
let x = {
let area = columns[3].area().nth_row(idx).skip_cols(x);
columns[3]
.grid_mut()
.write_string(
&strings.subject,
row_attr.fg,
));
if strings.highlight_self {
let (x, _) = columns[3].grid_mut().write_string(
mailbox_settings!(
context[self.cursor_pos.0][&self.cursor_pos.1]
.listing
.highlight_self_flag
)
.as_ref()
.map(|s| s.as_str())
.unwrap_or(super::DEFAULT_HIGHLIGHT_SELF_FLAG),
self.color_cache.highlight_self.fg,
row_attr.bg,
row_attr.attrs,
area,
row_attr.attrs | Attr::FORCE_TEXT,
area_col_3,
None,
)
.0
+ x
};
let mut x = x + 1;
for (t, &color) in strings.tags.split_whitespace().zip(strings.tags.1.iter()) {
let color = color.unwrap_or(self.color_cache.tag_default.bg);
let _x = {
let area = columns[3].area().nth_row(idx).skip_cols(x + 1);
columns[3]
.grid_mut()
.write_string(
t,
self.color_cache.tag_default.fg,
color,
self.color_cache.tag_default.attrs,
area,
None,
)
.0
+ x
+ 1
};
for c in {
let area = columns[3].area();
columns[3].grid_mut().row_iter(area, x..(x + 1), idx)
} {
columns[3].grid_mut()[c].set_bg(color);
}
for c in {
let area = columns[3].area();
columns[3].grid_mut().row_iter(area, _x..(_x + 1), idx)
} {
columns[3].grid_mut()[c].set_bg(color).set_keep_bg(true);
);
for c in columns[3].grid().row_iter(area_col_3, 0..x, 0) {
columns[3].grid_mut()[c].set_keep_fg(true);
}
area_col_3 = area_col_3.skip_cols(x + 1);
}
for c in {
let area = columns[3].area();
columns[3].grid_mut().row_iter(area, (x + 1)..(_x + 1), idx)
} {
for c in columns[3].grid().row_iter(area_col_3, 0..min_width.3, 0) {
columns[3].grid_mut()[c]
.set_keep_fg(true)
.set_keep_bg(true)
.set_keep_attrs(true);
.set_bg(row_attr.bg)
.set_attrs(row_attr.attrs);
}
for c in {
let area = columns[3].area();
columns[3].grid_mut().row_iter(area, x..(x + 1), idx)
} {
columns[3].grid_mut()[c].set_keep_bg(true);
}
{
let mut area_col_4 = columns[4].area().nth_row(idx);
area_col_4 = area_col_4.skip_cols(columns[4].grid_mut().write_string(
&strings.subject,
row_attr.fg,
row_attr.bg,
row_attr.attrs,
area_col_4,
None,
));
#[cfg(feature = "regexp")]
{
for text_formatter in
crate::conf::text_format_regexps(context, "listing.subject")
{
let t = columns[4].grid_mut().insert_tag(text_formatter.tag);
for (start, end) in
text_formatter.regexp.find_iter(strings.subject.as_str())
{
columns[4].grid_mut().set_tag(t, (start, idx), (end, idx));
}
}
}
area_col_4 = area_col_4.skip_cols(1);
for (t, &color) in strings.tags.split_whitespace().zip(strings.tags.1.iter()) {
let color = color.unwrap_or(self.color_cache.tag_default.bg);
let (x, _) = columns[4].grid_mut().write_string(
t,
self.color_cache.tag_default.fg,
color,
self.color_cache.tag_default.attrs,
area_col_4.skip_cols(1),
None,
);
for c in columns[4].grid().row_iter(area_col_4, 0..(x + 1), 0) {
columns[4].grid_mut()[c]
.set_bg(color)
.set_keep_fg(true)
.set_keep_bg(true)
.set_keep_attrs(true);
}
area_col_4 = area_col_4.skip_cols(x + 1);
}
for c in columns[4].grid().row_iter(area_col_4, 0..min_width.4, 0) {
columns[4].grid_mut()[c]
.set_ch(' ')
.set_bg(row_attr.bg)
.set_attrs(row_attr.attrs);
}
x = _x + 2;
}
}
if self.length == 0 && self.filter_term.is_empty() {
@ -1033,21 +1084,9 @@ impl PlainListing {
let strings = self.make_entry_string(&envelope, context);
drop(envelope);
let columns = &mut self.data_columns.columns;
{
let area = columns[0].area().nth_row(idx);
columns[0].grid_mut().clear_area(area, row_attr)
};
{
let area = columns[1].area().nth_row(idx);
columns[1].grid_mut().clear_area(area, row_attr);
}
{
let area = columns[2].area().nth_row(idx);
columns[2].grid_mut().clear_area(area, row_attr);
}
{
let area = columns[3].area().nth_row(idx);
columns[3].grid_mut().clear_area(area, row_attr);
for n in 0..=4 {
let area = columns[n].area().nth_row(idx);
columns[n].grid_mut().clear_area(area, row_attr);
}
let (x, _) = {
@ -1062,8 +1101,8 @@ impl PlainListing {
)
};
for c in {
let area = columns[0].area();
columns[0].grid_mut().row_iter(area, x..area.width(), idx)
let area = columns[0].area().nth_row(idx);
columns[0].grid_mut().row_iter(area, x..area.width(), 0)
} {
columns[0].grid_mut()[c]
.set_bg(row_attr.bg)
@ -1081,8 +1120,8 @@ impl PlainListing {
)
};
for c in {
let area = columns[1].area();
columns[1].grid_mut().row_iter(area, x..area.width(), idx)
let area = columns[1].area().nth_row(idx);
columns[1].grid_mut().row_iter(area, x..area.width(), 0)
} {
columns[1].grid_mut()[c]
.set_bg(row_attr.bg)
@ -1100,85 +1139,101 @@ impl PlainListing {
)
};
for c in {
let area = columns[2].area();
columns[2].grid_mut().row_iter(area, x..area.width(), idx)
let area = columns[2].area().nth_row(idx);
columns[2].grid_mut().row_iter(area, x..area.width(), 0)
} {
columns[2].grid_mut()[c]
.set_bg(row_attr.bg)
.set_attrs(row_attr.attrs);
}
let (x, _) = {
let area = columns[3].area().nth_row(idx);
columns[3].grid_mut().write_string(
{
let mut area_col_3 = columns[3].area().nth_row(idx);
area_col_3 = area_col_3.skip_cols(columns[3].grid_mut().write_string(
&strings.flag,
row_attr.fg,
row_attr.bg,
row_attr.attrs,
area,
area_col_3,
None,
)
};
let (x, _) = {
let area = columns[3].area().nth_row(idx).skip_cols(x);
columns[3].grid_mut().write_string(
));
if strings.highlight_self {
let (x, _) = columns[3].grid_mut().write_string(
mailbox_settings!(
context[self.cursor_pos.0][&self.cursor_pos.1]
.listing
.highlight_self_flag
)
.as_ref()
.map(|s| s.as_str())
.unwrap_or(super::DEFAULT_HIGHLIGHT_SELF_FLAG),
self.color_cache.highlight_self.fg,
row_attr.bg,
row_attr.attrs | Attr::FORCE_TEXT,
area_col_3,
None,
);
for c in columns[3].grid().row_iter(area_col_3, 0..x, 0) {
columns[3].grid_mut()[c].set_keep_fg(true);
}
area_col_3 = area_col_3.skip_cols(x + 1);
}
for c in columns[3]
.grid()
.row_iter(area_col_3, 0..area_col_3.width(), 0)
{
columns[3].grid_mut()[c]
.set_bg(row_attr.bg)
.set_attrs(row_attr.attrs);
}
}
{
let mut area_col_4 = columns[4].area().nth_row(idx);
area_col_4 = area_col_4.skip_cols(columns[4].grid_mut().write_string(
&strings.subject,
row_attr.fg,
row_attr.bg,
row_attr.attrs,
area,
area_col_4,
None,
)
};
let x = {
let mut x = x + 1;
));
#[cfg(feature = "regexp")]
{
for text_formatter in crate::conf::text_format_regexps(context, "listing.subject") {
let t = columns[4].grid_mut().insert_tag(text_formatter.tag);
for (start, end) in text_formatter.regexp.find_iter(strings.subject.as_str()) {
columns[4].grid_mut().set_tag(t, (start, idx), (end, idx));
}
}
}
area_col_4 = area_col_4.skip_cols(1);
for (t, &color) in strings.tags.split_whitespace().zip(strings.tags.1.iter()) {
let color = color.unwrap_or(self.color_cache.tag_default.bg);
let (_x, _) = {
let area = columns[3].area().nth_row(idx).skip_cols(x + 1);
columns[3].grid_mut().write_string(
t,
self.color_cache.tag_default.fg,
color,
self.color_cache.tag_default.attrs,
area,
None,
)
};
for c in {
let area = columns[3].area();
columns[3].grid_mut().row_iter(area, x..(x + 1), idx)
} {
columns[3].grid_mut()[c].set_bg(color);
}
for c in {
let area = columns[3].area();
columns[3].grid_mut().row_iter(area, _x..(_x + 1), idx)
} {
columns[3].grid_mut()[c].set_bg(color).set_keep_bg(true);
}
for c in {
let area = columns[3].area();
columns[3].grid_mut().row_iter(area, (x + 1)..(_x + 1), idx)
} {
columns[3].grid_mut()[c].set_keep_fg(true).set_keep_bg(true);
}
for c in {
let area = columns[3].area();
columns[3].grid_mut().row_iter(area, x..(x + 1), idx)
} {
columns[3].grid_mut()[c].set_keep_bg(true);
let (x, _) = columns[4].grid_mut().write_string(
t,
self.color_cache.tag_default.fg,
color,
self.color_cache.tag_default.attrs,
area_col_4.skip_cols(1),
None,
);
for c in columns[4].grid().row_iter(area_col_4, 0..(x + 1), 0) {
columns[4].grid_mut()[c]
.set_bg(color)
.set_keep_fg(true)
.set_keep_bg(true)
.set_keep_attrs(true);
}
x = _x + 2;
area_col_4 = area_col_4.skip_cols(x + 1);
}
for c in columns[4]
.grid()
.row_iter(area_col_4, 0..area_col_4.width(), 0)
{
columns[4].grid_mut()[c]
.set_ch(' ')
.set_bg(row_attr.bg)
.set_attrs(row_attr.attrs);
}
x
};
for c in {
let area = columns[3].area();
columns[3].grid().row_iter(area, x..area.width(), idx)
} {
columns[3].grid_mut()[c]
.set_bg(row_attr.bg)
.set_attrs(row_attr.attrs);
}
*self.rows.entries.get_mut(idx).unwrap() = ((thread_hash, env_hash), strings);
}
@ -1229,6 +1284,49 @@ impl PlainListing {
}
}
fn draw_relative_numbers(&mut self, grid: &mut CellBuffer, area: Area, top_idx: usize) {
let width = self.data_columns.columns[0].area().width();
let area = area.take_cols(width);
for i in 0..area.height() {
if top_idx + i >= self.length {
break;
}
let row_attr = if let Some(env_hash) = self.get_env_under_cursor(top_idx + i) {
let unseen = self
.rows
.entries
.get(top_idx + i)
.map(|((_, _), strings)| strings.unseen)
.unwrap_or(false);
row_attr!(
self.color_cache,
even: (top_idx + i) % 2 == 0,
unseen: unseen,
highlighted: self.cursor_pos.2 == (top_idx + i),
selected: self.rows.selection[&env_hash]
)
} else {
row_attr!(self.color_cache, even: (top_idx + i) % 2 == 0, unseen: false, highlighted: true, selected: false)
};
grid.clear_area(area.nth_row(i), row_attr);
grid.write_string(
&if self.new_cursor_pos.2.saturating_sub(top_idx) == i {
self.new_cursor_pos.2.to_string()
} else {
(i as isize - (self.new_cursor_pos.2 - top_idx) as isize)
.abs()
.to_string()
},
row_attr.fg,
row_attr.bg,
row_attr.attrs,
area.nth_row(i),
None,
);
}
}
fn perform_movement(&mut self, height: Option<usize>) {
let rows = height.unwrap_or(1);
if let Some(mvm) = self.movement.take() {

@ -19,12 +19,12 @@
* along with meli. If not, see <http://www.gnu.org/licenses/>.
*/
use std::{cmp, convert::TryInto, iter::FromIterator};
use std::{convert::TryInto, iter::FromIterator};
use melib::{Address, SortField, SortOrder, ThreadNode, Threads};
use super::*;
use crate::{components::PageMovement, jobs::JoinHandle};
use crate::{components::PageMovement, jobs::JoinHandle, segment_tree::SegmentTree};
macro_rules! row_attr {
($color_cache:expr, even: $even:expr, unseen: $unseen:expr, highlighted: $highlighted:expr, selected: $selected:expr $(,)*) => {{
@ -146,6 +146,7 @@ pub struct ThreadListing {
filtered_selection: Vec<EnvelopeHash>,
_filtered_order: HashMap<EnvelopeHash, usize>,
data_columns: DataColumns<5>,
rows_drawn: SegmentTree,
rows: RowsState<(ThreadHash, EnvelopeHash)>,
seen_cache: IndexMap<EnvelopeHash, bool>,
/// If we must redraw on next redraw event
@ -300,6 +301,16 @@ impl MailListingTrait for ThreadListing {
.listing
.threaded_repeat_identical_from_values
);
let should_highlight_self = mailbox_settings!(
context[self.cursor_pos.0][&self.cursor_pos.1]
.listing
.highlight_self
)
.is_true();
let my_address: Address = context.accounts[&self.cursor_pos.0]
.settings
.account
.make_display_name();
while let Some((indentation, thread_node_hash, has_sibling)) = iter.next() {
let thread_node = &thread_nodes[&thread_node_hash];
@ -321,6 +332,8 @@ impl MailListingTrait for ThreadListing {
prev_group = threads.find_group(thread_node.group);
let mut entry_strings = self.make_entry_string(&envelope, context);
entry_strings.highlight_self =
should_highlight_self && envelope.recipient_any(&my_address);
entry_strings.subject = SubjectString(Self::make_thread_entry(
&envelope,
indentation,
@ -363,11 +376,10 @@ impl MailListingTrait for ThreadListing {
.try_into()
.unwrap_or(255),
);
min_width.1 = cmp::max(min_width.1, entry_strings.date.grapheme_width()); /* date */
min_width.2 = cmp::max(min_width.2, entry_strings.from.grapheme_width()); /* from */
min_width.3 = cmp::max(min_width.3, entry_strings.flag.grapheme_width()); /* flags */
min_width.4 = cmp::max(
min_width.4,
min_width.1 = min_width.1.max(entry_strings.date.grapheme_width()); /* date */
min_width.2 = min_width.2.max(entry_strings.from.grapheme_width()); /* from */
min_width.3 = min_width.3.max(entry_strings.flag.grapheme_width()); /* flags */
min_width.4 = min_width.4.max(
entry_strings.subject.grapheme_width()
+ 1
+ entry_strings.tags.grapheme_width(),
@ -432,6 +444,12 @@ impl MailListingTrait for ThreadListing {
_ = self.data_columns.columns[4].resize_with_context(min_width.4, self.rows.len(), context);
self.data_columns.segment_tree[4] = row_widths.4.into();
self.rows_drawn = SegmentTree::from(
std::iter::repeat(1)
.take(self.rows.len())
.collect::<SmallVec<_>>(),
);
debug_assert_eq!(self.rows_drawn.array.len(), self.rows.len());
self.draw_rows(
context,
0,
@ -516,16 +534,14 @@ impl ListingTrait for ThreadListing {
let page_no = (self.new_cursor_pos.2).wrapping_div(rows);
let top_idx = page_no * rows;
let end_idx = self.length.saturating_sub(1).min(top_idx + rows - 1);
self.draw_rows(context, top_idx, end_idx);
// If cursor position has changed, remove the highlight from the previous
// position and apply it in the new one.
if self.cursor_pos.2 != self.new_cursor_pos.2 && prev_page_no == page_no {
let old_cursor_pos = self.cursor_pos;
self.cursor_pos = self.new_cursor_pos;
if *account_settings!(context[self.cursor_pos.0].listing.relative_list_indices) {
self.draw_relative_numbers(grid, area, top_idx);
context.dirty_areas.push_back(area);
}
for &(idx, highlight) in &[(old_cursor_pos.2, false), (self.new_cursor_pos.2, true)] {
if idx >= self.length {
continue; //bounds check
@ -541,6 +557,10 @@ impl ListingTrait for ThreadListing {
}
context.dirty_areas.push_back(new_area);
}
if *account_settings!(context[self.cursor_pos.0].listing.relative_list_indices) {
self.draw_relative_numbers(grid, area, top_idx);
context.dirty_areas.push_back(area);
}
if !self.force_draw {
return;
}
@ -557,12 +577,6 @@ impl ListingTrait for ThreadListing {
grid.clear_area(area, self.color_cache.theme_default);
}
self.draw_rows(
context,
top_idx,
self.length.saturating_sub(1).min(top_idx + rows - 1),
);
// Page_no has changed, so draw new page
_ = self.data_columns.recalc_widths(area.size(), top_idx);
// copy table columns
@ -745,6 +759,7 @@ impl ThreadListing {
subsort: (Default::default(), Default::default()),
color_cache: ColorCache::new(context, IndexStyle::Threaded),
data_columns: DataColumns::default(),
rows_drawn: SegmentTree::default(),
rows: RowsState::default(),
seen_cache: IndexMap::default(),
filter_term: String::new(),
@ -875,6 +890,7 @@ impl ThreadListing {
),
from: FromString(Address::display_name_slice(e.from())),
tags: TagString(tags, colors),
unseen: !e.is_seen(),
highlight_self: false,
}
}
@ -884,6 +900,12 @@ impl ThreadListing {
return;
}
debug_assert!(end >= start);
if self.rows_drawn.get_max(start, end) == 0 {
return;
}
for i in start..=end {
self.rows_drawn.update(i, 0);
}
let min_width = (
self.data_columns.columns[0].area().width(),
self.data_columns.columns[1].area().width(),
@ -891,6 +913,7 @@ impl ThreadListing {
self.data_columns.columns[3].area().width(),
self.data_columns.columns[4].area().width(),
);
let columns = &mut self.data_columns.columns;
for (idx, ((_thread_hash, env_hash), strings)) in self
.rows
@ -907,152 +930,159 @@ impl ThreadListing {
self.color_cache,
even: idx % 2 == 0,
unseen: !self.seen_cache[env_hash],
highlighted: self.cursor_pos.2 == idx,
selected: self.rows.selection[env_hash]
highlighted: false,
selected: false,
);
self.rows.row_attr_cache.insert(idx, row_attr);
{
let area = self.data_columns.columns[0].area();
let mut area_col_0 = columns[0].area().nth_row(idx);
if !*account_settings!(context[self.cursor_pos.0].listing.relative_list_indices) {
let (x, _) = self.data_columns.columns[0].grid_mut().write_string(
area_col_0 = area_col_0.skip_cols(columns[0].grid_mut().write_string(
&idx.to_string(),
row_attr.fg,
row_attr.bg,
row_attr.attrs,
area.nth_row(idx),
area_col_0,
None,
);
for x in x..min_width.0 {
self.data_columns.columns[0].grid_mut()[(x, idx)]
));
for c in columns[0].grid().row_iter(area_col_0, 0..min_width.0, 0) {
columns[0].grid_mut()[c]
.set_bg(row_attr.bg)
.set_attrs(row_attr.attrs);
}
}
}
{
let area = self.data_columns.columns[1].area();
let (x, _) = self.data_columns.columns[1].grid_mut().write_string(
let mut area_col_1 = columns[1].area().nth_row(idx);
area_col_1 = area_col_1.skip_cols(columns[1].grid_mut().write_string(
&strings.date,
row_attr.fg,
row_attr.bg,
row_attr.attrs,
area.nth_row(idx),
area_col_1,
None,
);
for x in x..min_width.1 {
self.data_columns.columns[1].grid_mut()[(x, idx)]
));
for c in columns[1].grid().row_iter(area_col_1, 0..min_width.1, 0) {
columns[1].grid_mut()[c]
.set_bg(row_attr.bg)
.set_attrs(row_attr.attrs);
}
}
{
let area = self.data_columns.columns[2].area();
let (x, _) = self.data_columns.columns[2].grid_mut().write_string(
let area_col_2 = columns[2].area().nth_row(idx);
let (skip_cols, _) = columns[2].grid_mut().write_string(
&strings.from,
row_attr.fg,
row_attr.bg,
row_attr.attrs,
area.nth_row(idx),
area_col_2,
None,
);
#[cfg(feature = "regexp")]
{
for text_formatter in crate::conf::text_format_regexps(context, "listing.from")
{
let t = self.data_columns.columns[2]
.grid_mut()
.insert_tag(text_formatter.tag);
let t = columns[2].grid_mut().insert_tag(text_formatter.tag);
for (start, end) in text_formatter.regexp.find_iter(strings.from.as_str()) {
self.data_columns.columns[2].grid_mut().set_tag(
columns[2].grid_mut().set_tag(
t,
(start, idx),
(end, idx),
(start + skip_cols, idx),
(end + skip_cols, idx),
);
}
}
}
for x in x..min_width.2 {
self.data_columns.columns[2].grid_mut()[(x, idx)]
for c in columns[2]
.grid()
.row_iter(area_col_2, skip_cols..min_width.2, 0)
{
columns[2].grid_mut()[c]
.set_bg(row_attr.bg)
.set_attrs(row_attr.attrs);
}
}
{
let area = self.data_columns.columns[3].area();
let (x, _) = self.data_columns.columns[3].grid_mut().write_string(
let mut area_col_3 = columns[3].area().nth_row(idx);
area_col_3 = area_col_3.skip_cols(columns[3].grid_mut().write_string(
&strings.flag,
row_attr.fg,
row_attr.bg,
row_attr.attrs,
area.nth_row(idx),
area_col_3,
None,
);
for x in x..min_width.3 {
self.data_columns.columns[3].grid_mut()[(x, idx)]
));
if strings.highlight_self {
let (x, _) = columns[3].grid_mut().write_string(
mailbox_settings!(
context[self.cursor_pos.0][&self.cursor_pos.1]
.listing
.highlight_self_flag
)
.as_ref()
.map(|s| s.as_str())
.unwrap_or(super::DEFAULT_HIGHLIGHT_SELF_FLAG),
self.color_cache.highlight_self.fg,
row_attr.bg,
row_attr.attrs | Attr::FORCE_TEXT,
area_col_3,
None,
);
for c in columns[3].grid().row_iter(area_col_3, 0..x, 0) {
columns[3].grid_mut()[c].set_keep_fg(true);
}
area_col_3 = area_col_3.skip_cols(x + 1);
}
for c in columns[3].grid().row_iter(area_col_3, 0..min_width.3, 0) {
columns[3].grid_mut()[c]
.set_bg(row_attr.bg)
.set_attrs(row_attr.attrs);
}
}
{
let area = self.data_columns.columns[4].area();
let (x, _) = self.data_columns.columns[4].grid_mut().write_string(
let mut area_col_4 = columns[4].area().nth_row(idx);
area_col_4 = area_col_4.skip_cols(columns[4].grid_mut().write_string(
&strings.subject,
row_attr.fg,
row_attr.bg,
row_attr.attrs,
area.nth_row(idx),
area_col_4,
None,
);
));
#[cfg(feature = "regexp")]
{
for text_formatter in
crate::conf::text_format_regexps(context, "listing.subject")
{
let t = self.data_columns.columns[4]
.grid_mut()
.insert_tag(text_formatter.tag);
let t = columns[4].grid_mut().insert_tag(text_formatter.tag);
for (start, end) in
text_formatter.regexp.find_iter(strings.subject.as_str())
{
self.data_columns.columns[4].grid_mut().set_tag(
t,
(start, idx),
(end, idx),
);
columns[4].grid_mut().set_tag(t, (start, idx), (end, idx));
}
}
}
let x = {
let mut x = x + 1;
let area = self.data_columns.columns[4].area();
for (t, &color) in strings.tags.split_whitespace().zip(strings.tags.1.iter()) {
let color = color.unwrap_or(self.color_cache.tag_default.bg);
let (_x, _) = self.data_columns.columns[4].grid_mut().write_string(
t,
self.color_cache.tag_default.fg,
color,
self.color_cache.tag_default.attrs,
area.nth_row(idx).skip_cols(x + 1),
None,
);
self.data_columns.columns[4].grid_mut()[(x, idx)].set_bg(color);
if _x < min_width.4 {
self.data_columns.columns[4].grid_mut()[(_x, idx)]
.set_bg(color)
.set_keep_bg(true);
}
for x in (x + 1).._x {
self.data_columns.columns[4].grid_mut()[(x, idx)]
.set_keep_fg(true)
.set_keep_bg(true)
.set_keep_attrs(true);
}
self.data_columns.columns[4].grid_mut()[(x, idx)].set_keep_bg(true);
x = _x + 1;
area_col_4 = area_col_4.skip_cols(1);
for (t, &color) in strings.tags.split_whitespace().zip(strings.tags.1.iter()) {
let color = color.unwrap_or(self.color_cache.tag_default.bg);
let (x, _) = columns[4].grid_mut().write_string(
t,
self.color_cache.tag_default.fg,
color,
self.color_cache.tag_default.attrs,
area_col_4.skip_cols(1),
None,
);
for c in columns[4].grid().row_iter(area_col_4, 0..(x + 1), 0) {
columns[4].grid_mut()[c]
.set_bg(color)
.set_keep_fg(true)
.set_keep_bg(true)
.set_keep_attrs(true);
}
x
};
for x in x..min_width.4 {
self.data_columns.columns[4].grid_mut()[(x, idx)]
area_col_4 = area_col_4.skip_cols(x + 1);
}
for c in columns[4].grid().row_iter(area_col_4, 0..min_width.4, 0) {
columns[4].grid_mut()[c]
.set_ch(' ')
.set_bg(row_attr.bg)
.set_attrs(row_attr.attrs);
@ -1081,24 +1111,52 @@ impl ThreadListing {
);
self.seen_cache.insert(env_hash, envelope.is_seen());
let mut strings = self.make_entry_string(&envelope, context);
let should_highlight_self = mailbox_settings!(
context[self.cursor_pos.0][&self.cursor_pos.1]
.listing
.highlight_self
)
.is_true();
let mut entry_strings = self.make_entry_string(&envelope, context);
entry_strings.highlight_self = should_highlight_self && {
let my_address: Address = context.accounts[&self.cursor_pos.0]
.settings
.account
.make_display_name();
envelope.recipient_any(&my_address)
};
// [ref:FIXME]: generate new tree indentation for this new row subject
// entry_strings.subject = SubjectString(Self::make_thread_entry(
// &envelope,
// indentation,
// thread_node_hash,
// &threads,
// &indentations,
// has_sibling,
// is_root,
// ));
drop(envelope);
std::mem::swap(
&mut self.rows.entries.get_mut(idx).unwrap().1.subject,
&mut strings.subject,
&mut entry_strings.subject,
);
let columns = &mut self.data_columns.columns;
for n in 0..=4 {
let area = columns[n].area().nth_row(idx);
columns[n].grid_mut().clear_area(area, row_attr);
}
self.rows_drawn.update(idx, 1);
*self.rows.entries.get_mut(idx).unwrap() = ((thread_hash, env_hash), strings);
*self.rows.entries.get_mut(idx).unwrap() = ((thread_hash, env_hash), entry_strings);
}
fn draw_relative_numbers(&mut self, grid: &mut CellBuffer, area: Area, top_idx: usize) {
let width = self.data_columns.columns[0].area().width();
let area = area.take_cols(width);
for i in 0..area.height() {
if top_idx + i >= self.length {
break;
}
let row_attr = if let Some(env_hash) = self.get_env_under_cursor(top_idx + i) {
row_attr!(
self.color_cache,
@ -1111,27 +1169,7 @@ impl ThreadListing {
row_attr!(self.color_cache, even: (top_idx + i) % 2 == 0, unseen: false, highlighted: true, selected: false)
};
let idx_col_area = self.data_columns.columns[0].area();
self.data_columns.columns[0]
.grid_mut()
.clear_area(idx_col_area, row_attr);
grid.clear_area(area.nth_row(i).take_cols(width), row_attr);
self.data_columns.columns[0].grid_mut().write_string(
&if self.new_cursor_pos.2.saturating_sub(top_idx) == i {
self.new_cursor_pos.2.to_string()
} else {
(i as isize - (self.new_cursor_pos.2 - top_idx) as isize)
.abs()
.to_string()
},
row_attr.fg,
row_attr.bg,
row_attr.attrs,
idx_col_area.nth_row(i),
None,
);
grid.clear_area(area.nth_row(i), row_attr);
grid.write_string(
&if self.new_cursor_pos.2.saturating_sub(top_idx) == i {
self.new_cursor_pos.2.to_string()
@ -1143,7 +1181,7 @@ impl ThreadListing {
row_attr.fg,
row_attr.bg,
row_attr.attrs,
area.nth_row(i).take_cols(width),
area.nth_row(i),
None,
);
}
@ -1425,7 +1463,6 @@ impl Component for ThreadListing {
if self.force_draw {
/* Draw the entire list */
self.draw_list(grid, area, context);
self.force_draw = false;
}
} else {
/* Draw the entire list */
@ -1438,6 +1475,7 @@ impl Component for ThreadListing {
context.dirty_areas.push_back(area);
}
}
self.force_draw = false;
self.dirty = false;
}
@ -1602,9 +1640,9 @@ impl Component for ThreadListing {
Err(err) => {
context.replies.push_back(UIEvent::Notification {
title: Some("Could not perform search".into()),
source: None,
body: err.to_string().into(),
kind: Some(crate::types::NotificationType::Error(err.kind)),
source: Some(err),
});
}
};
@ -1628,9 +1666,9 @@ impl Component for ThreadListing {
Ok(Some(Err(err))) => {
context.replies.push_back(UIEvent::Notification {
title: Some("Could not perform search".into()),
source: None,
body: err.to_string().into(),
kind: Some(crate::types::NotificationType::Error(err.kind)),
source: Some(err),
});
}
}

@ -48,6 +48,7 @@ impl ScreenGeneration {
pub const NIL: Self = Self((0, 0));
#[inline]
#[must_use]
pub fn next(self) -> Self {
Self(uuid::Uuid::new_v4().as_u64_pair())
}
@ -521,6 +522,30 @@ impl<D: private::Sealed> From<&Screen<D>> for Area {
}
}
/// Convenience trait to turn both single `usize` values and `(usize, _)`
/// positions to `x` coordinate.
pub trait IntoColumns: private::Sealed {
#[must_use]
fn into(self) -> usize;
}
impl private::Sealed for usize {}
impl private::Sealed for Pos {}
impl IntoColumns for usize {
#[must_use]
fn into(self) -> usize {
self
}
}
impl IntoColumns for Pos {
#[must_use]
fn into(self) -> usize {
get_x(self)
}
}
impl Area {
#[inline]
pub fn height(&self) -> usize {
@ -545,6 +570,7 @@ impl Area {
/// Get `n`th row of `area` or its last one.
#[inline]
#[must_use]
pub fn nth_row(&self, n: usize) -> Self {
let Self {
offset,
@ -574,6 +600,7 @@ impl Area {
/// Get `n`th col of `area` or its last one.
#[inline]
#[must_use]
pub fn nth_col(&self, n: usize) -> Self {
let Self {
offset,
@ -602,6 +629,7 @@ impl Area {
}
/// Place box given by `(width, height)` in corner of `area`
#[must_use]
pub fn place_inside(&self, (width, height): (usize, usize), upper: bool, left: bool) -> Self {
if self.is_empty() || width < 3 || height < 3 {
return *self;
@ -644,6 +672,7 @@ impl Area {
/// Place given area of dimensions `(width, height)` inside `area` according
/// to given alignment
#[must_use]
pub fn align_inside(
&self,
(width, height): (usize, usize),
@ -677,6 +706,7 @@ impl Area {
/// Place box given by `dimensions` in center of `area`
#[inline]
#[must_use]
pub fn center_inside(&self, dimensions: (usize, usize)) -> Self {
self.align_inside(dimensions, Alignment::Center, Alignment::Center)
}
@ -712,6 +742,7 @@ impl Area {
/// assert_eq!(body.height(), 18);
/// ```
#[inline]
#[must_use]
pub fn skip_rows(&self, n: usize) -> Self {
let n = std::cmp::min(n, self.height());
if self.is_empty() || self.upper_left.1 + n > self.bottom_right.1 {
@ -743,6 +774,7 @@ impl Area {
/// assert_eq!(header, area.take_rows(2));
/// ```
#[inline]
#[must_use]
pub fn skip_rows_from_end(&self, n: usize) -> Self {
let n = std::cmp::min(n, self.height());
if self.is_empty() || self.bottom_right.1 < n {
@ -755,6 +787,21 @@ impl Area {
}
}
#[inline]
#[must_use]
fn _skip_cols_inner(&self, n: usize) -> Self {
let n = std::cmp::min(n, self.width());
if self.is_empty() || self.bottom_right.0 < self.upper_left.0 + n {
return self.into_empty();
}
Self {
offset: pos_inc(self.offset, (n, 0)),
upper_left: pos_inc(self.upper_left, (n, 0)),
..*self
}
}
/// Skip the first `n` rows and return the remaining area.
/// Return value will be an empty area if `n` is more than the width.
///
@ -772,17 +819,10 @@ impl Area {
/// assert_eq!(indent.width(), 118);
/// ```
#[inline]
pub fn skip_cols(&self, n: usize) -> Self {
let n = std::cmp::min(n, self.width());
if self.is_empty() || self.bottom_right.0 < self.upper_left.0 + n {
return self.into_empty();
}
Self {
offset: pos_inc(self.offset, (n, 0)),
upper_left: pos_inc(self.upper_left, (n, 0)),
..*self
}
#[must_use]
pub fn skip_cols(&self, n: impl IntoColumns) -> Self {
let n: usize = n.into();
self._skip_cols_inner(n)
}
/// Skip the last `n` rows and return the remaining area.
@ -803,6 +843,7 @@ impl Area {
/// assert_eq!(indent, area.take_cols(118));
/// ```
#[inline]
#[must_use]
pub fn skip_cols_from_end(&self, n: usize) -> Self {
let n = std::cmp::min(n, self.width());
if self.is_empty() || self.bottom_right.0 < n {
@ -816,6 +857,7 @@ impl Area {
/// Shortcut for using `Area::skip_cols` and `Area::skip_rows` together.
#[inline]
#[must_use]
pub fn skip(&self, n_cols: usize, n_rows: usize) -> Self {
self.skip_cols(n_cols).skip_rows(n_rows)
}
@ -837,6 +879,7 @@ impl Area {
/// assert_eq!(header.height(), 2);
/// ```
#[inline]
#[must_use]
pub fn take_rows(&self, n: usize) -> Self {
let n = std::cmp::min(n, self.height());
if self.is_empty() || self.bottom_right.1 < (self.height() - n) {
@ -869,6 +912,7 @@ impl Area {
/// assert_eq!(header.width(), 2);
/// ```
#[inline]
#[must_use]
pub fn take_cols(&self, n: usize) -> Self {
let n = std::cmp::min(n, self.width());
if self.is_empty() || self.bottom_right.0 < (self.width() - n) {
@ -886,41 +930,49 @@ impl Area {
/// Shortcut for using `Area::take_cols` and `Area::take_rows` together.
#[inline]
#[must_use]
pub fn take(&self, n_cols: usize, n_rows: usize) -> Self {
self.take_cols(n_cols).take_rows(n_rows)
}
#[inline]
#[must_use]
pub const fn upper_left(&self) -> Pos {
self.upper_left
}
#[inline]
#[must_use]
pub const fn bottom_right(&self) -> Pos {
self.bottom_right
}
#[inline]
#[must_use]
pub const fn upper_right(&self) -> Pos {
set_x(self.upper_left, get_x(self.bottom_right))
}
#[inline]
#[must_use]
pub const fn bottom_left(&self) -> Pos {
set_y(self.upper_left, get_y(self.bottom_right))
}
#[inline]
#[must_use]
pub const fn offset(&self) -> Pos {
self.offset
}
#[inline]
#[must_use]
pub const fn generation(&self) -> ScreenGeneration {
self.generation
}
#[inline]
#[must_use]
pub const fn new_empty(generation: ScreenGeneration) -> Self {
Self {
offset: (0, 0),
@ -934,6 +986,7 @@ impl Area {
}
#[inline]
#[must_use]
pub const fn into_empty(self) -> Self {
Self {
offset: (0, 0),
@ -945,6 +998,7 @@ impl Area {
}
#[inline]
#[must_use]
pub const fn is_empty(&self) -> bool {
self.empty
|| (self.upper_left.0 > self.bottom_right.0 || self.upper_left.1 > self.bottom_right.1)
@ -952,26 +1006,31 @@ impl Area {
}
#[inline(always)]
#[must_use]
const fn pos_inc(p: Pos, inc: (usize, usize)) -> Pos {
(p.0 + inc.0, p.1 + inc.1)
}
#[inline(always)]
#[must_use]
const fn get_x(p: Pos) -> usize {
p.0
}
#[inline(always)]
#[must_use]
const fn get_y(p: Pos) -> usize {
p.1
}
#[inline(always)]
#[must_use]
const fn set_x(p: Pos, new_x: usize) -> Pos {
(new_x, p.1)
}
#[inline(always)]
#[must_use]
const fn set_y(p: Pos, new_y: usize) -> Pos {
(p.0, new_y)
}

@ -214,7 +214,7 @@ impl<const N: usize> DataColumns<N> {
width_accum += self.widths[i];
}
// add column gaps
width_accum += 2 * N.saturating_sub(1);
width_accum += N.saturating_sub(1);
debug_assert!(growees >= growees_max);
if width_accum >= screen_width || screen_height == 0 || screen_width == 0 || growees == 0 {
self.width_accum = width_accum;
@ -260,7 +260,7 @@ impl<const N: usize> DataColumns<N> {
break;
}
x_offset -= self.widths[col];
x_offset = x_offset.saturating_sub(2);
x_offset = x_offset.saturating_sub(1);
}
for col in start_col..N {

@ -4,7 +4,7 @@ version = "0.8.5"
authors = ["Manos Pitsidianakis <manos@pitsidianak.is>"]
edition = "2021"
build = "build.rs"
rust-version = "1.68.2"
rust-version = "1.70.0"
homepage = "https://meli-email.org"
repository = "https://git.meli-email.org/meli/meli.git"

@ -859,6 +859,16 @@ impl Envelope {
pub fn tags_mut(&mut self) -> &mut IndexSet<TagHash> {
&mut self.tags
}
/// Returns `true` if `is_recipient` address is included in To:, Cc: or Bcc:
/// headers.
pub fn recipient_any(&self, is_recipient: &Address) -> bool {
self.to()
.iter()
.chain(self.cc().iter())
.chain(self.bcc().iter())
.any(|a| a == is_recipient)
}
}
impl Eq for Envelope {}

@ -335,6 +335,7 @@ pub enum ErrorKind {
Network(NetworkErrorKind),
TimedOut,
OSError,
Platform,
NotImplemented,
NotSupported,
ValueError,
@ -354,6 +355,7 @@ impl std::fmt::Display for ErrorKind {
fmt,
"Protocol is not supported. It could be the wrong type or version."
),
Self::Platform => write!(fmt, "Platform/Runtime environment; OS or hardware"),
Self::TimedOut => write!(fmt, "Timed Out"),
Self::OSError => write!(fmt, "OS Error"),
Self::Configuration => write!(fmt, "Configuration"),

@ -1334,12 +1334,24 @@ pub fn quoted(input: &[u8]) -> IResult<&[u8], Vec<u8>> {
}
let mut i = 1;
let mut escape_next = false;
while i < input.len() {
if input[i] == b'\"' && input[i - 1] != b'\\' {
return match crate::email::parser::encodings::phrase(&input[1..i], false) {
Ok((_, out)) => Ok((&input[i + 1..], out)),
e => e,
};
match (input[i], escape_next) {
(b'\\', false) => {
escape_next = true;
}
(b'\\', true) => {
escape_next = false;
}
(b'\"', false) => {
return match crate::email::parser::encodings::phrase(&input[1..i], false) {
Ok((_, out)) => Ok((&input[i + 1..], out)),
e => e,
};
}
_ => {
escape_next = false;
}
}
i += 1;
}

@ -169,6 +169,7 @@ mod tests {
);
assert_eq!("●".grapheme_width(), 1);
assert_eq!("●📎".grapheme_width(), 3);
assert_eq!("●📎︎".grapheme_width(), 3);
assert_eq!("●\u{FE0E}📎\u{FE0E}".grapheme_width(), 3);
assert_eq!("🎃".grapheme_width(), 2);
assert_eq!("👻".grapheme_width(), 2);

Loading…
Cancel
Save