Browse Source

status page: trim extension name at 30 chars

NNTP has some long protocol extension names
tags/alpha-0.6.1
parent
commit
890000bd0e
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS. GPG Key ID: 73627C2F690DF710
2 changed files with 61 additions and 5 deletions
  1. +55
    -3
      melib/src/text_processing/mod.rs
  2. +6
    -2
      src/components/mail/status.rs

+ 55
- 3
melib/src/text_processing/mod.rs View File

@@ -31,11 +31,46 @@ pub use line_break::*;
pub use wcwidth::*;

pub trait Truncate {
fn truncate_at_boundary(self, new_len: usize);
fn truncate_at_boundary(&mut self, new_len: usize);
fn trim_at_boundary(&self, new_len: usize) -> &str;
}

impl Truncate for &mut String {
fn truncate_at_boundary(self, new_len: usize) {
impl Truncate for &str {
fn truncate_at_boundary(&mut self, new_len: usize) {
if new_len >= self.len() {
return;
}

extern crate unicode_segmentation;
use unicode_segmentation::UnicodeSegmentation;
if let Some((last, _)) = UnicodeSegmentation::grapheme_indices(*self, true)
.take(new_len)
.last()
{
*self = &self[..last];
}
}

fn trim_at_boundary(&self, new_len: usize) -> &str {
if new_len >= self.len() {
return self;
}

extern crate unicode_segmentation;
use unicode_segmentation::UnicodeSegmentation;
if let Some((last, _)) = UnicodeSegmentation::grapheme_indices(*self, true)
.take(new_len)
.last()
{
&self[..last]
} else {
self
}
}
}

impl Truncate for String {
fn truncate_at_boundary(&mut self, new_len: usize) {
if new_len >= self.len() {
return;
}
@@ -49,6 +84,23 @@ impl Truncate for &mut String {
String::truncate(self, last);
}
}

fn trim_at_boundary(&self, new_len: usize) -> &str {
if new_len >= self.len() {
return self;
}

extern crate unicode_segmentation;
use unicode_segmentation::UnicodeSegmentation;
if let Some((last, _)) = UnicodeSegmentation::grapheme_indices(self.as_str(), true)
.take(new_len)
.last()
{
&self[..last]
} else {
self.as_str()
}
}
}

pub trait GlobMatch {


+ 6
- 2
src/components/mail/status.rs View File

@@ -548,7 +548,11 @@ impl Component for AccountStatus {
);
let max_name_width = std::cmp::max(
"Server Extensions:".len(),
extensions.iter().map(|(n, _)| n.len()).max().unwrap_or(0),
extensions
.iter()
.map(|(n, _)| std::cmp::min(30, n.len()))
.max()
.unwrap_or(0),
);
write_string_to_grid(
"meli support:",
@@ -563,7 +567,7 @@ impl Component for AccountStatus {
for (i, (name, status)) in extensions.into_iter().enumerate() {
let (width, height) = self.content.size();
write_string_to_grid(
&name,
name.trim_at_boundary(30),
&mut self.content,
self.theme_default.fg,
self.theme_default.bg,


Loading…
Cancel
Save