diff options
author | Christian Duerr <contact@christianduerr.com> | 2020-08-25 18:24:16 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-25 21:24:16 +0300 |
commit | ee2c5a6cdd6a07f18b99a50b9d2737bd8ea391c4 (patch) | |
tree | 3438919a4046c24fac4927f747bf3a07073f4430 /alacritty_terminal | |
parent | 6cfcd7c25930d0478bc35731543e37a2e0c8f13f (diff) | |
download | alacritty-ee2c5a6cdd6a07f18b99a50b9d2737bd8ea391c4.tar.gz alacritty-ee2c5a6cdd6a07f18b99a50b9d2737bd8ea391c4.zip |
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.
Diffstat (limited to 'alacritty_terminal')
-rw-r--r-- | alacritty_terminal/src/term/mod.rs | 26 | ||||
-rw-r--r-- | alacritty_terminal/src/vi_mode.rs | 30 |
2 files changed, 28 insertions, 28 deletions
diff --git a/alacritty_terminal/src/term/mod.rs b/alacritty_terminal/src/term/mod.rs index 993e6918..97025386 100644 --- a/alacritty_terminal/src/term/mod.rs +++ b/alacritty_terminal/src/term/mod.rs @@ -71,12 +71,12 @@ impl<'a> RenderableSearch<'a> { /// Create a new renderable search iterator. fn new<T>(term: &'a Term<T>) -> Self { let viewport_end = term.grid().display_offset(); - let viewport_start = viewport_end + term.grid().screen_lines().0 - 1; + let viewport_start = viewport_end + term.screen_lines().0 - 1; // Compute start of the first and end of the last line. let start_point = Point::new(viewport_start, Column(0)); let mut start = term.line_search_left(start_point); - let end_point = Point::new(viewport_end, term.grid().cols() - 1); + let end_point = Point::new(viewport_end, term.cols() - 1); let mut end = term.line_search_right(end_point); // Set upper bound on search before/after the viewport to prevent excessive blocking. @@ -986,7 +986,7 @@ impl<T> Term<T> { } else if let Some(selection) = self.selection.take() { // Move the selection if only number of lines changed. let delta = if num_lines > old_lines { - (num_lines - old_lines.0).saturating_sub(self.grid.history_size()) as isize + (num_lines - old_lines.0).saturating_sub(self.history_size()) as isize } else { let cursor_line = self.grid.cursor.point.line; -(min(old_lines - cursor_line - 1, old_lines - num_lines).0 as isize) @@ -1812,7 +1812,7 @@ impl<T: EventListener> Handler for Term<T> { }, } - let cursor_buffer_line = (self.grid.screen_lines() - self.grid.cursor.point.line - 1).0; + let cursor_buffer_line = (self.screen_lines() - self.grid.cursor.point.line - 1).0; self.selection = self .selection .take() @@ -1941,7 +1941,7 @@ impl<T: EventListener> Handler for Term<T> { self.selection = self.selection.take().filter(|s| !s.intersects_range(..num_lines)); }, - ansi::ClearMode::Saved if self.grid.history_size() > 0 => { + ansi::ClearMode::Saved if self.history_size() > 0 => { self.grid.clear_history(); self.selection = self.selection.take().filter(|s| !s.intersects_range(num_lines..)); @@ -2584,14 +2584,14 @@ mod tests { for _ in 0..19 { term.newline(); } - assert_eq!(term.grid.history_size(), 10); + assert_eq!(term.history_size(), 10); assert_eq!(term.grid.cursor.point, Point::new(Line(9), Column(0))); // Increase visible lines. size.height = 30.; term.resize(&size); - assert_eq!(term.grid.history_size(), 0); + assert_eq!(term.history_size(), 0); assert_eq!(term.grid.cursor.point, Point::new(Line(19), Column(0))); } @@ -2612,7 +2612,7 @@ mod tests { for _ in 0..19 { term.newline(); } - assert_eq!(term.grid.history_size(), 10); + assert_eq!(term.history_size(), 10); assert_eq!(term.grid.cursor.point, Point::new(Line(9), Column(0))); // Enter alt screen. @@ -2625,7 +2625,7 @@ mod tests { // Leave alt screen. term.unset_mode(ansi::Mode::SwapScreenAndSetRestoreCursor); - assert_eq!(term.grid().history_size(), 0); + assert_eq!(term.history_size(), 0); assert_eq!(term.grid.cursor.point, Point::new(Line(19), Column(0))); } @@ -2646,14 +2646,14 @@ mod tests { for _ in 0..19 { term.newline(); } - assert_eq!(term.grid.history_size(), 10); + assert_eq!(term.history_size(), 10); assert_eq!(term.grid.cursor.point, Point::new(Line(9), Column(0))); // Increase visible lines. size.height = 5.; term.resize(&size); - assert_eq!(term.grid().history_size(), 15); + assert_eq!(term.history_size(), 15); assert_eq!(term.grid.cursor.point, Point::new(Line(4), Column(0))); } @@ -2674,7 +2674,7 @@ mod tests { for _ in 0..19 { term.newline(); } - assert_eq!(term.grid.history_size(), 10); + assert_eq!(term.history_size(), 10); assert_eq!(term.grid.cursor.point, Point::new(Line(9), Column(0))); // Enter alt screen. @@ -2687,7 +2687,7 @@ mod tests { // Leave alt screen. term.unset_mode(ansi::Mode::SwapScreenAndSetRestoreCursor); - assert_eq!(term.grid().history_size(), 15); + assert_eq!(term.history_size(), 15); assert_eq!(term.grid.cursor.point, Point::new(Line(4), Column(0))); } 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<T: EventListener>(mut self, term: &mut Term<T>, 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<T: EventListener>(mut self, term: &Term<T>, 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<T>(term: &Term<T>, mut point: Point<usize>) -> Point<usize> { - 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<T>(term: &Term<T>, mut point: Point<usize>) -> Point<usize> { /// Find next non-empty cell to move to. fn first_occupied<T>(term: &Term<T>, mut point: Point<usize>) -> Point<usize> { - 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<T>(term: &Term<T>, mut point: Point<usize>) -> Point<usize> { 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<T: EventListener>( /// Find first non-empty cell in line. fn first_occupied_in_line<T>(term: &Term<T>, line: usize) -> Option<Point<usize>> { - (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<T>(term: &Term<T>, line: usize) -> Option<Point<usize>> { - (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<T>(term: &Term<T>, point: Point<usize>) -> bool { /// Check if point is at screen boundary. fn is_boundary<T>(term: &Term<T>, point: Point<usize>, 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) } |