diff options
author | Christian Duerr <chrisduerr@users.noreply.github.com> | 2019-07-10 21:17:20 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-10 21:17:20 +0000 |
commit | c4d2725e14ca9488b1b086024bf827c66945ae7b (patch) | |
tree | d8fd69f06671b30aa2df5c9bd5a0d161fabcfbc9 /alacritty_terminal/src/grid | |
parent | a99547cc6dc1d752b29de785f969591c1ed74782 (diff) | |
download | alacritty-c4d2725e14ca9488b1b086024bf827c66945ae7b.tar.gz alacritty-c4d2725e14ca9488b1b086024bf827c66945ae7b.zip |
Fix row occ not set during new and reset
Since ref tests were only stored whenever winit requested the window
close, they would not get stored properly when the terminal was closed
through Alacritty using `exit`, Ctrl+D or similar.
This moves the ref test code to the and of the main entry point, which
will always be executed regardless of how the terminal was shutdown.
Fixes #2613.
Diffstat (limited to 'alacritty_terminal/src/grid')
-rw-r--r-- | alacritty_terminal/src/grid/mod.rs | 2 | ||||
-rw-r--r-- | alacritty_terminal/src/grid/row.rs | 27 | ||||
-rw-r--r-- | alacritty_terminal/src/grid/storage.rs | 13 | ||||
-rw-r--r-- | alacritty_terminal/src/grid/tests.rs | 2 |
4 files changed, 34 insertions, 10 deletions
diff --git a/alacritty_terminal/src/grid/mod.rs b/alacritty_terminal/src/grid/mod.rs index 792dd844..1925a6f4 100644 --- a/alacritty_terminal/src/grid/mod.rs +++ b/alacritty_terminal/src/grid/mod.rs @@ -565,7 +565,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 + GridCell, { let history_size = self.raw.len().saturating_sub(*self.lines); self.raw.initialize(self.max_scroll_limit - history_size, Row::new(self.cols, template)); diff --git a/alacritty_terminal/src/grid/row.rs b/alacritty_terminal/src/grid/row.rs index b67f8cd4..f82e7eaa 100644 --- a/alacritty_terminal/src/grid/row.rs +++ b/alacritty_terminal/src/grid/row.rs @@ -45,8 +45,12 @@ 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 } + pub fn new(columns: Column, template: &T) -> Row<T> + where + T: GridCell, + { + let occ = if template.is_empty() { 0 } else { columns.0 }; + Row { inner: vec![*template; columns.0], occ } } pub fn grow(&mut self, cols: Column, template: &T) { @@ -70,7 +74,7 @@ impl<T: Copy> Row<T> { let index = new_row.iter().rposition(|c| !c.is_empty()).map(|i| i + 1).unwrap_or(0); new_row.truncate(index); - self.occ = min(self.occ, *cols); + self.occ = min(self.occ, cols.0); if new_row.is_empty() { None @@ -80,11 +84,17 @@ impl<T: Copy> Row<T> { } /// Resets contents to the contents of `other` - pub fn reset(&mut self, other: &T) { - for item in &mut self.inner[..] { - *item = *other; + pub fn reset(&mut self, template: &T) + where + T: GridCell, + { + for item in &mut self.inner[..self.occ] { + *item = *template; + } + + if template.is_empty() { + self.occ = 0; } - self.occ = 0; } } @@ -116,13 +126,14 @@ impl<T> Row<T> { where T: GridCell, { + self.occ += vec.len(); self.inner.append(vec); - self.occ = self.inner.iter().rposition(|c| !c.is_empty()).map(|i| i + 1).unwrap_or(0); } #[inline] pub fn append_front(&mut self, mut vec: Vec<T>) { self.occ += vec.len(); + vec.append(&mut self.inner); self.inner = vec; } diff --git a/alacritty_terminal/src/grid/storage.rs b/alacritty_terminal/src/grid/storage.rs index 9b8b0b2a..e04d01cd 100644 --- a/alacritty_terminal/src/grid/storage.rs +++ b/alacritty_terminal/src/grid/storage.rs @@ -310,8 +310,21 @@ impl<T> IndexMut<Line> for Storage<T> { mod test { use crate::grid::row::Row; use crate::grid::storage::Storage; + use crate::grid::GridCell; use crate::index::{Column, Line}; + impl GridCell for char { + fn is_empty(&self) -> bool { + *self == ' ' || *self == '\t' + } + + fn is_wrap(&self) -> bool { + false + } + + fn set_wrap(&mut self, _wrap: bool) {} + } + /// Grow the buffer one line at the end of the buffer /// /// Before: diff --git a/alacritty_terminal/src/grid/tests.rs b/alacritty_terminal/src/grid/tests.rs index ce094b96..a352e747 100644 --- a/alacritty_terminal/src/grid/tests.rs +++ b/alacritty_terminal/src/grid/tests.rs @@ -21,7 +21,7 @@ use crate::term::cell::{Cell, Flags}; impl GridCell for usize { fn is_empty(&self) -> bool { - false + *self == 0 } fn is_wrap(&self) -> bool { |