Append ellipse to truncated labels.

This commit is contained in:
shy 2021-04-12 08:59:47 +02:00
parent 3021fdb848
commit a95c00aa57
2 changed files with 5 additions and 2 deletions

View file

@ -9,7 +9,7 @@ pub const COLOR: [&dyn termion::color::Color; 6] = [
]; ];
// Maximum length of labels. // Maximum length of labels.
pub const LABEL_SIZE_LIMIT: usize = 42; pub const LABEL_SIZE_LIMIT: usize = 32;
pub mod ui { pub mod ui {
pub const NAME: &str = env!("CARGO_PKG_NAME"); pub const NAME: &str = env!("CARGO_PKG_NAME");

View file

@ -8,7 +8,10 @@ pub fn unicode_length(input: &str) -> u16 {
pub fn unicode_truncate(input: &mut String, limit: usize) { pub fn unicode_truncate(input: &mut String, limit: usize) {
match UnicodeSegmentation::grapheme_indices(input.as_str(), true).nth(limit) { match UnicodeSegmentation::grapheme_indices(input.as_str(), true).nth(limit) {
Some((i, _)) => input.truncate(i), Some((i, _)) => {
input.truncate(i);
input.push('…');
},
None => (), None => (),
} }
} }