status page: trim extension name at 30 chars
NNTP has some long protocol extension namesmemfd
parent
c5d0a6c3b6
commit
890000bd0e
|
@ -31,11 +31,46 @@ pub use line_break::*;
|
||||||
pub use wcwidth::*;
|
pub use wcwidth::*;
|
||||||
|
|
||||||
pub trait Truncate {
|
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 {
|
impl Truncate for &str {
|
||||||
fn truncate_at_boundary(self, new_len: usize) {
|
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() {
|
if new_len >= self.len() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -49,6 +84,23 @@ impl Truncate for &mut String {
|
||||||
String::truncate(self, last);
|
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 {
|
pub trait GlobMatch {
|
||||||
|
|
|
@ -548,7 +548,11 @@ impl Component for AccountStatus {
|
||||||
);
|
);
|
||||||
let max_name_width = std::cmp::max(
|
let max_name_width = std::cmp::max(
|
||||||
"Server Extensions:".len(),
|
"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(
|
write_string_to_grid(
|
||||||
"meli support:",
|
"meli support:",
|
||||||
|
@ -563,7 +567,7 @@ impl Component for AccountStatus {
|
||||||
for (i, (name, status)) in extensions.into_iter().enumerate() {
|
for (i, (name, status)) in extensions.into_iter().enumerate() {
|
||||||
let (width, height) = self.content.size();
|
let (width, height) = self.content.size();
|
||||||
write_string_to_grid(
|
write_string_to_grid(
|
||||||
&name,
|
name.trim_at_boundary(30),
|
||||||
&mut self.content,
|
&mut self.content,
|
||||||
self.theme_default.fg,
|
self.theme_default.fg,
|
||||||
self.theme_default.bg,
|
self.theme_default.bg,
|
||||||
|
|
Loading…
Reference in New Issue