summaryrefslogtreecommitdiffstats
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
parent896f8dc698da62b5925d65dbe046c5d50b9b44ee (diff)
hotfix(truncation): display long uneven hostnames properly (fixes small issue in #177)
-rw-r--r--src/display/components/table.rs5
-rw-r--r--src/tests/cases/snapshots/ui__rearranged_by_tab-3.snap2
-rw-r--r--src/tests/cases/snapshots/ui__truncate_long_hostnames.snap4
3 files changed, 6 insertions, 5 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)
}
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 <interface_na[..]1:12345 (tcp)
+ .1.1.1 1 0Bps / 22Bps <interface_n[...]:12345 (tcp)
diff --git a/src/tests/cases/snapshots/ui__truncate_long_hostnames.snap b/src/tests/cases/snapshots/ui__truncate_long_hostnames.snap
index 12da2e3..ff2bcd8 100644
--- a/src/tests/cases/snapshots/ui__truncate_long_hostnames.snap
+++ b/src/tests/cases/snapshots/ui__truncate_long_hostnames.snap
@@ -7,7 +7,7 @@ expression: "&terminal_draw_events_mirror[1]"
1 1 28Bps / 30Bps i.am.not.too.long 1 28Bps / 30Bps
- 5 1 17Bps / 18Bps i.am.an.obnox[..].really.i.ask 1 17Bps / 18Bps
+ 5 1 17Bps / 18Bps i.am.an.obno[...]really.i.ask 1 17Bps / 18Bps
@@ -31,7 +31,7 @@ expression: "&terminal_draw_events_mirror[1]"
<interface_name>:443 => i.am.not.too.long:12345 (tcp) 1 28Bps / 30Bps
- <interface_name>:4435 => i.am.an.obnoxiosuly.lon[..]why.would.anyone.do.this.really.i.ask:1337 (tcp) 5 17Bps / 18Bps
+ <interface_name>:4435 => i.am.an.obnoxiosuly.lo[...]hy.would.anyone.do.this.really.i.ask:1337 (tcp) 5 17Bps / 18Bps