diff options
author | Christian Duerr <chrisduerr@users.noreply.github.com> | 2019-03-13 18:55:18 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-13 18:55:18 +0000 |
commit | b1032bcc6b79135f87f327548e43563da05657fb (patch) | |
tree | 94915b15d11094006dcd3381b8ff0d0d3ed5de9b /src/grid/tests.rs | |
parent | 0b9ae4ce936dfafbf5ea1929a170c97391cdea0b (diff) | |
download | r-alacritty-b1032bcc6b79135f87f327548e43563da05657fb.tar.gz r-alacritty-b1032bcc6b79135f87f327548e43563da05657fb.tar.bz2 r-alacritty-b1032bcc6b79135f87f327548e43563da05657fb.zip |
Add text reflow
Alacritty will now automatically reflow lines and shrink them when they
would usually exceed the new width of the terminal instead of
truncation.
If a line had to be truncated, it will also be reflown into the previous
line after growing the terminal width.
The reflow behavior when not at the bottom of the history is similar to
that of VTE and aims to keep the viewport stationary whenever possible.
Opposed to VTE, reflow will also be performed in the alternate screen
buffer.
There will be bugs when resizing the terminal emulator to a size smaller
than the prompt, though these issues were present in all terminal
emulators with reflow support.
This fixes #591.
Diffstat (limited to 'src/grid/tests.rs')
-rw-r--r-- | src/grid/tests.rs | 174 |
1 files changed, 174 insertions, 0 deletions
diff --git a/src/grid/tests.rs b/src/grid/tests.rs index 560bb0fe..82edda69 100644 --- a/src/grid/tests.rs +++ b/src/grid/tests.rs @@ -16,6 +16,20 @@ use super::{Grid, BidirectionalIterator}; use crate::index::{Point, Line, Column}; +use crate::term::cell::{Cell, Flags}; +use crate::grid::GridCell; + +impl GridCell for usize { + fn is_empty(&self) -> bool { + false + } + + fn is_wrap(&self) -> bool { + false + } + + fn set_wrap(&mut self, _wrap: bool) {} +} // Scroll up moves lines upwards #[test] @@ -123,3 +137,163 @@ fn test_iter() { assert_eq!(None, final_iter.next()); assert_eq!(Some(&23), final_iter.prev()); } + +#[test] +fn shrink_reflow() { + let mut grid = Grid::new(Line(1), Column(5), 2, cell('x')); + grid[Line(0)][Column(0)] = cell('1'); + grid[Line(0)][Column(1)] = cell('2'); + grid[Line(0)][Column(2)] = cell('3'); + grid[Line(0)][Column(3)] = cell('4'); + grid[Line(0)][Column(4)] = cell('5'); + + grid.resize(Line(1), Column(2), &mut Point::new(Line(0), Column(0)), &Cell::default()); + + assert_eq!(grid.len(), 3); + + assert_eq!(grid[2].len(), 2); + assert_eq!(grid[2][Column(0)], cell('1')); + assert_eq!(grid[2][Column(1)], wrap_cell('2')); + + assert_eq!(grid[1].len(), 2); + assert_eq!(grid[1][Column(0)], cell('3')); + assert_eq!(grid[1][Column(1)], wrap_cell('4')); + + assert_eq!(grid[0].len(), 2); + assert_eq!(grid[0][Column(0)], cell('5')); + assert_eq!(grid[0][Column(1)], Cell::default()); +} + +#[test] +fn shrink_reflow_twice() { + let mut grid = Grid::new(Line(1), Column(5), 2, cell('x')); + grid[Line(0)][Column(0)] = cell('1'); + grid[Line(0)][Column(1)] = cell('2'); + grid[Line(0)][Column(2)] = cell('3'); + grid[Line(0)][Column(3)] = cell('4'); + grid[Line(0)][Column(4)] = cell('5'); + + grid.resize(Line(1), Column(4), &mut Point::new(Line(0), Column(0)), &Cell::default()); + grid.resize(Line(1), Column(2), &mut Point::new(Line(0), Column(0)), &Cell::default()); + + assert_eq!(grid.len(), 3); + + assert_eq!(grid[2].len(), 2); + assert_eq!(grid[2][Column(0)], cell('1')); + assert_eq!(grid[2][Column(1)], wrap_cell('2')); + + assert_eq!(grid[1].len(), 2); + assert_eq!(grid[1][Column(0)], cell('3')); + assert_eq!(grid[1][Column(1)], wrap_cell('4')); + + assert_eq!(grid[0].len(), 2); + assert_eq!(grid[0][Column(0)], cell('5')); + assert_eq!(grid[0][Column(1)], Cell::default()); +} + +#[test] +fn shrink_reflow_empty_cell_inside_line() { + let mut grid = Grid::new(Line(1), Column(5), 3, cell('x')); + grid[Line(0)][Column(0)] = cell('1'); + grid[Line(0)][Column(1)] = Cell::default(); + grid[Line(0)][Column(2)] = cell('3'); + grid[Line(0)][Column(3)] = cell('4'); + grid[Line(0)][Column(4)] = Cell::default(); + + grid.resize(Line(1), Column(2), &mut Point::new(Line(0), Column(0)), &Cell::default()); + + assert_eq!(grid.len(), 2); + + assert_eq!(grid[1].len(), 2); + assert_eq!(grid[1][Column(0)], cell('1')); + assert_eq!(grid[1][Column(1)], wrap_cell(' ')); + + assert_eq!(grid[0].len(), 2); + assert_eq!(grid[0][Column(0)], cell('3')); + assert_eq!(grid[0][Column(1)], cell('4')); + + grid.resize(Line(1), Column(1), &mut Point::new(Line(0), Column(0)), &Cell::default()); + + assert_eq!(grid.len(), 4); + + assert_eq!(grid[3].len(), 1); + assert_eq!(grid[3][Column(0)], wrap_cell('1')); + + assert_eq!(grid[2].len(), 1); + assert_eq!(grid[2][Column(0)], wrap_cell(' ')); + + assert_eq!(grid[1].len(), 1); + assert_eq!(grid[1][Column(0)], wrap_cell('3')); + + assert_eq!(grid[0].len(), 1); + assert_eq!(grid[0][Column(0)], cell('4')); +} + +#[test] +fn grow_reflow() { + let mut grid = Grid::new(Line(2), Column(2), 0, cell('x')); + grid[Line(0)][Column(0)] = cell('1'); + grid[Line(0)][Column(1)] = wrap_cell('2'); + grid[Line(1)][Column(0)] = cell('3'); + grid[Line(1)][Column(1)] = Cell::default(); + + grid.resize(Line(2), Column(3), &mut Point::new(Line(0), Column(0)), &Cell::default()); + + assert_eq!(grid.len(), 2); + + assert_eq!(grid[1].len(), 3); + assert_eq!(grid[1][Column(0)], cell('1')); + assert_eq!(grid[1][Column(1)], cell('2')); + assert_eq!(grid[1][Column(2)], cell('3')); + + // 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()); + assert_eq!(grid[0][Column(2)], Cell::default()); +} + +#[test] +fn grow_reflow_multiline() { + let mut grid = Grid::new(Line(3), Column(2), 0, cell('x')); + grid[Line(0)][Column(0)] = cell('1'); + grid[Line(0)][Column(1)] = wrap_cell('2'); + grid[Line(1)][Column(0)] = cell('3'); + grid[Line(1)][Column(1)] = wrap_cell('4'); + grid[Line(2)][Column(0)] = cell('5'); + grid[Line(2)][Column(1)] = cell('6'); + + grid.resize(Line(3), Column(6), &mut Point::new(Line(0), Column(0)), &Cell::default()); + + assert_eq!(grid.len(), 3); + + assert_eq!(grid[2].len(), 6); + assert_eq!(grid[2][Column(0)], cell('1')); + assert_eq!(grid[2][Column(1)], cell('2')); + assert_eq!(grid[2][Column(2)], cell('3')); + assert_eq!(grid[2][Column(3)], cell('4')); + assert_eq!(grid[2][Column(4)], cell('5')); + assert_eq!(grid[2][Column(5)], cell('6')); + + // 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 { + assert_eq!(grid[r].len(), 6); + for c in 0..6 { + assert_eq!(grid[r][Column(c)], Cell::default()); + } + } +} + +fn cell(c: char) -> Cell { + let mut cell = Cell::default(); + cell.c = c; + cell +} + +fn wrap_cell(c: char) -> Cell { + let mut cell = cell(c); + cell.flags.insert(Flags::WRAPLINE); + cell +} |