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(compatibility): ansi scroll down #1279

Merged
merged 2 commits into from
Mar 28, 2022
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
3 changes: 3 additions & 0 deletions src/tests/fixtures/scroll_down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@


line1line2
33 changes: 17 additions & 16 deletions zellij-server/src/panes/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -814,30 +814,31 @@ impl Grid {
}
}
pub fn rotate_scroll_region_up(&mut self, count: usize) {
if let Some((scroll_region_top, scroll_region_bottom)) = self.scroll_region {
if let Some((scroll_region_top, scroll_region_bottom)) = self
.scroll_region
.or(Some((0, self.height.saturating_sub(1))))
{
for _ in 0..count {
let columns = VecDeque::from(vec![EMPTY_TERMINAL_CHARACTER; self.width]);
if scroll_region_bottom < self.viewport.len() {
self.viewport.remove(scroll_region_bottom);
}
if scroll_region_top < self.viewport.len() {
self.viewport
.insert(scroll_region_top, Row::from_columns(columns).canonical());
if self.cursor.y >= scroll_region_top && self.cursor.y <= scroll_region_bottom {
self.pad_lines_until(scroll_region_bottom, EMPTY_TERMINAL_CHARACTER);
if self.viewport.get(scroll_region_bottom).is_some() {
self.viewport.remove(scroll_region_bottom);
}
}
}
self.output_buffer.update_all_lines(); // TODO: only update scroll region lines
}
}
pub fn rotate_scroll_region_down(&mut self, count: usize) {
if let Some((scroll_region_top, scroll_region_bottom)) = self.scroll_region {
if let Some((scroll_region_top, scroll_region_bottom)) = self
.scroll_region
.or(Some((0, self.height.saturating_sub(1))))
{
for _ in 0..count {
let columns = VecDeque::from(vec![EMPTY_TERMINAL_CHARACTER; self.width]);
self.viewport.remove(scroll_region_top);
if self.viewport.len() > scroll_region_top {
self.viewport
.insert(scroll_region_bottom, Row::from_columns(columns).canonical());
} else {
self.viewport.push(Row::from_columns(columns).canonical());
if self.cursor.y >= scroll_region_top && self.cursor.y <= scroll_region_bottom {
self.pad_lines_until(scroll_region_top, EMPTY_TERMINAL_CHARACTER);
self.viewport.remove(scroll_region_top);
self.pad_lines_until(scroll_region_bottom, EMPTY_TERMINAL_CHARACTER);
}
}
self.output_buffer.update_all_lines(); // TODO: only update scroll region lines
Expand Down
17 changes: 17 additions & 0 deletions zellij-server/src/panes/unit/grid_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1602,3 +1602,20 @@ pub fn replace_non_wide_characters_with_wide_characters() {
}
assert_snapshot!(format!("{:?}", grid));
}

#[test]
pub fn scroll_down_ansi() {
let mut vte_parser = vte::Parser::new();
let mut grid = Grid::new(
51,
112,
Palette::default(),
Rc::new(RefCell::new(LinkHandler::new())),
);
let fixture_name = "scroll_down";
let content = read_fixture(fixture_name);
for byte in content {
vte_parser.advance(&mut grid, byte);
}
assert_snapshot!(format!("{:?}", grid));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
source: zellij-server/src/panes/./unit/grid_tests.rs
assertion_line: 1620
expression: "format!(\"{:?}\", grid)"
---
00 (C):
01 (C): line1
02 (C): line2
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):
48 (C):
49 (C):
50 (C):