From 8b4bdf07891fea614b2705ceb568981feb73940e Mon Sep 17 00:00:00 2001 From: Aram Drevekenin Date: Tue, 1 Sep 2020 10:10:11 +0200 Subject: hotfix(truncation): display long uneven hostnames properly (fixes small issue in #177) --- src/display/components/table.rs | 5 +++-- src/tests/cases/snapshots/ui__rearranged_by_tab-3.snap | 2 +- src/tests/cases/snapshots/ui__truncate_long_hostnames.snap | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) (limited to 'src') 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::(); if max_length % 2 == 0 { - format!("{}[..]{}", first_slice, second_slice) + format!("{}[...]{}", first_slice, second_slice) } else { format!("{}[..]{}", first_slice, second_slice) } diff --git a/src/tests/cases/snapshots/ui__rearranged_by_tab-3.snap b/src/tests/cases/snapshots/ui__rearranged_by_tab-3.snap index 7f7797f..e6e653b 100644 --- a/src/tests/cases/snapshots/ui__rearranged_by_tab-3.snap +++ b/src/tests/cases/snapshots/ui__rearranged_by_tab-3.snap @@ -6,7 +6,7 @@ expression: "&terminal_draw_events_mirror[2]" remote addr ss connection──── Remote Address Connections Up / Down Connection Proc ss - .1.1.1 1 0Bps / 22Bps :443 => i.am.not.too.long:12345 (tcp) 1 28Bps / 30Bps - :4435 => i.am.an.obnoxiosuly.lon[..]why.would.anyone.do.this.really.i.ask:1337 (tcp) 5 17Bps / 18Bps + :4435 => i.am.an.obnoxiosuly.lo[...]hy.would.anyone.do.this.really.i.ask:1337 (tcp) 5 17Bps / 18Bps -- cgit v1.2.3