1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-11 03:27:05 +03:00

fix bounds for scrolling

unfortunately this is super expensive and halves the cat test perf.
This commit is contained in:
Wez Furlong 2018-02-19 11:26:19 -08:00
parent b0fa3c329f
commit 58f423eebe
2 changed files with 47 additions and 2 deletions

View File

@ -207,12 +207,18 @@ impl Screen {
}
};
let remove_idx = if scroll_region.start == 0 {
0
} else {
phys_scroll.start
};
// To avoid thrashing the heap, prefer to move lines that were
// scrolled off the top and re-use them at the bottom.
let to_move = lines_removed.min(num_rows);
let (to_remove, to_add) = {
for _ in 0..to_move {
let mut line = self.lines.remove(phys_scroll.start);
let mut line = self.lines.remove(remove_idx);
// Make the line like a new one of the appropriate width
line.reset(self.physical_cols);
if scroll_region.end as usize == self.physical_rows {
@ -228,7 +234,7 @@ impl Screen {
// Perform the removal
for _ in 0..to_remove {
self.lines.remove(phys_scroll.start);
self.lines.remove(remove_idx);
}
if scroll_region.end as usize == self.physical_rows {

View File

@ -266,6 +266,15 @@ bitflags! {
}
}
fn print_all_lines(term: &Terminal) {
let screen = term.screen();
println!("whole screen contents are:");
for line in screen.lines.iter() {
println!("[{}]", line.as_str());
}
}
fn print_visible_lines(term: &Terminal) {
let screen = term.screen();
@ -288,6 +297,15 @@ fn assert_visible_contents(term: &Terminal, expect_lines: &[&str]) {
assert_lines_equal(screen.visible_lines(), &expect, Compare::TEXT);
}
fn assert_all_contents(term: &Terminal, expect_lines: &[&str]) {
print_all_lines(&term);
let screen = term.screen();
let expect: Vec<Line> = expect_lines.iter().map(|s| (*s).into()).collect();
assert_lines_equal(&screen.lines, &expect, Compare::TEXT);
}
#[test]
fn basic_output() {
let mut term = TestTerm::new(5, 10, 0);
@ -407,6 +425,27 @@ fn test_delete_lines() {
term.assert_dirty_lines(&[1, 2, 3, 4], None);
}
#[test]
fn test_scrollup() {
let mut term = TestTerm::new(2, 1, 4);
term.print("1\n");
assert_all_contents(&term, &["1", " "]);
term.print("2\n");
assert_all_contents(&term, &["1", "2", " "]);
term.print("3\n");
assert_all_contents(&term, &["1", "2", "3", " "]);
term.print("4\n");
assert_all_contents(&term, &["1", "2", "3", "4", " "]);
term.print("5\n");
assert_all_contents(&term, &["1", "2", "3", "4", "5", " "]);
term.print("6\n");
assert_all_contents(&term, &["2", "3", "4", "5", "6", " "]);
term.print("7\n");
assert_all_contents(&term, &["3", "4", "5", "6", "7", " "]);
term.print("8\n");
assert_all_contents(&term, &["4", "5", "6", "7", "8", " "]);
}
#[test]
fn test_hyperlinks() {
let mut term = TestTerm::new(3, 5, 0);