From faa2dc11e470e131f57426699a9f1aa80354695b Mon Sep 17 00:00:00 2001 From: Joe Wilm Date: Wed, 19 Apr 2017 20:08:44 -0700 Subject: [PATCH] Pass scrolling region tests in vttest 2 --- src/grid.rs | 17 +++++++---------- src/term/mod.rs | 39 +++++++-------------------------------- 2 files changed, 14 insertions(+), 42 deletions(-) diff --git a/src/grid.rs b/src/grid.rs index af3a8ae4..8d1d051b 100644 --- a/src/grid.rs +++ b/src/grid.rs @@ -152,19 +152,16 @@ impl Grid { #[inline] pub fn scroll_down(&mut self, region: Range, positions: index::Line) { - for line in IndexRange(region).rev() { - let src = line; - let dst = line - positions; - self.swap_lines(src, dst); + for line in IndexRange((region.start + positions)..region.end).rev() { + self.swap_lines(line, line - positions); } } #[inline] pub fn scroll_up(&mut self, region: Range, positions: index::Line) { - for line in IndexRange(region) { - let src = line; - let dst = line + positions; - self.swap_lines(src, dst); + + for line in IndexRange(region.start..(region.end - positions)) { + self.swap_lines(line, line + positions); } } @@ -622,7 +619,7 @@ mod tests { info!("grid: {:?}", grid); - grid.scroll_up(Line(0)..Line(8), Line(2)); + grid.scroll_up(Line(0)..Line(10), Line(2)); info!("grid: {:?}", grid); @@ -656,7 +653,7 @@ mod tests { info!("grid: {:?}", grid); - grid.scroll_down(Line(2)..Line(10), Line(2)); + grid.scroll_down(Line(0)..Line(10), Line(2)); info!("grid: {:?}", grid); diff --git a/src/term/mod.rs b/src/term/mod.rs index 40fb58e1..e55af7ca 100644 --- a/src/term/mod.rs +++ b/src/term/mod.rs @@ -16,7 +16,7 @@ use std::mem; use std::ops::{Range, Index, IndexMut}; use std::ptr; -use std::cmp::min; +use std::cmp::{min, max}; use std::io; use std::time::{Duration, Instant}; @@ -962,26 +962,14 @@ impl Term { // Copy of cell template; can't have it borrowed when calling clear/scroll let template = self.empty_cell; - // Clear the entire region if lines is going to be greater than the region. - // This also ensures all the math below this if statement is sane. - if lines > self.scroll_region.end - origin { - self.grid.clear_region(origin..self.scroll_region.end, |c| c.reset(&template)); - return; - } - // Clear `lines` lines at bottom of area { - let end = self.scroll_region.end; - let start = Line(end.0.saturating_sub(lines.0)); - self.grid.clear_region(start..end, |c| c.reset(&template)); + let start = max(origin, Line(self.scroll_region.end.0.saturating_sub(lines.0))); + self.grid.clear_region(start..self.scroll_region.end, |c| c.reset(&template)); } // Scroll between origin and bottom - { - let end = self.scroll_region.end; - let start = origin + lines; - self.grid.scroll_down(start..end, lines); - } + self.grid.scroll_down(origin..self.scroll_region.end, lines); } /// Scroll screen up @@ -995,24 +983,14 @@ impl Term { // Copy of cell template; can't have it borrowed when calling clear/scroll let template = self.empty_cell; - // Clear the entire region if lines is going to be greater than the region. - // This also ensures all the math below this if statement is sane. - if lines > self.scroll_region.end - origin { - self.grid.clear_region(origin..self.scroll_region.end, |c| c.reset(&template)); - return; - } - // Clear `lines` lines starting from origin to origin + lines { - let end = min(origin + lines, self.grid.num_lines()); + let end = min(origin + lines, self.scroll_region.end); self.grid.clear_region(origin..end, |c| c.reset(&template)); } // Scroll from origin to bottom less number of lines - { - let end = self.scroll_region.end - lines; - self.grid.scroll_up(origin..end, lines); - } + self.grid.scroll_up(origin..self.scroll_region.end, lines); } fn deccolm(&mut self) { @@ -1049,9 +1027,6 @@ impl ansi::Handler for Term { /// A character to be displayed #[inline] fn input(&mut self, c: char) { - // The character is printed in yellow to differentiate from - // other logs. - print!("{}", ::util::fmt::Yellow(c)); if self.input_needs_wrap { if !self.mode.contains(mode::LINE_WRAP) { return; @@ -1132,7 +1107,7 @@ impl ansi::Handler for Term { fn goto(&mut self, line: Line, col: Column) { trace!("goto: line={}, col={}", line, col); let (y_offset, max_y) = if self.mode.contains(mode::ORIGIN) { - (self.scroll_region.start, self.scroll_region.end) + (self.scroll_region.start, self.scroll_region.end - 1) } else { (Line(0), self.grid.num_lines() - 1) };