summaryrefslogtreecommitdiff
path: root/alacritty_terminal/src/grid/row.rs
diff options
context:
space:
mode:
authorChristian Duerr <chrisduerr@users.noreply.github.com>2019-07-10 21:17:20 +0000
committerGitHub <noreply@github.com>2019-07-10 21:17:20 +0000
commitc4d2725e14ca9488b1b086024bf827c66945ae7b (patch)
treed8fd69f06671b30aa2df5c9bd5a0d161fabcfbc9 /alacritty_terminal/src/grid/row.rs
parenta99547cc6dc1d752b29de785f969591c1ed74782 (diff)
downloadalacritty-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/row.rs')
-rw-r--r--alacritty_terminal/src/grid/row.rs27
1 files changed, 19 insertions, 8 deletions
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;
}