Fix title widechar overflow (#1361)

* fix(ui): make sure wide characters don't cause a title overflow

* style(fmt): rustfmt
This commit is contained in:
Aram Drevekenin 2022-04-29 10:30:30 +02:00 committed by GitHub
parent 8984d1eef6
commit 640d1058a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 81 additions and 6 deletions

2
src/tests/fixtures/title-wide-chars vendored Normal file
View file

@ -0,0 +1,2 @@
]0;Remixed by BEMANI Sound Team 'TAG feat. PON' - 新宝島\

View file

@ -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): │────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────│

View file

@ -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): └────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

View file

@ -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);
}

View file

@ -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;