diff options
author | Nathan Lilienthal <nathan@nixpulvis.com> | 2018-09-01 20:30:03 -0400 |
---|---|---|
committer | Christian Duerr <chrisduerr@users.noreply.github.com> | 2018-09-02 00:30:03 +0000 |
commit | 72495172c25e00799f29eb2e79fe40ddfa189866 (patch) | |
tree | 996394ed5bef5318aaf202db98076f0455b02734 /src/term | |
parent | 8e8ecdd0f98dd8005cd940d19dc0a922661d64fc (diff) | |
download | alacritty-72495172c25e00799f29eb2e79fe40ddfa189866.tar.gz alacritty-72495172c25e00799f29eb2e79fe40ddfa189866.zip |
Implement `ansi::ClearMode::Saved`
The clearing the screen for the `ansi::ClearMode::Saved` enum value
has been implemented. This is used to clear all lines which are
currently outside of the visible region but still inside the scrollback
buffer.
The specifications of XTerm indicate that the clearing of saved lines
should only clear the saved lines and not the saved lines plus the
currently visible part of the grid. Applications like `clear` send both
the escape for clearing history plus the escape for clearing history
when requested, so all sources seem to agree here.
To allow both clearing the screen and the saved lines when a key is
pressed the `process_key_bindings` method has been altered so multiple
bindings can be specified. So it is now possible to execute both `^L`
and `ClearHistory` with just a single binding. The
`process_mouse_bindings` method has also been changed for consistency.
To make sure everything works properly a test has been added which
clears the history and then attempts to scroll. Since scrolling is the
only way for a user to check if scrollback is available, this seems like
a nice abstraction to check if there is a scrollback.
Diffstat (limited to 'src/term')
-rw-r--r-- | src/term/mod.rs | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/src/term/mod.rs b/src/term/mod.rs index ff7a53e9..21c97671 100644 --- a/src/term/mod.rs +++ b/src/term/mod.rs @@ -1797,7 +1797,9 @@ impl ansi::Handler for Term { } }, // If scrollback is implemented, this should clear it - ansi::ClearMode::Saved => return + ansi::ClearMode::Saved => { + self.grid.clear_history(); + } } } @@ -2006,9 +2008,9 @@ mod tests { use super::{Cell, Term, SizeInfo}; use term::cell; - use grid::Grid; + use grid::{Grid, Scroll}; use index::{Point, Line, Column}; - use ansi::{Handler, CharsetIndex, StandardCharset}; + use ansi::{self, Handler, CharsetIndex, StandardCharset}; use selection::Selection; use std::mem; use input::FONT_SIZE_STEP; @@ -2183,6 +2185,31 @@ mod tests { let expected_font_size: Size = config.font().size(); assert_eq!(term.font_size, expected_font_size); } + + #[test] + fn clear_saved_lines() { + let size = SizeInfo { + width: 21.0, + height: 51.0, + cell_width: 3.0, + cell_height: 3.0, + padding_x: 0.0, + padding_y: 0.0, + }; + let config: Config = Default::default(); + let mut term: Term = Term::new(&config, size); + + // Add one line of scrollback + term.grid.scroll_up(&(Line(0)..Line(1)), Line(1), &Cell::default()); + + // Clear the history + term.clear_screen(ansi::ClearMode::Saved); + + // Make sure that scrolling does not change the grid + let mut scrolled_grid = term.grid.clone(); + scrolled_grid.scroll_display(Scroll::Top); + assert_eq!(term.grid, scrolled_grid); + } } #[cfg(all(test, feature = "bench"))] |