summaryrefslogtreecommitdiff
path: root/src/grid
diff options
context:
space:
mode:
Diffstat (limited to 'src/grid')
-rw-r--r--src/grid/mod.rs159
-rw-r--r--src/grid/row.rs22
-rw-r--r--src/grid/storage.rs110
-rw-r--r--src/grid/tests.rs19
4 files changed, 144 insertions, 166 deletions
diff --git a/src/grid/mod.rs b/src/grid/mod.rs
index a1903535..3a6bacf8 100644
--- a/src/grid/mod.rs
+++ b/src/grid/mod.rs
@@ -14,10 +14,10 @@
//! A specialized 2d grid implementation optimized for use in a terminal.
-use std::cmp::{min, max, Ordering};
-use std::ops::{Deref, Range, Index, IndexMut, RangeTo, RangeFrom, RangeFull, RangeInclusive};
+use std::cmp::{max, min, Ordering};
+use std::ops::{Deref, Index, IndexMut, Range, RangeFrom, RangeFull, RangeInclusive, RangeTo};
-use crate::index::{self, Point, Line, Column, IndexRange};
+use crate::index::{self, Column, IndexRange, Line, Point};
use crate::selection::Selection;
mod row;
@@ -55,13 +55,13 @@ 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
- self.raw.eq(&other.raw) &&
- self.cols.eq(&other.cols) &&
- self.lines.eq(&other.lines) &&
- self.display_offset.eq(&other.display_offset) &&
- self.scroll_limit.eq(&other.scroll_limit) &&
- self.selection.eq(&other.selection) &&
- self.url_highlight.eq(&other.url_highlight)
+ self.raw.eq(&other.raw)
+ && self.cols.eq(&other.cols)
+ && self.lines.eq(&other.lines)
+ && self.display_offset.eq(&other.display_offset)
+ && self.scroll_limit.eq(&other.scroll_limit)
+ && self.selection.eq(&other.selection)
+ && self.url_highlight.eq(&other.url_highlight)
}
}
@@ -142,10 +142,7 @@ impl<T: GridCell + Copy + Clone> Grid<T> {
}
pub fn visible_to_buffer(&self, point: Point) -> Point<usize> {
- Point {
- line: self.visible_line_to_buffer(point.line),
- col: point.col
- }
+ Point { line: self.visible_line_to_buffer(point.line), col: point.col }
}
pub fn buffer_line_to_visible(&self, line: usize) -> ViewportPosition {
@@ -164,8 +161,7 @@ impl<T: GridCell + Copy + Clone> Grid<T> {
}
/// Update the size of the scrollback history
- pub fn update_history(&mut self, history_size: usize, template: &T)
- {
+ pub fn update_history(&mut self, history_size: usize, template: &T) {
self.raw.update_history(history_size, Row::new(self.cols, &template));
self.max_scroll_limit = history_size;
self.scroll_limit = min(self.scroll_limit, history_size);
@@ -177,20 +173,14 @@ impl<T: GridCell + Copy + Clone> Grid<T> {
Scroll::Lines(count) => {
self.display_offset = min(
max((self.display_offset as isize) + count, 0isize) as usize,
- self.scroll_limit
+ self.scroll_limit,
);
},
Scroll::PageUp => {
- self.display_offset = min(
- self.display_offset + self.lines.0,
- self.scroll_limit
- );
+ self.display_offset = min(self.display_offset + self.lines.0, self.scroll_limit);
},
Scroll::PageDown => {
- self.display_offset -= min(
- self.display_offset,
- self.lines.0
- );
+ self.display_offset -= min(self.display_offset, self.lines.0);
},
Scroll::Top => self.display_offset = self.scroll_limit,
Scroll::Bottom => self.display_offset = 0,
@@ -222,8 +212,7 @@ impl<T: GridCell + Copy + Clone> Grid<T> {
}
}
- fn increase_scroll_limit(&mut self, count: usize, template: &T)
- {
+ fn increase_scroll_limit(&mut self, count: usize, template: &T) {
self.scroll_limit = min(self.scroll_limit + count, self.max_scroll_limit);
// Initialize new lines when the history buffer is smaller than the scroll limit
@@ -246,11 +235,7 @@ impl<T: GridCell + Copy + Clone> Grid<T> {
/// Alacritty keeps the cursor at the bottom of the terminal as long as there
/// is scrollback available. Once scrollback is exhausted, new lines are
/// simply added to the bottom of the screen.
- fn grow_lines(
- &mut self,
- new_line_count: index::Line,
- template: &T,
- ) {
+ fn grow_lines(&mut self, new_line_count: index::Line, template: &T) {
let lines_added = new_line_count - self.lines;
// Need to "resize" before updating buffer
@@ -435,7 +420,7 @@ impl<T: GridCell + Copy + Clone> Grid<T> {
// Now, restore any scroll region lines
let lines = self.lines;
- for i in IndexRange(region.end .. lines) {
+ for i in IndexRange(region.end..lines) {
self.raw.swap_lines(i, i + positions);
}
@@ -449,7 +434,7 @@ impl<T: GridCell + Copy + Clone> Grid<T> {
self.raw.swap_lines(line, line - positions);
}
- for line in IndexRange(region.start .. (region.start + positions)) {
+ for line in IndexRange(region.start..(region.start + positions)) {
self.raw[line].reset(&template);
}
}
@@ -458,19 +443,12 @@ impl<T: GridCell + Copy + Clone> Grid<T> {
/// scroll_up moves lines at the bottom towards the top
///
/// This is the performance-sensitive part of scrolling.
- pub fn scroll_up(
- &mut self,
- region: &Range<index::Line>,
- positions: index::Line,
- template: &T
- ) {
+ pub fn scroll_up(&mut self, region: &Range<index::Line>, positions: index::Line, template: &T) {
if region.start == Line(0) {
// Update display offset when not pinned to active area
if self.display_offset != 0 {
- self.display_offset = min(
- self.display_offset + *positions,
- self.len() - self.num_lines().0,
- );
+ self.display_offset =
+ min(self.display_offset + *positions, self.len() - self.num_lines().0);
}
self.increase_scroll_limit(*positions, template);
@@ -506,7 +484,7 @@ impl<T: GridCell + Copy + Clone> Grid<T> {
}
// Clear reused lines
- for line in IndexRange((region.end - positions) .. region.end) {
+ for line in IndexRange((region.end - positions)..region.end) {
self.raw[line].reset(&template);
}
}
@@ -569,7 +547,7 @@ impl<T> Grid<T> {
/// This is used only for initializing after loading ref-tests
pub fn initialize_all(&mut self, template: &T)
where
- T: Copy
+ T: Copy,
{
let history_size = self.raw.len().saturating_sub(*self.lines);
self.raw.initialize(self.max_scroll_limit - history_size, Row::new(self.cols, template));
@@ -581,10 +559,7 @@ impl<T> Grid<T> {
}
pub fn iter_from(&self, point: Point<usize>) -> GridIterator<'_, T> {
- GridIterator {
- grid: self,
- cur: point,
- }
+ GridIterator { grid: self, cur: point }
}
#[inline]
@@ -613,8 +588,7 @@ impl<'a, T> Iterator for GridIterator<'a, T> {
let last_col = self.grid.num_cols() - Column(1);
match self.cur {
Point { line, col } if line == 0 && col == last_col => None,
- Point { col, .. } if
- (col == last_col) => {
+ Point { col, .. } if (col == last_col) => {
self.cur.line -= 1;
self.cur.col = Column(0);
Some(&self.grid[self.cur.line][self.cur.col])
@@ -622,7 +596,7 @@ impl<'a, T> Iterator for GridIterator<'a, T> {
_ => {
self.cur.col += Column(1);
Some(&self.grid[self.cur.line][self.cur.col])
- }
+ },
}
}
}
@@ -641,7 +615,7 @@ impl<'a, T> BidirectionalIterator for GridIterator<'a, T> {
_ => {
self.cur.col -= Column(1);
Some(&self.grid[self.cur.line][self.cur.col])
- }
+ },
}
}
}
@@ -742,77 +716,48 @@ impl<T> IndexRegion<Range<Line>, T> for Grid<T> {
assert!(index.start < self.num_lines());
assert!(index.end <= self.num_lines());
assert!(index.start <= index.end);
- Region {
- start: index.start,
- end: index.end,
- raw: &self.raw
- }
+ Region { start: index.start, end: index.end, raw: &self.raw }
}
+
fn region_mut(&mut self, index: Range<Line>) -> RegionMut<'_, T> {
assert!(index.start < self.num_lines());
assert!(index.end <= self.num_lines());
assert!(index.start <= index.end);
- RegionMut {
- start: index.start,
- end: index.end,
- raw: &mut self.raw
- }
+ RegionMut { start: index.start, end: index.end, raw: &mut self.raw }
}
}
impl<T> IndexRegion<RangeTo<Line>, T> for Grid<T> {
fn region(&self, index: RangeTo<Line>) -> Region<'_, T> {
assert!(index.end <= self.num_lines());
- Region {
- start: Line(0),
- end: index.end,
- raw: &self.raw
- }
+ Region { start: Line(0), end: index.end, raw: &self.raw }
}
+
fn region_mut(&mut self, index: RangeTo<Line>) -> RegionMut<'_, T> {
assert!(index.end <= self.num_lines());
- RegionMut {
- start: Line(0),
- end: index.end,
- raw: &mut self.raw
- }
+ RegionMut { start: Line(0), end: index.end, raw: &mut self.raw }
}
}
impl<T> IndexRegion<RangeFrom<Line>, T> for Grid<T> {
fn region(&self, index: RangeFrom<Line>) -> Region<'_, T> {
assert!(index.start < self.num_lines());
- Region {
- start: index.start,
- end: self.num_lines(),
- raw: &self.raw
- }
+ Region { start: index.start, end: self.num_lines(), raw: &self.raw }
}
+
fn region_mut(&mut self, index: RangeFrom<Line>) -> RegionMut<'_, T> {
assert!(index.start < self.num_lines());
- RegionMut {
- start: index.start,
- end: self.num_lines(),
- raw: &mut self.raw
- }
+ RegionMut { start: index.start, end: self.num_lines(), raw: &mut self.raw }
}
}
impl<T> IndexRegion<RangeFull, T> for Grid<T> {
fn region(&self, _: RangeFull) -> Region<'_, T> {
- Region {
- start: Line(0),
- end: self.num_lines(),
- raw: &self.raw
- }
+ Region { start: Line(0), end: self.num_lines(), raw: &self.raw }
}
fn region_mut(&mut self, _: RangeFull) -> RegionMut<'_, T> {
- RegionMut {
- start: Line(0),
- end: self.num_lines(),
- raw: &mut self.raw
- }
+ RegionMut { start: Line(0), end: self.num_lines(), raw: &mut self.raw }
}
}
@@ -829,33 +774,26 @@ pub struct RegionIterMut<'a, T> {
}
impl<'a, T> IntoIterator for Region<'a, T> {
- type Item = &'a Row<T>;
type IntoIter = RegionIter<'a, T>;
+ type Item = &'a Row<T>;
fn into_iter(self) -> Self::IntoIter {
- RegionIter {
- end: self.end,
- cur: self.start,
- raw: self.raw
- }
+ RegionIter { end: self.end, cur: self.start, raw: self.raw }
}
}
impl<'a, T> IntoIterator for RegionMut<'a, T> {
- type Item = &'a mut Row<T>;
type IntoIter = RegionIterMut<'a, T>;
+ type Item = &'a mut Row<T>;
fn into_iter(self) -> Self::IntoIter {
- RegionIterMut {
- end: self.end,
- cur: self.start,
- raw: self.raw
- }
+ RegionIterMut { end: self.end, cur: self.start, raw: self.raw }
}
}
impl<'a, T> Iterator for RegionIter<'a, T> {
type Item = &'a Row<T>;
+
fn next(&mut self) -> Option<Self::Item> {
if self.cur < self.end {
let index = self.cur;
@@ -869,13 +807,12 @@ impl<'a, T> Iterator for RegionIter<'a, T> {
impl<'a, T> Iterator for RegionIterMut<'a, T> {
type Item = &'a mut Row<T>;
+
fn next(&mut self) -> Option<Self::Item> {
if self.cur < self.end {
let index = self.cur;
self.cur += 1;
- unsafe {
- Some(&mut *(&mut self.raw[index] as *mut _))
- }
+ unsafe { Some(&mut *(&mut self.raw[index] as *mut _)) }
} else {
None
}
@@ -898,7 +835,7 @@ pub struct DisplayIter<'a, T> {
impl<'a, T: 'a> DisplayIter<'a, T> {
pub fn new(grid: &'a Grid<T>) -> DisplayIter<'a, T> {
let offset = grid.display_offset + *grid.num_lines() - 1;
- let limit = grid.display_offset;
+ let limit = grid.display_offset;
let col = Column(0);
let line = Line(0);
@@ -932,7 +869,7 @@ impl<'a, T: Copy + 'a> Iterator for DisplayIter<'a, T> {
let item = Some(Indexed {
inner: self.grid.raw[self.offset][self.col],
line: self.line,
- column: self.col
+ column: self.col,
});
// Update line/col to point to next item
diff --git a/src/grid/row.rs b/src/grid/row.rs
index ef27f040..0a58de97 100644
--- a/src/grid/row.rs
+++ b/src/grid/row.rs
@@ -14,9 +14,9 @@
//! Defines the Row type which makes up lines in the grid
+use std::cmp::{max, min};
use std::ops::{Index, IndexMut};
-use std::ops::{Range, RangeTo, RangeFrom, RangeFull, RangeToInclusive};
-use std::cmp::{min, max};
+use std::ops::{Range, RangeFrom, RangeFull, RangeTo, RangeToInclusive};
use std::slice;
use crate::grid::GridCell;
@@ -46,10 +46,7 @@ impl<T: PartialEq> PartialEq for Row<T> {
impl<T: Copy> Row<T> {
pub fn new(columns: Column, template: &T) -> Row<T> {
- Row {
- inner: vec![*template; *columns],
- occ: 0,
- }
+ Row { inner: vec![*template; *columns], occ: 0 }
}
pub fn grow(&mut self, cols: Column, template: &T) {
@@ -62,7 +59,7 @@ impl<T: Copy> Row<T> {
pub fn shrink(&mut self, cols: Column) -> Option<Vec<T>>
where
- T: GridCell
+ T: GridCell,
{
if self.inner.len() <= cols.0 {
return None;
@@ -96,10 +93,7 @@ impl<T: Copy> Row<T> {
impl<T> Row<T> {
#[inline]
pub fn from_vec(vec: Vec<T>, occ: usize) -> Row<T> {
- Row {
- inner: vec,
- occ,
- }
+ Row { inner: vec, occ }
}
#[inline]
@@ -121,7 +115,7 @@ impl<T> Row<T> {
#[inline]
pub fn append(&mut self, vec: &mut Vec<T>)
where
- T: GridCell
+ T: GridCell,
{
self.inner.append(vec);
self.occ = self.inner.iter().rposition(|c| !c.is_empty()).map(|i| i + 1).unwrap_or(0);
@@ -137,7 +131,7 @@ impl<T> Row<T> {
#[inline]
pub fn is_empty(&self) -> bool
where
- T: GridCell
+ T: GridCell,
{
self.inner.iter().all(|c| c.is_empty())
}
@@ -153,8 +147,8 @@ impl<T> Row<T> {
}
impl<'a, T> IntoIterator for &'a mut Row<T> {
- type Item = &'a mut T;
type IntoIter = slice::IterMut<'a, T>;
+ type Item = &'a mut T;
#[inline]
fn into_iter(self) -> slice::IterMut<'a, T> {
diff --git a/src/grid/storage.rs b/src/grid/storage.rs
index 6a119ead..32260426 100644
--- a/src/grid/storage.rs
+++ b/src/grid/storage.rs
@@ -15,9 +15,9 @@ use std::ops::{Index, IndexMut};
use static_assertions::assert_eq_size;
-use crate::index::{Column, Line};
-use crate::grid::GridCell;
use super::Row;
+use crate::grid::GridCell;
+use crate::index::{Column, Line};
/// Maximum number of invisible lines before buffer is resized
const TRUNCATE_STEP: usize = 100;
@@ -46,11 +46,8 @@ impl<T: PartialEq> ::std::cmp::PartialEq for Storage<T> {
}
// Check which vec has the bigger zero
- let (ref bigger, ref smaller) = if self.zero >= other.zero {
- (self, other)
- } else {
- (other, self)
- };
+ let (ref bigger, ref smaller) =
+ if self.zero >= other.zero { (self, other) } else { (other, self) };
// Calculate the actual zero offset
let len = self.inner.len();
@@ -88,12 +85,7 @@ impl<T> Storage<T> {
// Initialize visible lines, the scrollback buffer is initialized dynamically
let inner = vec![template; lines.0];
- Storage {
- inner,
- zero: 0,
- visible_lines: lines - 1,
- len: lines.0,
- }
+ Storage { inner, zero: 0, visible_lines: lines - 1, len: lines.0 }
}
/// Update the size of the scrollback history
@@ -179,7 +171,8 @@ impl<T> Storage<T> {
/// Dynamically grow the storage buffer at runtime
pub fn initialize(&mut self, num_rows: usize, template_row: Row<T>)
- where T: Clone
+ where
+ T: Clone,
{
let mut new = vec![template_row; num_rows];
@@ -297,7 +290,7 @@ impl<T> Storage<T> {
#[inline]
pub fn shrink_hidden(&mut self, cols: Column)
where
- T: GridCell + Copy
+ T: GridCell + Copy,
{
let start = self.zero + self.len;
let end = self.zero + self.inner.len();
@@ -317,7 +310,7 @@ impl<T> Storage<T> {
#[inline]
pub fn grow_hidden(&mut self, cols: Column, template: &T)
where
- T: Copy + Clone
+ T: Copy + Clone,
{
let start = self.zero + self.len;
let end = self.zero + self.inner.len();
@@ -333,6 +326,7 @@ impl<T> Storage<T> {
impl<T> Index<usize> for Storage<T> {
type Output = Row<T>;
+
#[inline]
fn index(&self, index: usize) -> &Self::Output {
&self.inner[self.compute_index(index)]
@@ -349,6 +343,7 @@ impl<T> IndexMut<usize> for Storage<T> {
impl<T> Index<Line> for Storage<T> {
type Output = Row<T>;
+
#[inline]
fn index(&self, index: Line) -> &Self::Output {
let index = self.visible_lines - index;
@@ -379,7 +374,11 @@ impl<T> IndexMut<Line> for Storage<T> {
fn grow_after_zero() {
// Setup storage area
let mut storage = Storage {
- inner: vec![Row::new(Column(1), &'0'), Row::new(Column(1), &'1'), Row::new(Column(1), &'-')],
+ inner: vec![
+ Row::new(Column(1), &'0'),
+ Row::new(Column(1), &'1'),
+ Row::new(Column(1), &'-'),
+ ],
zero: 0,
visible_lines: Line(2),
len: 3,
@@ -390,7 +389,12 @@ fn grow_after_zero() {
// Make sure the result is correct
let expected = Storage {
- inner: vec![Row::new(Column(1), &'-'), Row::new(Column(1), &'0'), Row::new(Column(1), &'1'), Row::new(Column(1), &'-')],
+ inner: vec![
+ Row::new(Column(1), &'-'),
+ Row::new(Column(1), &'0'),
+ Row::new(Column(1), &'1'),
+ Row::new(Column(1), &'-'),
+ ],
zero: 1,
visible_lines: Line(0),
len: 4,
@@ -415,7 +419,11 @@ fn grow_after_zero() {
fn grow_before_zero() {
// Setup storage area
let mut storage = Storage {
- inner: vec![Row::new(Column(1), &'-'), Row::new(Column(1), &'0'), Row::new(Column(1), &'1')],
+ inner: vec![
+ Row::new(Column(1), &'-'),
+ Row::new(Column(1), &'0'),
+ Row::new(Column(1), &'1'),
+ ],
zero: 1,
visible_lines: Line(2),
len: 3,
@@ -426,7 +434,12 @@ fn grow_before_zero() {
// Make sure the result is correct
let expected = Storage {
- inner: vec![Row::new(Column(1), &'-'), Row::new(Column(1), &'-'), Row::new(Column(1), &'0'), Row::new(Column(1), &'1')],
+ inner: vec![
+ Row::new(Column(1), &'-'),
+ Row::new(Column(1), &'-'),
+ Row::new(Column(1), &'0'),
+ Row::new(Column(1), &'1'),
+ ],
zero: 2,
visible_lines: Line(0),
len: 4,
@@ -450,7 +463,11 @@ fn grow_before_zero() {
fn shrink_before_zero() {
// Setup storage area
let mut storage = Storage {
- inner: vec![Row::new(Column(1), &'2'), Row::new(Column(1), &'0'), Row::new(Column(1), &'1')],
+ inner: vec![
+ Row::new(Column(1), &'2'),
+ Row::new(Column(1), &'0'),
+ Row::new(Column(1), &'1'),
+ ],
zero: 1,
visible_lines: Line(2),
len: 3,
@@ -461,7 +478,11 @@ fn shrink_before_zero() {
// Make sure the result is correct
let expected = Storage {
- inner: vec![Row::new(Column(1), &'2'), Row::new(Column(1), &'0'), Row::new(Column(1), &'1')],
+ inner: vec![
+ Row::new(Column(1), &'2'),
+ Row::new(Column(1), &'0'),
+ Row::new(Column(1), &'1'),
+ ],
zero: 1,
visible_lines: Line(0),
len: 2,
@@ -485,7 +506,11 @@ fn shrink_before_zero() {
fn shrink_after_zero() {
// Setup storage area
let mut storage = Storage {
- inner: vec![Row::new(Column(1), &'0'), Row::new(Column(1), &'1'), Row::new(Column(1), &'2')],
+ inner: vec![
+ Row::new(Column(1), &'0'),
+ Row::new(Column(1), &'1'),
+ Row::new(Column(1), &'2'),
+ ],
zero: 0,
visible_lines: Line(2),
len: 3,
@@ -496,7 +521,11 @@ fn shrink_after_zero() {
// Make sure the result is correct
let expected = Storage {
- inner: vec![Row::new(Column(1), &'0'), Row::new(Column(1), &'1'), Row::new(Column(1), &'2')],
+ inner: vec![
+ Row::new(Column(1), &'0'),
+ Row::new(Column(1), &'1'),
+ Row::new(Column(1), &'2'),
+ ],
zero: 0,
visible_lines: Line(0),
len: 2,
@@ -526,7 +555,14 @@ fn shrink_after_zero() {
fn shrink_before_and_after_zero() {
// Setup storage area
let mut storage = Storage {
- inner: vec![Row::new(Column(1), &'4'), Row::new(Column(1), &'5'), Row::new(Column(1), &'0'), Row::new(Column(1), &'1'), Row::new(Column(1), &'2'), Row::new(Column(1), &'3')],
+ inner: vec![
+ Row::new(Column(1), &'4'),
+ Row::new(Column(1), &'5'),
+ Row::new(Column(1), &'0'),
+ Row::new(Column(1), &'1'),
+ Row::new(Column(1), &'2'),
+ Row::new(Column(1), &'3'),
+ ],
zero: 2,
visible_lines: Line(5),
len: 6,
@@ -537,7 +573,14 @@ fn shrink_before_and_after_zero() {
// Make sure the result is correct
let expected = Storage {
- inner: vec![Row::new(Column(1), &'4'), Row::new(Column(1), &'5'), Row::new(Column(1), &'0'), Row::new(Column(1), &'1'), Row::new(Column(1), &'2'), Row::new(Column(1), &'3')],
+ inner: vec![
+ Row::new(Column(1), &'4'),
+ Row::new(Column(1), &'5'),
+ Row::new(Column(1), &'0'),
+ Row::new(Column(1), &'1'),
+ Row::new(Column(1), &'2'),
+ Row::new(Column(1), &'3'),
+ ],
zero: 2,
visible_lines: Line(0),
len: 2,
@@ -563,7 +606,14 @@ fn shrink_before_and_after_zero() {
fn truncate_invisible_lines() {
// Setup storage area
let mut storage = Storage {
- inner: vec![Row::new(Column(1), &'4'), Row::new(Column(1), &'5'), Row::new(Column(1), &'0'), Row::new(Column(1), &'1'), Row::new(Column(1), &'2'), Row::new(Column(1), &'3')],
+ inner: vec![
+ Row::new(Column(1), &'4'),
+ Row::new(Column(1), &'5'),
+ Row::new(Column(1), &'0'),
+ Row::new(Column(1), &'1'),
+ Row::new(Column(1), &'2'),
+ Row::new(Column(1), &'3'),
+ ],
zero: 2,
visible_lines: Line(1),
len: 2,
@@ -598,7 +648,11 @@ fn truncate_invisible_lines() {
fn truncate_invisible_lines_beginning() {
// Setup storage area
let mut storage = Storage {
- inner: vec![Row::new(Column(1), &'1'), Row::new(Column(1), &'2'), Row::new(Column(1), &'0')],
+ inner: vec![
+ Row::new(Column(1), &'1'),
+ Row::new(Column(1), &'2'),
+ Row::new(Column(1), &'0'),
+ ],
zero: 2,
visible_lines: Line(1),
len: 2,
diff --git a/src/grid/tests.rs b/src/grid/tests.rs
index 82edda69..fc41fdc6 100644
--- a/src/grid/tests.rs
+++ b/src/grid/tests.rs
@@ -14,10 +14,10 @@
//! Tests for the Gird
-use super::{Grid, BidirectionalIterator};
-use crate::index::{Point, Line, Column};
-use crate::term::cell::{Cell, Flags};
+use super::{BidirectionalIterator, Grid};
use crate::grid::GridCell;
+use crate::index::{Column, Line, Point};
+use crate::term::cell::{Cell, Flags};
impl GridCell for usize {
fn is_empty(&self) -> bool {
@@ -101,14 +101,11 @@ fn test_iter() {
let mut grid = Grid::new(Line(5), Column(5), 0, 0);
for i in 0..5 {
for j in 0..5 {
- grid[Line(i)][Column(j)] = i*5 + j;
+ grid[Line(i)][Column(j)] = i * 5 + j;
}
}
- let mut iter = grid.iter_from(Point {
- line: 4,
- col: Column(0),
- });
+ let mut iter = grid.iter_from(Point { line: 4, col: Column(0) });
assert_eq!(None, iter.prev());
assert_eq!(Some(&1), iter.next());
@@ -128,12 +125,8 @@ fn test_iter() {
assert_eq!(Column(4), iter.cur.col);
assert_eq!(4, iter.cur.line);
-
// test that iter ends at end of grid
- let mut final_iter = grid.iter_from(Point {
- line: 0,
- col: Column(4),
- });
+ 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());
}