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.
This commit is contained in:
parent
6cfcd7c259
commit
ee2c5a6cdd
|
@ -242,7 +242,7 @@ impl<T: EventListener> Execute<T> for Action {
|
|||
Action::ScrollPageUp => {
|
||||
// Move vi mode cursor.
|
||||
let term = ctx.terminal_mut();
|
||||
let scroll_lines = term.grid().screen_lines().0 as isize;
|
||||
let scroll_lines = term.screen_lines().0 as isize;
|
||||
term.vi_mode_cursor = term.vi_mode_cursor.scroll(term, scroll_lines);
|
||||
|
||||
ctx.scroll(Scroll::PageUp);
|
||||
|
@ -250,7 +250,7 @@ impl<T: EventListener> Execute<T> for Action {
|
|||
Action::ScrollPageDown => {
|
||||
// Move vi mode cursor.
|
||||
let term = ctx.terminal_mut();
|
||||
let scroll_lines = -(term.grid().screen_lines().0 as isize);
|
||||
let scroll_lines = -(term.screen_lines().0 as isize);
|
||||
term.vi_mode_cursor = term.vi_mode_cursor.scroll(term, scroll_lines);
|
||||
|
||||
ctx.scroll(Scroll::PageDown);
|
||||
|
@ -258,7 +258,7 @@ impl<T: EventListener> Execute<T> for Action {
|
|||
Action::ScrollHalfPageUp => {
|
||||
// Move vi mode cursor.
|
||||
let term = ctx.terminal_mut();
|
||||
let scroll_lines = term.grid().screen_lines().0 as isize / 2;
|
||||
let scroll_lines = term.screen_lines().0 as isize / 2;
|
||||
term.vi_mode_cursor = term.vi_mode_cursor.scroll(term, scroll_lines);
|
||||
|
||||
ctx.scroll(Scroll::Delta(scroll_lines));
|
||||
|
@ -266,7 +266,7 @@ impl<T: EventListener> Execute<T> for Action {
|
|||
Action::ScrollHalfPageDown => {
|
||||
// Move vi mode cursor.
|
||||
let term = ctx.terminal_mut();
|
||||
let scroll_lines = -(term.grid().screen_lines().0 as isize / 2);
|
||||
let scroll_lines = -(term.screen_lines().0 as isize / 2);
|
||||
term.vi_mode_cursor = term.vi_mode_cursor.scroll(term, scroll_lines);
|
||||
|
||||
ctx.scroll(Scroll::Delta(scroll_lines));
|
||||
|
@ -274,8 +274,8 @@ impl<T: EventListener> Execute<T> for Action {
|
|||
Action::ScrollLineUp => {
|
||||
// Move vi mode cursor.
|
||||
let term = ctx.terminal();
|
||||
if term.grid().display_offset() != term.grid().history_size()
|
||||
&& term.vi_mode_cursor.point.line + 1 != term.grid().screen_lines()
|
||||
if term.grid().display_offset() != term.history_size()
|
||||
&& term.vi_mode_cursor.point.line + 1 != term.screen_lines()
|
||||
{
|
||||
ctx.terminal_mut().vi_mode_cursor.point.line += 1;
|
||||
}
|
||||
|
@ -304,7 +304,7 @@ impl<T: EventListener> Execute<T> for Action {
|
|||
|
||||
// Move vi mode cursor.
|
||||
let term = ctx.terminal_mut();
|
||||
term.vi_mode_cursor.point.line = term.grid().screen_lines() - 1;
|
||||
term.vi_mode_cursor.point.line = term.screen_lines() - 1;
|
||||
|
||||
// Move to beginning twice, to always jump across linewraps.
|
||||
term.vi_motion(ViMotion::FirstOccupied);
|
||||
|
@ -557,7 +557,7 @@ impl<'a, T: EventListener, A: ActionContext<T>> Processor<'a, T, A> {
|
|||
// Load mouse point, treating message bar and padding as the closest cell.
|
||||
let mouse = self.ctx.mouse();
|
||||
let mut point = self.ctx.size_info().pixels_to_coords(mouse.x, mouse.y);
|
||||
point.line = min(point.line, self.ctx.terminal().grid().screen_lines() - 1);
|
||||
point.line = min(point.line, self.ctx.terminal().screen_lines() - 1);
|
||||
|
||||
match button {
|
||||
MouseButton::Left => self.on_left_click(point),
|
||||
|
@ -770,7 +770,7 @@ impl<'a, T: EventListener, A: ActionContext<T>> Processor<'a, T, A> {
|
|||
|
||||
// Reset cursor when message bar height changed or all messages are gone.
|
||||
let size = self.ctx.size_info();
|
||||
let current_lines = (size.lines() - self.ctx.terminal().grid().screen_lines()).0;
|
||||
let current_lines = (size.lines() - self.ctx.terminal().screen_lines()).0;
|
||||
let new_lines = self.ctx.message().map(|m| m.text(&size).len()).unwrap_or(0);
|
||||
|
||||
let new_icon = match current_lines.cmp(&new_lines) {
|
||||
|
@ -978,7 +978,7 @@ impl<'a, T: EventListener, A: ActionContext<T>> Processor<'a, T, A> {
|
|||
|
||||
/// Check if the cursor is hovering above the message bar.
|
||||
fn message_at_cursor(&mut self) -> bool {
|
||||
self.ctx.mouse().line >= self.ctx.terminal().grid().screen_lines()
|
||||
self.ctx.mouse().line >= self.ctx.terminal().screen_lines()
|
||||
}
|
||||
|
||||
/// Whether the point is over the message bar's close button.
|
||||
|
@ -990,7 +990,7 @@ impl<'a, T: EventListener, A: ActionContext<T>> Processor<'a, T, A> {
|
|||
|
||||
mouse.inside_text_area
|
||||
&& mouse.column + message_bar::CLOSE_BUTTON_TEXT.len() >= self.ctx.size_info().cols()
|
||||
&& mouse.line == self.ctx.terminal().grid().screen_lines() + search_height
|
||||
&& mouse.line == self.ctx.terminal().screen_lines() + search_height
|
||||
}
|
||||
|
||||
/// Copy text selection.
|
||||
|
|
|
@ -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)));
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue