diff options
author | Christian Duerr <contact@christianduerr.com> | 2020-05-05 22:50:23 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-05 22:50:23 +0000 |
commit | 81ce93574f62d4b117fdd79af65391f30316a457 (patch) | |
tree | 951a0578860c6028e2dfff0ca83879001c6b2385 /alacritty_terminal/src/grid | |
parent | 04f0bcaf54ed373128ca0f84ee8fcdd8e52bce23 (diff) | |
download | alacritty-81ce93574f62d4b117fdd79af65391f30316a457.tar.gz alacritty-81ce93574f62d4b117fdd79af65391f30316a457.zip |
Extend style guideline documentation
Diffstat (limited to 'alacritty_terminal/src/grid')
-rw-r--r-- | alacritty_terminal/src/grid/mod.rs | 148 | ||||
-rw-r--r-- | alacritty_terminal/src/grid/row.rs | 15 | ||||
-rw-r--r-- | alacritty_terminal/src/grid/storage.rs | 98 | ||||
-rw-r--r-- | alacritty_terminal/src/grid/tests.rs | 26 |
4 files changed, 137 insertions, 150 deletions
diff --git a/alacritty_terminal/src/grid/mod.rs b/alacritty_terminal/src/grid/mod.rs index 97353647..71545dca 100644 --- a/alacritty_terminal/src/grid/mod.rs +++ b/alacritty_terminal/src/grid/mod.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! A specialized 2d grid implementation optimized for use in a terminal. +//! A specialized 2D grid implementation optimized for use in a terminal. use std::cmp::{max, min, Ordering}; use std::ops::{Deref, Index, IndexMut, Range, RangeFrom, RangeFull, RangeTo}; @@ -32,7 +32,7 @@ mod tests; mod storage; use self::storage::Storage; -/// Bidirection iterator +/// Bidirectional iterator. pub trait BidirectionalIterator: Iterator { fn prev(&mut self) -> Option<Self::Item>; } @@ -55,7 +55,7 @@ impl<T> Deref for Indexed<T> { impl<T: PartialEq> ::std::cmp::PartialEq for Grid<T> { fn eq(&self, other: &Self) -> bool { - // Compare struct fields and check result of grid comparison + // Compare struct fields and check result of grid comparison. self.raw.eq(&other.raw) && self.cols.eq(&other.cols) && self.lines.eq(&other.lines) @@ -72,11 +72,11 @@ pub trait GridCell { /// Fast equality approximation. /// /// This is a faster alternative to [`PartialEq`], - /// but might report inequal cells as equal. + /// but might report unequal cells as equal. fn fast_eq(&self, other: Self) -> bool; } -/// Represents the terminal display contents +/// Represents the terminal display contents. /// /// ```notrust /// ┌─────────────────────────┐ <-- max_scroll_limit + lines @@ -152,7 +152,7 @@ impl<T: GridCell + PartialEq + Copy> Grid<T> { } else if point.line >= self.display_offset + self.lines.0 { Point::new(Line(0), Column(0)) } else { - // Since edgecases are handled, conversion is identical as visible to buffer + // Since edge-cases are handled, conversion is identical as visible to buffer. self.visible_to_buffer(point.into()).into() } } @@ -162,7 +162,7 @@ impl<T: GridCell + PartialEq + Copy> Grid<T> { Point { line: self.lines.0 + self.display_offset - point.line.0 - 1, col: point.col } } - /// Update the size of the scrollback history + /// Update the size of the scrollback history. pub fn update_history(&mut self, history_size: usize) { let current_history_size = self.history_size(); if current_history_size > history_size { @@ -199,7 +199,7 @@ impl<T: GridCell + PartialEq + Copy> Grid<T> { cursor_pos: &mut Point, template: &T, ) { - // Check that there's actually work to do and return early if not + // Check that there's actually work to do and return early if not. if lines == self.lines && cols == self.cols { return; } @@ -231,7 +231,7 @@ impl<T: GridCell + PartialEq + Copy> Grid<T> { } } - /// Add lines to the visible area + /// Add lines to the visible area. /// /// Alacritty keeps the cursor at the bottom of the terminal as long as there /// is scrollback available. Once scrollback is exhausted, new lines are @@ -239,18 +239,18 @@ impl<T: GridCell + PartialEq + Copy> Grid<T> { fn grow_lines(&mut self, new_line_count: Line, cursor_pos: &mut Point, template: &T) { let lines_added = new_line_count - self.lines; - // Need to "resize" before updating buffer + // Need to "resize" before updating buffer. self.raw.grow_visible_lines(new_line_count, Row::new(self.cols, template)); self.lines = new_line_count; let history_size = self.history_size(); let from_history = min(history_size, lines_added.0); - // Move cursor down for all lines pulled from history + // Move cursor down for all lines pulled from history. cursor_pos.line += from_history; if from_history != lines_added.0 { - // Move existing lines up for every line that couldn't be pulled from history + // Move existing lines up for every line that couldn't be pulled from history. self.scroll_up(&(Line(0)..new_line_count), lines_added - from_history, template); } @@ -258,9 +258,9 @@ impl<T: GridCell + PartialEq + Copy> Grid<T> { self.display_offset = self.display_offset.saturating_sub(*lines_added); } - // Grow number of columns in each row, reflowing if necessary + /// Grow number of columns in each row, reflowing if necessary. fn grow_cols(&mut self, reflow: bool, cols: Column, cursor_pos: &mut Point, template: &T) { - // Check if a row needs to be wrapped + // Check if a row needs to be wrapped. let should_reflow = |row: &Row<T>| -> bool { let len = Column(row.len()); reflow && len < cols && row[len - 1].flags().contains(Flags::WRAPLINE) @@ -269,7 +269,7 @@ impl<T: GridCell + PartialEq + Copy> Grid<T> { let mut new_empty_lines = 0; let mut reversed: Vec<Row<T>> = Vec::with_capacity(self.raw.len()); for (i, mut row) in self.raw.drain().enumerate().rev() { - // Check if reflowing shoud be performed + // Check if reflowing should be performed. let last_row = match reversed.last_mut() { Some(last_row) if should_reflow(last_row) => last_row, _ => { @@ -278,12 +278,12 @@ impl<T: GridCell + PartialEq + Copy> Grid<T> { }, }; - // Remove wrap flag before appending additional cells + // Remove wrap flag before appending additional cells. if let Some(cell) = last_row.last_mut() { cell.flags_mut().remove(Flags::WRAPLINE); } - // Remove leading spacers when reflowing wide char to the previous line + // Remove leading spacers when reflowing wide char to the previous line. let last_len = last_row.len(); if last_len >= 2 && !last_row[Column(last_len - 2)].flags().contains(Flags::WIDE_CHAR) @@ -292,10 +292,10 @@ impl<T: GridCell + PartialEq + Copy> Grid<T> { last_row.shrink(Column(last_len - 1)); } - // Append as many cells from the next line as possible + // Append as many cells from the next line as possible. let len = min(row.len(), cols.0 - last_row.len()); - // Insert leading spacer when there's not enough room for reflowing wide char + // Insert leading spacer when there's not enough room for reflowing wide char. let mut cells = if row[Column(len - 1)].flags().contains(Flags::WIDE_CHAR) { let mut cells = row.front_split_off(len - 1); @@ -312,28 +312,28 @@ impl<T: GridCell + PartialEq + Copy> Grid<T> { if row.is_empty() { if i + reversed.len() < self.lines.0 { - // Add new line and move lines up if we can't pull from history + // Add new line and move lines up if we can't pull from history. cursor_pos.line = Line(cursor_pos.line.saturating_sub(1)); new_empty_lines += 1; } else if i < self.display_offset { - // Keep viewport in place if line is outside of the visible area + // Keep viewport in place if line is outside of the visible area. self.display_offset = self.display_offset.saturating_sub(1); } - // Don't push line into the new buffer + // Don't push line into the new buffer. continue; } else if let Some(cell) = last_row.last_mut() { - // Set wrap flag if next line still has cells + // Set wrap flag if next line still has cells. cell.flags_mut().insert(Flags::WRAPLINE); } reversed.push(row); } - // Add padding lines + // Add padding lines. reversed.append(&mut vec![Row::new(cols, template); new_empty_lines]); - // Fill remaining cells and reverse iterator + // Fill remaining cells and reverse iterator. let mut new_raw = Vec::with_capacity(reversed.len()); for mut row in reversed.drain(..).rev() { if row.len() < cols.0 { @@ -348,18 +348,18 @@ impl<T: GridCell + PartialEq + Copy> Grid<T> { self.cols = cols; } - // Shrink number of columns in each row, reflowing if necessary + /// Shrink number of columns in each row, reflowing if necessary. fn shrink_cols(&mut self, reflow: bool, cols: Column, template: &T) { let mut new_raw = Vec::with_capacity(self.raw.len()); let mut buffered = None; for (i, mut row) in self.raw.drain().enumerate().rev() { - // Append lines left over from previous row + // Append lines left over from previous row. if let Some(buffered) = buffered.take() { row.append_front(buffered); } loop { - // Check if reflowing shoud be performed + // Check if reflowing should be performed. let mut wrapped = match row.shrink(cols) { Some(wrapped) if reflow => wrapped, _ => { @@ -368,7 +368,7 @@ impl<T: GridCell + PartialEq + Copy> Grid<T> { }, }; - // Insert spacer if a wide char would be wrapped into the last column + // Insert spacer if a wide char would be wrapped into the last column. if row.len() >= cols.0 && row[cols - 1].flags().contains(Flags::WIDE_CHAR) { wrapped.insert(0, row[cols - 1]); @@ -377,7 +377,7 @@ impl<T: GridCell + PartialEq + Copy> Grid<T> { row[cols - 1] = spacer; } - // Remove wide char spacer before shrinking + // Remove wide char spacer before shrinking. let len = wrapped.len(); if (len == 1 || (len >= 2 && !wrapped[len - 2].flags().contains(Flags::WIDE_CHAR))) && wrapped[len - 1].flags().contains(Flags::WIDE_CHAR_SPACER) @@ -394,7 +394,7 @@ impl<T: GridCell + PartialEq + Copy> Grid<T> { new_raw.push(row); - // Set line as wrapped if cells got removed + // Set line as wrapped if cells got removed. if let Some(cell) = new_raw.last_mut().and_then(|r| r.last_mut()) { cell.flags_mut().insert(Flags::WRAPLINE); } @@ -405,21 +405,21 @@ impl<T: GridCell + PartialEq + Copy> Grid<T> { .unwrap_or(false) && wrapped.len() < cols.0 { - // Make sure previous wrap flag doesn't linger around + // Make sure previous wrap flag doesn't linger around. if let Some(cell) = wrapped.last_mut() { cell.flags_mut().remove(Flags::WRAPLINE); } - // Add removed cells to start of next row + // Add removed cells to start of next row. buffered = Some(wrapped); break; } else { - // Make sure viewport doesn't move if line is outside of the visible area + // Make sure viewport doesn't move if line is outside of the visible area. if i < self.display_offset { self.display_offset = min(self.display_offset + 1, self.max_scroll_limit); } - // Make sure new row is at least as long as new width + // Make sure new row is at least as long as new width. let occ = wrapped.len(); if occ < cols.0 { wrapped.append(&mut vec![*template; cols.0 - occ]); @@ -435,7 +435,7 @@ impl<T: GridCell + PartialEq + Copy> Grid<T> { self.cols = cols; } - /// Remove lines from the visible area + /// Remove lines from the visible area. /// /// The behavior in Terminal.app and iTerm.app is to keep the cursor at the /// bottom of the screen. This is achieved by pushing history "out the top" @@ -443,7 +443,7 @@ impl<T: GridCell + PartialEq + Copy> Grid<T> { /// /// Alacritty takes the same approach. fn shrink_lines(&mut self, target: Line, cursor_pos: &mut Point, template: &T) { - // Scroll up to keep cursor inside the window + // Scroll up to keep cursor inside the window. let required_scrolling = (cursor_pos.line + 1).saturating_sub(target.0); if required_scrolling > 0 { self.scroll_up(&(Line(0)..self.lines), Line(required_scrolling), template); @@ -476,24 +476,24 @@ impl<T: GridCell + PartialEq + Copy> Grid<T> { self.decrease_scroll_limit(*positions); - // Now, restore any scroll region lines + // Now, restore any scroll region lines. let lines = self.lines; for i in IndexRange(region.end..lines) { self.raw.swap_lines(i, i + positions); } - // Finally, reset recycled lines + // Finally, reset recycled lines. for i in IndexRange(Line(0)..positions) { self.raw[i].reset(&template); } } else { - // Rotate selection to track content + // Rotate selection to track content. self.selection = self .selection .take() .and_then(|s| s.rotate(num_lines, num_cols, region, -(*positions as isize))); - // Subregion rotation + // Subregion rotation. for line in IndexRange((region.start + positions)..region.end).rev() { self.raw.swap_lines(line, line - positions); } @@ -504,7 +504,7 @@ impl<T: GridCell + PartialEq + Copy> Grid<T> { } } - /// scroll_up moves lines at the bottom towards the top + /// Move lines at the bottom towards the top. /// /// This is the performance-sensitive part of scrolling. pub fn scroll_up(&mut self, region: &Range<Line>, positions: Line, template: &T) { @@ -512,7 +512,7 @@ impl<T: GridCell + PartialEq + Copy> Grid<T> { let num_cols = self.num_cols().0; if region.start == Line(0) { - // Update display offset when not pinned to active area + // Update display offset when not pinned to active area. if self.display_offset != 0 { self.display_offset = min(self.display_offset + *positions, self.max_scroll_limit); } @@ -537,25 +537,25 @@ impl<T: GridCell + PartialEq + Copy> Grid<T> { self.raw.swap(i, i + *positions); } - // Finally, reset recycled lines + // Finally, reset recycled lines. // // Recycled lines are just above the end of the scrolling region. for i in 0..*positions { self.raw[i + fixed_lines].reset(&template); } } else { - // Rotate selection to track content + // Rotate selection to track content. self.selection = self .selection .take() .and_then(|s| s.rotate(num_lines, num_cols, region, *positions as isize)); - // Subregion rotation + // Subregion rotation. for line in IndexRange(region.start..(region.end - positions)) { self.raw.swap_lines(line, line + positions); } - // Clear reused lines + // Clear reused lines. for line in IndexRange((region.end - positions)..region.end) { self.raw[line].reset(&template); } @@ -575,23 +575,23 @@ impl<T: GridCell + PartialEq + Copy> Grid<T> { let positions = self.lines - iter.cur.line; let region = Line(0)..self.num_lines(); - // Reset display offset + // Reset display offset. self.display_offset = 0; - // Clear the viewport + // Clear the viewport. self.scroll_up(®ion, positions, template); - // Reset rotated lines + // Reset rotated lines. for i in positions.0..self.lines.0 { self.raw[i].reset(&template); } } - // Completely reset the grid state + /// Completely reset the grid state. pub fn reset(&mut self, template: &T) { self.clear_history(); - // Reset all visible lines + // Reset all visible lines. for row in 0..self.raw.len() { self.raw[row].reset(template); } @@ -620,11 +620,11 @@ impl<T> Grid<T> { #[inline] pub fn clear_history(&mut self) { - // Explicitly purge all lines from history + // Explicitly purge all lines from history. self.raw.shrink_lines(self.history_size()); } - /// Total number of lines in the buffer, this includes scrollback + visible lines + /// Total number of lines in the buffer, this includes scrollback + visible lines. #[inline] pub fn len(&self) -> usize { self.raw.len() @@ -635,20 +635,20 @@ impl<T> Grid<T> { self.raw.len() - *self.lines } - /// This is used only for initializing after loading ref-tests + /// This is used only for initializing after loading ref-tests. #[inline] pub fn initialize_all(&mut self, template: &T) where T: Copy + GridCell, { - // Remove all cached lines to clear them of any content + // Remove all cached lines to clear them of any content. self.truncate(); - // Initialize everything with empty new lines + // Initialize everything with empty new lines. self.raw.initialize(self.max_scroll_limit - self.history_size(), template, self.cols); } - /// This is used only for truncating before saving ref-tests + /// This is used only for truncating before saving ref-tests. #[inline] pub fn truncate(&mut self) { self.raw.truncate(); @@ -666,7 +666,7 @@ impl<T> Grid<T> { } pub struct GridIterator<'a, T> { - /// Immutable grid reference + /// Immutable grid reference. grid: &'a Grid<T>, /// Current position of the iterator within the grid. @@ -722,7 +722,7 @@ impl<'a, T> BidirectionalIterator for GridIterator<'a, T> { } } -/// Index active region by line +/// Index active region by line. impl<T> Index<Line> for Grid<T> { type Output = Row<T>; @@ -732,7 +732,7 @@ impl<T> Index<Line> for Grid<T> { } } -/// Index with buffer offset +/// Index with buffer offset. impl<T> Index<usize> for Grid<T> { type Output = Row<T>; @@ -772,22 +772,18 @@ impl<'point, T> IndexMut<&'point Point> for Grid<T> { } } -// ------------------------------------------------------------------------------------------------- -// REGIONS -// ------------------------------------------------------------------------------------------------- - -/// A subset of lines in the grid +/// A subset of lines in the grid. /// -/// May be constructed using Grid::region(..) +/// May be constructed using Grid::region(..). pub struct Region<'a, T> { start: Line, end: Line, raw: &'a Storage<T>, } -/// A mutable subset of lines in the grid +/// A mutable subset of lines in the grid. /// -/// May be constructed using Grid::region_mut(..) +/// May be constructed using Grid::region_mut(..). pub struct RegionMut<'a, T> { start: Line, end: Line, @@ -795,7 +791,7 @@ pub struct RegionMut<'a, T> { } impl<'a, T> RegionMut<'a, T> { - /// Call the provided function for every item in this region + /// Call the provided function for every item in this region. pub fn each<F: Fn(&mut T)>(self, func: F) { for row in self { for item in row { @@ -806,10 +802,10 @@ impl<'a, T> RegionMut<'a, T> { } pub trait IndexRegion<I, T> { - /// Get an immutable region of Self + /// Get an immutable region of Self. fn region(&self, _: I) -> Region<'_, T>; - /// Get a mutable region of Self + /// Get a mutable region of Self. fn region_mut(&mut self, _: I) -> RegionMut<'_, T>; } @@ -921,11 +917,7 @@ impl<'a, T> Iterator for RegionIterMut<'a, T> { } } -// ------------------------------------------------------------------------------------------------- -// DISPLAY ITERATOR -// ------------------------------------------------------------------------------------------------- - -/// Iterates over the visible area accounting for buffer transform +/// Iterates over the visible area accounting for buffer transform. pub struct DisplayIter<'a, T> { grid: &'a Grid<T>, offset: usize, @@ -974,7 +966,7 @@ impl<'a, T: Copy + 'a> Iterator for DisplayIter<'a, T> { column: self.col, }); - // Update line/col to point to next item + // Update line/col to point to next item. self.col += 1; if self.col == self.grid.num_cols() && self.offset != self.limit { self.offset -= 1; diff --git a/alacritty_terminal/src/grid/row.rs b/alacritty_terminal/src/grid/row.rs index 0bfa88d4..22a10625 100644 --- a/alacritty_terminal/src/grid/row.rs +++ b/alacritty_terminal/src/grid/row.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! Defines the Row type which makes up lines in the grid +//! Defines the Row type which makes up lines in the grid. use std::cmp::{max, min}; use std::ops::{Index, IndexMut}; @@ -24,7 +24,7 @@ use serde::{Deserialize, Serialize}; use crate::grid::GridCell; use crate::index::Column; -/// A row in the grid +/// A row in the grid. #[derive(Default, Clone, Debug, Serialize, Deserialize)] pub struct Row<T> { inner: Vec<T>, @@ -67,7 +67,7 @@ impl<T: Copy> Row<T> { return None; } - // Split off cells for a new row + // Split off cells for a new row. let mut new_row = self.inner.split_off(cols.0); let index = new_row.iter().rposition(|c| !c.is_empty()).map(|i| i + 1).unwrap_or(0); new_row.truncate(index); @@ -91,14 +91,13 @@ impl<T: Copy> Row<T> { let template = *template; - // Mark all cells as dirty if template cell changed + // Mark all cells as dirty if template cell changed. let len = self.inner.len(); if !self.inner[len - 1].fast_eq(template) { self.occ = len; } - // Reset every dirty in the row - // let template = *template; + // Reset every dirty in the row. for item in &mut self.inner[..self.occ] { *item = template; } @@ -193,10 +192,6 @@ impl<T> IndexMut<Column> for Row<T> { } } -// ----------------------------------------------------------------------------- -// Index ranges of columns -// ----------------------------------------------------------------------------- - impl<T> Index<Range<Column>> for Row<T> { type Output = [T]; diff --git a/alacritty_terminal/src/grid/storage.rs b/alacritty_terminal/src/grid/storage.rs index 8a5c93cb..4820036f 100644 --- a/alacritty_terminal/src/grid/storage.rs +++ b/alacritty_terminal/src/grid/storage.rs @@ -52,7 +52,7 @@ pub struct Storage<T> { impl<T: PartialEq> PartialEq for Storage<T> { fn eq(&self, other: &Self) -> bool { - // Both storage buffers need to be truncated and zeroed + // Both storage buffers need to be truncated and zeroed. assert_eq!(self.zero, 0); assert_eq!(other.zero, 0); @@ -66,7 +66,7 @@ impl<T> Storage<T> { where T: Clone, { - // Initialize visible lines, the scrollback buffer is initialized dynamically + // Initialize visible lines, the scrollback buffer is initialized dynamically. let inner = vec![template; visible_lines.0]; Storage { inner, zero: 0, visible_lines, len: visible_lines.0 } @@ -77,11 +77,11 @@ impl<T> Storage<T> { where T: Clone, { - // Number of lines the buffer needs to grow + // Number of lines the buffer needs to grow. let growage = next - self.visible_lines; self.grow_lines(growage.0, template_row); - // Update visible lines + // Update visible lines. self.visible_lines = next; } @@ -90,43 +90,43 @@ impl<T> Storage<T> { where T: Clone, { - // Only grow if there are not enough lines still hidden + // Only grow if there are not enough lines still hidden. let mut new_growage = 0; if growage > (self.inner.len() - self.len) { - // Lines to grow additionally to invisible lines + // Lines to grow additionally to invisible lines. new_growage = growage - (self.inner.len() - self.len); - // Split off the beginning of the raw inner buffer + // Split off the beginning of the raw inner buffer. let mut start_buffer = self.inner.split_off(self.zero); - // Insert new template rows at the end of the raw inner buffer + // Insert new template rows at the end of the raw inner buffer. let mut new_lines = vec![template_row; new_growage]; self.inner.append(&mut new_lines); - // Add the start to the raw inner buffer again + // Add the start to the raw inner buffer again. self.inner.append(&mut start_buffer); } - // Update raw buffer length and zero offset + // Update raw buffer length and zero offset. self.zero += new_growage; self.len += growage; } /// Decrease the number of lines in the buffer. pub fn shrink_visible_lines(&mut self, next: Line) { - // Shrink the size without removing any lines + // Shrink the size without removing any lines. let shrinkage = self.visible_lines - next; self.shrink_lines(shrinkage.0); - // Update visible lines + // Update visible lines. self.visible_lines = next; } - // Shrink the number of lines in the buffer + /// Shrink the number of lines in the buffer. pub fn shrink_lines(&mut self, shrinkage: usize) { self.len -= shrinkage; - // Free memory + // Free memory. if self.inner.len() > self.len + MAX_CACHE_SIZE { self.truncate(); } @@ -209,7 +209,7 @@ impl<T> Storage<T> { let a_ptr = self.inner.as_mut_ptr().add(a) as *mut usize; let b_ptr = self.inner.as_mut_ptr().add(b) as *mut usize; - // Copy 1 qword at a time + // Copy 1 qword at a time. // // The optimizer unrolls this loop and vectorizes it. let mut tmp: usize; @@ -360,7 +360,7 @@ mod tests { assert_eq!(storage.zero, 2); } - /// Grow the buffer one line at the end of the buffer + /// Grow the buffer one line at the end of the buffer. /// /// Before: /// 0: 0 <- Zero @@ -406,7 +406,7 @@ mod tests { assert_eq!(storage.len, expected.len); } - /// Grow the buffer one line at the start of the buffer + /// Grow the buffer one line at the start of the buffer. /// /// Before: /// 0: - @@ -419,7 +419,7 @@ mod tests { /// 3: 1 #[test] fn grow_before_zero() { - // Setup storage area + // Setup storage area. let mut storage = Storage { inner: vec![ Row::new(Column(1), &'-'), @@ -431,10 +431,10 @@ mod tests { len: 3, }; - // Grow buffer + // Grow buffer. storage.grow_visible_lines(Line(4), Row::new(Column(1), &'-')); - // Make sure the result is correct + // Make sure the result is correct. let expected = Storage { inner: vec![ Row::new(Column(1), &'-'), @@ -452,7 +452,7 @@ mod tests { assert_eq!(storage.len, expected.len); } - /// Shrink the buffer one line at the start of the buffer + /// Shrink the buffer one line at the start of the buffer. /// /// Before: /// 0: 2 @@ -464,7 +464,7 @@ mod tests { /// 1: 1 #[test] fn shrink_before_zero() { - // Setup storage area + // Setup storage area. let mut storage = Storage { inner: vec![ Row::new(Column(1), &'2'), @@ -476,10 +476,10 @@ mod tests { len: 3, }; - // Shrink buffer + // Shrink buffer. storage.shrink_visible_lines(Line(2)); - // Make sure the result is correct + // Make sure the result is correct. let expected = Storage { inner: vec![ Row::new(Column(1), &'2'), @@ -496,7 +496,7 @@ mod tests { assert_eq!(storage.len, expected.len); } - /// Shrink the buffer one line at the end of the buffer + /// Shrink the buffer one line at the end of the buffer. /// /// Before: /// 0: 0 <- Zero @@ -508,7 +508,7 @@ mod tests { /// 2: 2 <- Hidden #[test] fn shrink_after_zero() { - // Setup storage area + // Setup storage area. let mut storage = Storage { inner: vec![ Row::new(Column(1), &'0'), @@ -520,10 +520,10 @@ mod tests { len: 3, }; - // Shrink buffer + // Shrink buffer. storage.shrink_visible_lines(Line(2)); - // Make sure the result is correct + // Make sure the result is correct. let expected = Storage { inner: vec![ Row::new(Column(1), &'0'), @@ -540,7 +540,7 @@ mod tests { assert_eq!(storage.len, expected.len); } - /// Shrink the buffer at the start and end of the buffer + /// Shrink the buffer at the start and end of the buffer. /// /// Before: /// 0: 4 @@ -558,7 +558,7 @@ mod tests { /// 5: 3 <- Hidden #[test] fn shrink_before_and_after_zero() { - // Setup storage area + // Setup storage area. let mut storage = Storage { inner: vec![ Row::new(Column(1), &'4'), @@ -573,10 +573,10 @@ mod tests { len: 6, }; - // Shrink buffer + // Shrink buffer. storage.shrink_visible_lines(Line(2)); - // Make sure the result is correct + // Make sure the result is correct. let expected = Storage { inner: vec![ Row::new(Column(1), &'4'), @@ -596,7 +596,7 @@ mod tests { assert_eq!(storage.len, expected.len); } - /// Check that when truncating all hidden lines are removed from the raw buffer + /// Check that when truncating all hidden lines are removed from the raw buffer. /// /// Before: /// 0: 4 <- Hidden @@ -610,7 +610,7 @@ mod tests { /// 1: 1 #[test] fn truncate_invisible_lines() { - // Setup storage area + // Setup storage area. let mut storage = Storage { inner: vec![ Row::new(Column(1), &'4'), @@ -625,10 +625,10 @@ mod tests { len: 2, }; - // Truncate buffer + // Truncate buffer. storage.truncate(); - // Make sure the result is correct + // Make sure the result is correct. let expected = Storage { inner: vec![Row::new(Column(1), &'0'), Row::new(Column(1), &'1')], zero: 0, @@ -641,7 +641,7 @@ mod tests { assert_eq!(storage.len, expected.len); } - /// Truncate buffer only at the beginning + /// Truncate buffer only at the beginning. /// /// Before: /// 0: 1 @@ -652,7 +652,7 @@ mod tests { /// 0: 0 <- Zero #[test] fn truncate_invisible_lines_beginning() { - // Setup storage area + // Setup storage area. let mut storage = Storage { inner: vec![ Row::new(Column(1), &'1'), @@ -664,10 +664,10 @@ mod tests { len: 2, }; - // Truncate buffer + // Truncate buffer. storage.truncate(); - // Make sure the result is correct + // Make sure the result is correct. let expected = Storage { inner: vec![Row::new(Column(1), &'0'), Row::new(Column(1), &'1')], zero: 0, @@ -680,7 +680,7 @@ mod tests { assert_eq!(storage.len, expected.len); } - /// First shrink the buffer and then grow it again + /// First shrink the buffer and then grow it again. /// /// Before: /// 0: 4 @@ -706,7 +706,7 @@ mod tests { /// 6: 3 #[test] fn shrink_then_grow() { - // Setup storage area + // Setup storage area. let mut storage = Storage { inner: vec![ Row::new(Column(1), &'4'), @@ -721,10 +721,10 @@ mod tests { len: 6, }; - // Shrink buffer + // Shrink buffer. storage.shrink_lines(3); - // Make sure the result after shrinking is correct + // Make sure the result after shrinking is correct. let shrinking_expected = Storage { inner: vec![ Row::new(Column(1), &'4'), @@ -742,10 +742,10 @@ mod tests { assert_eq!(storage.zero, shrinking_expected.zero); assert_eq!(storage.len, shrinking_expected.len); - // Grow buffer + // Grow buffer. storage.grow_lines(4, Row::new(Column(1), &'-')); - // Make sure the result after shrinking is correct + // Make sure the result after shrinking is correct. let growing_expected = Storage { inner: vec![ Row::new(Column(1), &'4'), @@ -767,7 +767,7 @@ mod tests { #[test] fn initialize() { - // Setup storage area + // Setup storage area. let mut storage = Storage { inner: vec![ Row::new(Column(1), &'4'), @@ -782,11 +782,11 @@ mod tests { len: 6, }; - // Initialize additional lines + // Initialize additional lines. let init_size = 3; storage.initialize(init_size, &'-', Column(1)); - // Make sure the lines are present and at the right location + // Make sure the lines are present and at the right location. let expected_init_size = std::cmp::max(init_size, MAX_CACHE_SIZE); let mut expected_inner = vec![Row::new(Column(1), &'4'), Row::new(Column(1), &'5')]; diff --git a/alacritty_terminal/src/grid/tests.rs b/alacritty_terminal/src/grid/tests.rs index e8f4fb8d..ef011d16 100644 --- a/alacritty_terminal/src/grid/tests.rs +++ b/alacritty_terminal/src/grid/tests.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! Tests for the Grid +//! Tests for the Grid. use super::{BidirectionalIterator, Grid}; use crate::grid::GridCell; @@ -71,7 +71,7 @@ fn visible_to_buffer() { assert_eq!(point, Point::new(4, Column(3))); } -// Scroll up moves lines upwards +// Scroll up moves lines upwards. #[test] fn scroll_up() { let mut grid = Grid::new(Line(10), Column(1), 0, 0); @@ -97,13 +97,13 @@ fn scroll_up() { assert_eq!(grid[Line(6)].occ, 1); assert_eq!(grid[Line(7)][Column(0)], 9); assert_eq!(grid[Line(7)].occ, 1); - assert_eq!(grid[Line(8)][Column(0)], 0); // was 0 + assert_eq!(grid[Line(8)][Column(0)], 0); // was 0. assert_eq!(grid[Line(8)].occ, 0); - assert_eq!(grid[Line(9)][Column(0)], 0); // was 1 + assert_eq!(grid[Line(9)][Column(0)], 0); // was 1. assert_eq!(grid[Line(9)].occ, 0); } -// Scroll down moves lines downwards +// Scroll down moves lines downwards. #[test] fn scroll_down() { let mut grid = Grid::new(Line(10), Column(1), 0, 0); @@ -113,9 +113,9 @@ fn scroll_down() { grid.scroll_down(&(Line(0)..Line(10)), Line(2), &0); - assert_eq!(grid[Line(0)][Column(0)], 0); // was 8 + assert_eq!(grid[Line(0)][Column(0)], 0); // was 8. assert_eq!(grid[Line(0)].occ, 0); - assert_eq!(grid[Line(1)][Column(0)], 0); // was 9 + assert_eq!(grid[Line(1)][Column(0)], 0); // was 9. assert_eq!(grid[Line(1)].occ, 0); assert_eq!(grid[Line(2)][Column(0)], 0); assert_eq!(grid[Line(2)].occ, 1); @@ -135,7 +135,7 @@ fn scroll_down() { assert_eq!(grid[Line(9)].occ, 1); } -// Test that GridIterator works +// Test that GridIterator works. #[test] fn test_iter() { let mut grid = Grid::new(Line(5), Column(5), 0, 0); @@ -156,7 +156,7 @@ fn test_iter() { assert_eq!(Some(&3), iter.next()); assert_eq!(Some(&4), iter.next()); - // test linewrapping + // Test line-wrapping. assert_eq!(Some(&5), iter.next()); assert_eq!(Column(0), iter.point().col); assert_eq!(3, iter.point().line); @@ -165,10 +165,10 @@ fn test_iter() { assert_eq!(Column(4), iter.point().col); assert_eq!(4, iter.point().line); - // Make sure iter.cell() returns the current iterator position + // Make sure iter.cell() returns the current iterator position. assert_eq!(&4, iter.cell()); - // test that iter ends at end of grid + // Test that iter ends at end of grid. let mut final_iter = grid.iter_from(Point { line: 0, col: Column(4) }); assert_eq!(None, final_iter.next()); assert_eq!(Some(&23), final_iter.prev()); @@ -282,7 +282,7 @@ fn grow_reflow() { assert_eq!(grid[1][Column(1)], cell('2')); assert_eq!(grid[1][Column(2)], cell('3')); - // Make sure rest of grid is empty + // Make sure rest of grid is empty. assert_eq!(grid[0].len(), 3); assert_eq!(grid[0][Column(0)], Cell::default()); assert_eq!(grid[0][Column(1)], Cell::default()); @@ -311,7 +311,7 @@ fn grow_reflow_multiline() { assert_eq!(grid[2][Column(4)], cell('5')); assert_eq!(grid[2][Column(5)], cell('6')); - // Make sure rest of grid is empty + // Make sure rest of grid is empty. // https://github.com/rust-lang/rust-clippy/issues/3788 #[allow(clippy::needless_range_loop)] for r in 0..2 { |