From ee2c5a6cdd6a07f18b99a50b9d2737bd8ea391c4 Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Tue, 25 Aug 2020 18:24:16 +0000 Subject: Unify term dimension calls Since the `Term` implements the `Dimensions` trait itself, we shouldn't call `term.grid()` to call methods from the `Dimensions` trait. This removes all instances of this that I could find in the code at the moment. --- alacritty_terminal/src/vi_mode.rs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'alacritty_terminal/src/vi_mode.rs') diff --git a/alacritty_terminal/src/vi_mode.rs b/alacritty_terminal/src/vi_mode.rs index 20b132dd..965cd3d5 100644 --- a/alacritty_terminal/src/vi_mode.rs +++ b/alacritty_terminal/src/vi_mode.rs @@ -66,14 +66,14 @@ impl ViModeCursor { #[must_use = "this returns the result of the operation, without modifying the original"] pub fn motion(mut self, term: &mut Term, motion: ViMotion) -> Self { let display_offset = term.grid().display_offset(); - let lines = term.grid().screen_lines(); - let cols = term.grid().cols(); + let lines = term.screen_lines(); + let cols = term.cols(); let mut buffer_point = term.visible_to_buffer(self.point); match motion { ViMotion::Up => { - if buffer_point.line + 1 < term.grid().total_lines() { + if buffer_point.line + 1 < term.total_lines() { buffer_point.line += 1; } }, @@ -82,7 +82,7 @@ impl ViModeCursor { buffer_point = term.expand_wide(buffer_point, Direction::Left); let wrap_point = Point::new(buffer_point.line + 1, cols - 1); if buffer_point.col.0 == 0 - && buffer_point.line + 1 < term.grid().total_lines() + && buffer_point.line + 1 < term.total_lines() && is_wrap(term, wrap_point) { buffer_point = wrap_point; @@ -101,7 +101,7 @@ impl ViModeCursor { ViMotion::First => { buffer_point = term.expand_wide(buffer_point, Direction::Left); while buffer_point.col.0 == 0 - && buffer_point.line + 1 < term.grid().total_lines() + && buffer_point.line + 1 < term.total_lines() && is_wrap(term, Point::new(buffer_point.line + 1, cols - 1)) { buffer_point.line += 1; @@ -165,7 +165,7 @@ impl ViModeCursor { pub fn scroll(mut self, term: &Term, lines: isize) -> Self { // Check number of lines the cursor needs to be moved. let overscroll = if lines > 0 { - let max_scroll = term.grid().history_size() - term.grid().display_offset(); + let max_scroll = term.history_size() - term.grid().display_offset(); max(0, lines - max_scroll as isize) } else { let max_scroll = term.grid().display_offset(); @@ -175,12 +175,12 @@ impl ViModeCursor { // Clamp movement to within visible region. let mut line = self.point.line.0 as isize; line -= overscroll; - line = max(0, min(term.grid().screen_lines().0 as isize - 1, line)); + line = max(0, min(term.screen_lines().0 as isize - 1, line)); // Find the first occupied cell after scrolling has been performed. let buffer_point = term.visible_to_buffer(self.point); let mut target_line = buffer_point.line as isize + lines; - target_line = max(0, min(term.grid().total_lines() as isize - 1, target_line)); + target_line = max(0, min(term.total_lines() as isize - 1, target_line)); let col = first_occupied_in_line(term, target_line as usize).unwrap_or_default().col; // Move cursor. @@ -192,7 +192,7 @@ impl ViModeCursor { /// Find next end of line to move to. fn last(term: &Term, mut point: Point) -> Point { - let cols = term.grid().cols(); + let cols = term.cols(); // Expand across wide cells. point = term.expand_wide(point, Direction::Right); @@ -218,7 +218,7 @@ fn last(term: &Term, mut point: Point) -> Point { /// Find next non-empty cell to move to. fn first_occupied(term: &Term, mut point: Point) -> Point { - let cols = term.grid().cols(); + let cols = term.cols(); // Expand left across wide chars, since we're searching lines left to right. point = term.expand_wide(point, Direction::Left); @@ -232,7 +232,7 @@ fn first_occupied(term: &Term, mut point: Point) -> Point { let mut occupied = None; // Search for non-empty cell in previous lines. - for line in (point.line + 1)..term.grid().total_lines() { + for line in (point.line + 1)..term.total_lines() { if !is_wrap(term, Point::new(line, cols - 1)) { break; } @@ -352,14 +352,14 @@ fn word( /// Find first non-empty cell in line. fn first_occupied_in_line(term: &Term, line: usize) -> Option> { - (0..term.grid().cols().0) + (0..term.cols().0) .map(|col| Point::new(line, Column(col))) .find(|&point| !is_space(term, point)) } /// Find last non-empty cell in line. fn last_occupied_in_line(term: &Term, line: usize) -> Option> { - (0..term.grid().cols().0) + (0..term.cols().0) .map(|col| Point::new(line, Column(col))) .rfind(|&point| !is_space(term, point)) } @@ -386,8 +386,8 @@ fn is_wrap(term: &Term, point: Point) -> bool { /// Check if point is at screen boundary. fn is_boundary(term: &Term, point: Point, direction: Direction) -> bool { - let total_lines = term.grid().total_lines(); - let num_cols = term.grid().cols(); + let total_lines = term.total_lines(); + let num_cols = term.cols(); (point.line + 1 >= total_lines && point.col.0 == 0 && direction == Direction::Left) || (point.line == 0 && point.col + 1 >= num_cols && direction == Direction::Right) } -- cgit v1.2.3-54-g00ecf