From 640d1058a4fcf6df93af9dc391c412236afc5a6b Mon Sep 17 00:00:00 2001 From: Aram Drevekenin Date: Fri, 29 Apr 2022 10:30:30 +0200 Subject: [PATCH] Fix title widechar overflow (#1361) * fix(ui): make sure wide characters don't cause a title overflow * style(fmt): rustfmt --- src/tests/fixtures/title-wide-chars | 2 + ...s__replacing_existing_wide_characters.snap | 4 +- ...s__wide_characters_in_left_title_side.snap | 54 +++++++++++++++++++ .../src/tab/unit/tab_integration_tests.rs | 22 ++++++++ zellij-server/src/ui/pane_boundaries_frame.rs | 5 +- 5 files changed, 81 insertions(+), 6 deletions(-) create mode 100644 src/tests/fixtures/title-wide-chars create mode 100644 zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__wide_characters_in_left_title_side.snap diff --git a/src/tests/fixtures/title-wide-chars b/src/tests/fixtures/title-wide-chars new file mode 100644 index 00000000..7d6af840 --- /dev/null +++ b/src/tests/fixtures/title-wide-chars @@ -0,0 +1,2 @@ +]0;Remixed by BEMANI Sound Team 'TAG feat. PON' - 新宝島\ + diff --git a/zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__replacing_existing_wide_characters.snap b/zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__replacing_existing_wide_characters.snap index bce2c604..b783b646 100644 --- a/zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__replacing_existing_wide_characters.snap +++ b/zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__replacing_existing_wide_characters.snap @@ -1,9 +1,9 @@ --- source: zellij-server/src/tab/./unit/tab_integration_tests.rs +assertion_line: 1096 expression: snapshot - --- -00 (C): ┌ Remixed by BEMANI Sound Team 'TAG feat. PON' - 新宝島 ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── +00 (C): ┌ Remixed by BEMANI Sound Team 'TAG feat. PON' - 新宝島 ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ 01 (C): │0:14/1:59 ──┤ 新宝島 ├── Vol: 39%│ 02 (C): │[playing] Remixed by BEMANI Sound Team 'TAG feat. PON' - beatmania IIDX 28 BISTROVER Original Soundtrack (Disc2) (2021) [------]│ 03 (C): │────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────│ diff --git a/zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__wide_characters_in_left_title_side.snap b/zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__wide_characters_in_left_title_side.snap new file mode 100644 index 00000000..1a5d98f0 --- /dev/null +++ b/zellij-server/src/tab/unit/snapshots/zellij_server__tab__tab_integration_tests__wide_characters_in_left_title_side.snap @@ -0,0 +1,54 @@ +--- +source: zellij-server/src/tab/./unit/tab_integration_tests.rs +assertion_line: 1118 +expression: snapshot +--- +00 (C): ┌ Remixed by BEMANI Sound Team 'TAG feat. PON' - 新宝島 ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ +01 (C): │ │ +02 (C): │ │ +03 (C): │ │ +04 (C): │ │ +05 (C): │ │ +06 (C): │ │ +07 (C): │ │ +08 (C): │ │ +09 (C): │ │ +10 (C): │ │ +11 (C): │ │ +12 (C): │ │ +13 (C): │ │ +14 (C): │ │ +15 (C): │ │ +16 (C): │ │ +17 (C): │ │ +18 (C): │ │ +19 (C): │ │ +20 (C): │ │ +21 (C): │ │ +22 (C): │ │ +23 (C): │ │ +24 (C): │ │ +25 (C): │ │ +26 (C): │ │ +27 (C): │ │ +28 (C): │ │ +29 (C): │ │ +30 (C): │ │ +31 (C): │ │ +32 (C): │ │ +33 (C): │ │ +34 (C): │ │ +35 (C): │ │ +36 (C): │ │ +37 (C): │ │ +38 (C): │ │ +39 (C): │ │ +40 (C): │ │ +41 (C): │ │ +42 (C): │ │ +43 (C): │ │ +44 (C): │ │ +45 (C): │ │ +46 (C): │ │ +47 (C): └────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ + diff --git a/zellij-server/src/tab/unit/tab_integration_tests.rs b/zellij-server/src/tab/unit/tab_integration_tests.rs index c9f3fcf7..636d9ba6 100644 --- a/zellij-server/src/tab/unit/tab_integration_tests.rs +++ b/zellij-server/src/tab/unit/tab_integration_tests.rs @@ -1095,3 +1095,25 @@ fn replacing_existing_wide_characters() { ); assert_snapshot!(snapshot); } + +#[test] +fn wide_characters_in_left_title_side() { + // this test makes sure the title doesn't overflow when it has wide characters + let size = Size { + cols: 238, + rows: 48, + }; + let client_id = 1; + let mut tab = create_new_tab(size); + let mut output = Output::default(); + let pane_content = read_fixture("title-wide-chars"); + tab.handle_pty_bytes(1, pane_content); + tab.render(&mut output, None); + let snapshot = take_snapshot( + output.serialize().get(&client_id).unwrap(), + size.rows, + size.cols, + Palette::default(), + ); + assert_snapshot!(snapshot); +} diff --git a/zellij-server/src/ui/pane_boundaries_frame.rs b/zellij-server/src/ui/pane_boundaries_frame.rs index 22812cb3..905c3b87 100644 --- a/zellij-server/src/ui/pane_boundaries_frame.rs +++ b/zellij-server/src/ui/pane_boundaries_frame.rs @@ -312,10 +312,7 @@ impl PaneFrame { if max_length <= 6 || self.title.is_empty() { None } else if full_text.width() <= max_length { - Some(( - foreground_color(&full_text, self.color), - full_text.chars().count(), - )) + Some((foreground_color(&full_text, self.color), full_text.width())) } else { let length_of_each_half = (max_length - middle_truncated_sign.width()) / 2;