From 182a9d5c2e01ec9b155fc7edf547e8e6de2f2bd5 Mon Sep 17 00:00:00 2001 From: Nathan Lilienthal Date: Mon, 18 Nov 2019 16:15:25 -0500 Subject: 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. --- alacritty_terminal/src/term/mod.rs | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'alacritty_terminal/src/term/mod.rs') diff --git a/alacritty_terminal/src/term/mod.rs b/alacritty_terminal/src/term/mod.rs index 8d69fb3b..6a51ba35 100644 --- a/alacritty_terminal/src/term/mod.rs +++ b/alacritty_terminal/src/term/mod.rs @@ -701,7 +701,9 @@ pub struct Term { /// Mode flags mode: TermMode, - /// Scroll region + /// Scroll region. + /// + /// Range going from top to bottom of the terminal, indexed from the top of the viewport. scroll_region: Range, pub dirty: bool, @@ -1749,17 +1751,6 @@ impl ansi::Handler for Term { self.grid.selection = None; match mode { - ansi::ClearMode::Below => { - for cell in &mut self.grid[self.cursor.point.line][self.cursor.point.col..] { - cell.reset(&template); - } - if self.cursor.point.line < self.grid.num_lines() - 1 { - self.grid - .region_mut((self.cursor.point.line + 1)..) - .each(|cell| cell.reset(&template)); - } - }, - ansi::ClearMode::All => self.grid.region_mut(..).each(|c| c.reset(&template)), ansi::ClearMode::Above => { // If clearing more than one line if self.cursor.point.line > Line(1) { @@ -1774,6 +1765,23 @@ impl ansi::Handler for Term { cell.reset(&template); } }, + ansi::ClearMode::Below => { + for cell in &mut self.grid[self.cursor.point.line][self.cursor.point.col..] { + cell.reset(&template); + } + if self.cursor.point.line < self.grid.num_lines() - 1 { + self.grid + .region_mut((self.cursor.point.line + 1)..) + .each(|cell| cell.reset(&template)); + } + }, + ansi::ClearMode::All => { + if self.mode.contains(TermMode::ALT_SCREEN) { + self.grid.region_mut(..).each(|c| c.reset(&template)); + } else { + self.grid.clear_viewport(&template); + } + }, ansi::ClearMode::Saved => self.grid.clear_history(), } } -- cgit