summaryrefslogtreecommitdiffstats
path: root/src/display
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2020-09-01 10:10:11 +0200
committerAram Drevekenin <aram@poor.dev>2020-09-01 10:10:11 +0200
commit8b4bdf07891fea614b2705ceb568981feb73940e (patch)
treea06d416271e75f7dfa99109058531ce567d3a463 /src/display
parent896f8dc698da62b5925d65dbe046c5d50b9b44ee (diff)
hotfix(truncation): display long uneven hostnames properly (fixes small issue in #177)
Diffstat (limited to 'src/display')
-rw-r--r--src/display/components/table.rs5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/display/components/table.rs b/src/display/components/table.rs
index f61886c..8628054 100644
--- a/src/display/components/table.rs
+++ b/src/display/components/table.rs
@@ -70,7 +70,8 @@ fn truncate_middle(row: &str, max_length: u16) -> String {
if max_length < 6 {
truncate_iter_to_unicode_width(row.chars(), max_length as usize)
} else if row.len() as u16 > max_length {
- let split_point = (max_length as usize / 2) - 2;
+ let split_point = (max_length as usize / 2) - 3;
+ // why 3? 5 is the max size of the truncation text ([...] or [..]), 3 is ~5/2
let first_slice = truncate_iter_to_unicode_width::<_, String>(row.chars(), split_point);
let second_slice =
truncate_iter_to_unicode_width::<_, Vec<_>>(row.chars().rev(), split_point)
@@ -78,7 +79,7 @@ fn truncate_middle(row: &str, max_length: u16) -> String {
.rev()
.collect::<String>();
if max_length % 2 == 0 {
- format!("{}[..]{}", first_slice, second_slice)
+ format!("{}[...]{}", first_slice, second_slice)
} else {
format!("{}[..]{}", first_slice, second_slice)
}