Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(terminal): properly handle resizes in alternate screen #2654

Merged
merged 1 commit into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions zellij-server/src/output/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,12 @@ impl OutputBuffer {
if row_width < viewport_width {
let mut padding = vec![EMPTY_TERMINAL_CHARACTER; viewport_width - row_width];
terminal_characters.append(&mut padding);
} else if row_width > viewport_width {
let width_offset = row.excess_width_until(viewport_width);
let truncate_position = viewport_width.saturating_sub(width_offset);
if truncate_position < terminal_characters.len() {
terminal_characters.truncate(truncate_position);
}
}
terminal_characters
}
Expand Down
38 changes: 16 additions & 22 deletions zellij-server/src/panes/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -760,9 +760,16 @@ impl Grid {
if new_columns == 0 || new_rows == 0 {
return;
}
if self.alternate_screen_state.is_some() {
// in alternate screen we do nothing but log the new size, the program in the terminal
// is in control now...
self.height = new_rows;
self.width = new_columns;
return;
}
self.selection.reset();
self.sixel_grid.character_cell_size_possibly_changed();
if new_columns != self.width && self.alternate_screen_state.is_none() {
if new_columns != self.width {
self.horizontal_tabstops = create_horizontal_tabstops(new_columns);
let mut cursor_canonical_line_index = self.cursor_canonical_line_index();
let cursor_index_in_canonical_line = self.cursor_index_in_canonical_line();
Expand Down Expand Up @@ -917,14 +924,6 @@ impl Grid {
},
}
};
} else if new_columns != self.width && self.alternate_screen_state.is_some() {
// in alternate screen just truncate exceeding width
for row in &mut self.viewport {
if row.width() >= new_columns {
let truncate_at = row.position_accounting_for_widechars(new_columns);
row.columns.truncate(truncate_at);
}
}
}
if new_rows != self.height {
let current_viewport_row_count = self.viewport.len();
Expand Down Expand Up @@ -959,18 +958,13 @@ impl Grid {
.saturating_sub(row_count_to_transfer);
};
}
if self.alternate_screen_state.is_none() {
transfer_rows_from_viewport_to_lines_above(
&mut self.viewport,
&mut self.lines_above,
&mut self.sixel_grid,
row_count_to_transfer,
new_columns,
);
} else {
// in alternate screen, no scroll buffer, so just remove lines
self.viewport.drain(0..row_count_to_transfer);
}
transfer_rows_from_viewport_to_lines_above(
&mut self.viewport,
&mut self.lines_above,
&mut self.sixel_grid,
row_count_to_transfer,
new_columns,
);
},
Ordering::Equal => {},
}
Expand Down Expand Up @@ -1340,7 +1334,7 @@ impl Grid {
if character_width == 0 {
return;
}
if self.cursor.x + character_width > self.width {
if self.cursor.x + character_width > self.width && self.alternate_screen_state.is_none() {
if self.disable_linewrap {
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
---
source: zellij-server/src/panes/./unit/grid_tests.rs
assertion_line: 2137
expression: "format!(\"{:?}\", grid)"

---
00 (C): line12aaaa
01 (C): line13aaaa
02 (C): line14aaaa
03 (C): line15aaaa
04 (C): line16aaaa
05 (C): line17aaaa
06 (C): line18aaaa
07 (C): line19a🦀a
08 (C): line20a🦀
09 (C): line21🦀🦀
00 (C): line2aaaaaaaaaaaaaaa
01 (C): line3aaaaaaaaaaaaaaa
02 (C): line4aaaaaaaaaaaaaaa
03 (C): line5aaaaaaaaaaaaaaa
04 (C): line6aaaaaaaaaaaaaaa
05 (C): line7aaaaaaaaaaaaaaa
06 (C): line8aaaaaaaaaaaaaaa
07 (C): line9aaaaaaaaaaaaaaa
08 (C): line10aaaaaaaaaaaaaa
09 (C): line11aaaaaaaaaaaaaa
10 (C): line12aaaaaaaaaaaaaa
11 (C): line13aaaaaaaaaaaaaa
12 (C): line14aaaaaaaaaaaaaa
13 (C): line15aaaaaaaaaaaaaa
14 (C): line16aaaaaaaaaaaaaa
15 (C): line17aaaaaaaaaaaaaa
16 (C): line18aaaaaaaaaaaaaa
17 (C): line19a🦀aaaaaaaaaaa
18 (C): line20a🦀🦀aaaaaaaaa
19 (C): line21🦀🦀🦀🦀🦀🦀🦀