aboutsummaryrefslogtreecommitdiff
path: root/alacritty_terminal/src/grid/mod.rs
diff options
context:
space:
mode:
authorNathan Lilienthal <nathan@nixpulvis.com>2019-11-18 16:15:25 -0500
committerChristian Duerr <contact@christianduerr.com>2019-11-18 22:15:25 +0100
commit182a9d5c2e01ec9b155fc7edf547e8e6de2f2bd5 (patch)
tree56889a5b18e40c7f4b30ea53b8eb152fbeb82a2d /alacritty_terminal/src/grid/mod.rs
parentbcdc605436ebe137173c531844a739eda6ee41ae (diff)
downloadr-alacritty-182a9d5c2e01ec9b155fc7edf547e8e6de2f2bd5.tar.gz
r-alacritty-182a9d5c2e01ec9b155fc7edf547e8e6de2f2bd5.tar.bz2
r-alacritty-182a9d5c2e01ec9b155fc7edf547e8e6de2f2bd5.zip
Fix deletion of lines when clearing the screen
Previously Alacritty would delete lines when clearing the screen, leading to a loss of data in the scrollback buffer. Instead of deleting these lines, they are now rotated outside of the visible region. This also fixes some issues with Alacritty only resetting lines partially when the background color of the template cell changed. Fixes #2199.
Diffstat (limited to 'alacritty_terminal/src/grid/mod.rs')
-rw-r--r--alacritty_terminal/src/grid/mod.rs66
1 files changed, 56 insertions, 10 deletions
diff --git a/alacritty_terminal/src/grid/mod.rs b/alacritty_terminal/src/grid/mod.rs
index 3141208f..09333b36 100644
--- a/alacritty_terminal/src/grid/mod.rs
+++ b/alacritty_terminal/src/grid/mod.rs
@@ -73,6 +73,32 @@ pub trait GridCell {
}
/// Represents the terminal display contents
+///
+/// ```notrust
+/// ┌─────────────────────────┐ <-- max_scroll_limit + lines
+/// │ │
+/// │ UNINITIALIZED │
+/// │ │
+/// ├─────────────────────────┤ <-- raw.len()
+/// │ │
+/// │ RESIZE BUFFER │
+/// │ │
+/// ├─────────────────────────┤ <-- scroll_limit + lines
+/// │ │
+/// │ SCROLLUP REGION │
+/// │ │
+/// ├─────────────────────────┤v lines
+/// │ │|
+/// │ VISIBLE REGION │|
+/// │ │|
+/// ├─────────────────────────┤^ <-- display_offset
+/// │ │
+/// │ SCROLLDOWN REGION │
+/// │ │
+/// └─────────────────────────┘ <-- zero
+/// ^
+/// cols
+/// ```
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Grid<T> {
/// Lines in the grid. Each row holds a list of cells corresponding to the
@@ -82,9 +108,7 @@ pub struct Grid<T> {
/// Number of columns
cols: index::Column,
- /// Number of lines.
- ///
- /// Invariant: lines is equivalent to raw.len()
+ /// Number of visible lines.
lines: index::Line,
/// Offset of displayed area
@@ -472,10 +496,10 @@ impl<T: GridCell + Copy + Clone> Grid<T> {
selection.rotate(*positions as isize);
}
- // // This next loop swaps "fixed" lines outside of a scroll region
- // // back into place after the rotation. The work is done in buffer-
- // // space rather than terminal-space to avoid redundant
- // // transformations.
+ // This next loop swaps "fixed" lines outside of a scroll region
+ // back into place after the rotation. The work is done in buffer-
+ // space rather than terminal-space to avoid redundant
+ // transformations.
let fixed_lines = *self.num_lines() - *region.end;
for i in 0..fixed_lines {
@@ -501,11 +525,30 @@ impl<T: GridCell + Copy + Clone> Grid<T> {
}
}
+ pub fn clear_viewport(&mut self, template: &T) {
+ // Determine how many lines to scroll up by.
+ let end = Point { line: 0, col: self.num_cols() };
+ let mut iter = self.iter_from(end);
+ while let Some(cell) = iter.prev() {
+ if !cell.is_empty() || iter.cur.line >= *self.lines {
+ break;
+ }
+ }
+ debug_assert!(iter.cur.line <= *self.lines);
+ let positions = self.lines - iter.cur.line;
+ let region = Line(0)..self.num_lines();
+
+ // Clear the viewport
+ self.scroll_up(&region, positions, template);
+
+ // Reset rotated lines
+ for i in positions.0..self.lines.0 {
+ self.raw[i].reset(&template);
+ }
+ }
+
// Completely reset the grid state
pub fn reset(&mut self, template: &T) {
- // Explicitly purge all lines from history
- let shrinkage = self.raw.len() - self.lines.0;
- self.raw.shrink_lines(shrinkage);
self.clear_history();
// Reset all visible lines
@@ -535,6 +578,9 @@ impl<T> Grid<T> {
}
pub fn clear_history(&mut self) {
+ // Explicitly purge all lines from history
+ let shrinkage = self.raw.len() - self.lines.0;
+ self.raw.shrink_lines(shrinkage);
self.scroll_limit = 0;
}