From 33e387be7d98c728862b0bc2a8ea248b5c7cd3e9 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Mon, 25 May 2020 17:13:08 -0700 Subject: [PATCH] term: implement EraseInDisplay::EraseScrollback refs: https://github.com/wez/wezterm/issues/194 --- term/src/screen.rs | 9 +++++++++ term/src/terminalstate.rs | 2 +- term/src/test/csi.rs | 9 +++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/term/src/screen.rs b/term/src/screen.rs index 1f2da32e4..2461032fe 100644 --- a/term/src/screen.rs +++ b/term/src/screen.rs @@ -469,6 +469,15 @@ impl Screen { } } + pub fn erase_scrollback(&mut self) { + let len = self.lines.len(); + let to_clear = len - self.physical_rows; + for _ in 0..to_clear { + self.lines.pop_front(); + self.stable_row_index_offset += 1; + } + } + /// --------- /// | /// |--- top diff --git a/term/src/terminalstate.rs b/term/src/terminalstate.rs index ff80a449a..bcdf286ea 100644 --- a/term/src/terminalstate.rs +++ b/term/src/terminalstate.rs @@ -1333,7 +1333,7 @@ impl TerminalState { } EraseInDisplay::EraseDisplay => 0..rows, EraseInDisplay::EraseScrollback => { - error!("TODO: ed: no support for xterm Erase Saved Lines yet"); + self.screen_mut().erase_scrollback(); return; } }; diff --git a/term/src/test/csi.rs b/term/src/test/csi.rs index 7f940e9f8..8777a2fab 100644 --- a/term/src/test/csi.rs +++ b/term/src/test/csi.rs @@ -183,3 +183,12 @@ fn test_ed() { Compare::TEXT | Compare::ATTRS, ); } + +#[test] +fn test_ed_erase_scrollback() { + let mut term = TestTerm::new(3, 3, 3); + term.print("abc\r\ndef\r\nghi\r\n111\r\n222\r\na\x1b[3J"); + assert_all_contents(&term, file!(), line!(), &["111", "222", "a "]); + term.print("b"); + assert_all_contents(&term, file!(), line!(), &["111", "222", "ab "]); +}