From b8acbac113f801ef932faba6511aeb6c57fc16ef Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Mon, 25 May 2020 17:29:22 -0700 Subject: [PATCH] wezterm: add ClearScrollback key assignment Bound to CMD-K and CTRL+SHIFT-K by default. This also functions while the output is filling up (eg: `find /` and hit the key binding to keep pruning the scrollback). closes: https://github.com/wez/wezterm/issues/194 --- docs/changelog.markdown | 1 + docs/config/keys.markdown | 15 +++++++++++++++ src/frontend/gui/termwindow.rs | 5 +++++ src/keyassignment.rs | 3 +++ src/localtab.rs | 4 ++++ src/mux/tab.rs | 2 ++ term/src/terminalstate.rs | 4 ++++ 7 files changed, 34 insertions(+) diff --git a/docs/changelog.markdown b/docs/changelog.markdown index b82bb69b1..4ab3962d3 100644 --- a/docs/changelog.markdown +++ b/docs/changelog.markdown @@ -19,6 +19,7 @@ brief notes about them may accumulate here. followed an example from the docs; migrate instead to using eg: `action=wezterm.action{ActivateTab=i-1}` to pass the integer argument. * Windows: now also available with a setup.exe installer +* Added `ClearScrollback` key assignment to clear the scrollback. This is bound to CMD-K and CTRL-SHIFT-K by default. ### 20200517-122836-92c201c6 diff --git a/docs/config/keys.markdown b/docs/config/keys.markdown index 1a99a25f0..5cb874274 100644 --- a/docs/config/keys.markdown +++ b/docs/config/keys.markdown @@ -62,6 +62,8 @@ The default key bindings are: | `SUPER` | `r` | `ReloadConfiguration` | | `CTRL+SHIFT` | `R` | `ReloadConfiguration` | | `SUPER` | `h` | `HideApplication` (macOS only) | +| `SUPER` | `k` | `ClearScrollback` | +| `CTRL+SHIFT` | `K` | `ClearScrollback` | ## Default Mouse Assignments @@ -538,6 +540,19 @@ return { } ``` +## ClearScrollback + +Clears the lines that have scrolled off the top of the viewport, resetting +the scrollbar thumb to the full height of the window. + +```lua +return { + keys = { + {key="K", mods="CTRL|SHIFT", action="ClearScrollback"} + } +} +``` + ## ReloadConfiguration Explicitly reload the configuration. diff --git a/src/frontend/gui/termwindow.rs b/src/frontend/gui/termwindow.rs index c16bb6006..f56334f99 100644 --- a/src/frontend/gui/termwindow.rs +++ b/src/frontend/gui/termwindow.rs @@ -1469,6 +1469,11 @@ impl TermWindow { window.invalidate(); } } + ClearScrollback => { + tab.erase_scrollback(); + let window = self.window.as_ref().unwrap(); + window.invalidate(); + } }; Ok(()) } diff --git a/src/keyassignment.rs b/src/keyassignment.rs index 3e96d8176..e2f718951 100644 --- a/src/keyassignment.rs +++ b/src/keyassignment.rs @@ -97,6 +97,7 @@ pub enum KeyAssignment { SpawnCommandInNewTab(SpawnCommand), SpawnCommandInNewWindow(SpawnCommand), ShowLauncher, + ClearScrollback, SelectTextAtMouseCursor(SelectionMode), ExtendSelectionToMouseCursor(Option), @@ -158,6 +159,8 @@ impl InputMap { [KeyModifiers::SUPER, KeyCode::Char('n'), SpawnWindow], [ctrl_shift, KeyCode::Char('M'), Hide], [ctrl_shift, KeyCode::Char('N'), SpawnWindow], + [KeyModifiers::SUPER, KeyCode::Char('k'), ClearScrollback], + [ctrl_shift, KeyCode::Char('K'), ClearScrollback], // Font size manipulation [KeyModifiers::CTRL, KeyCode::Char('-'), DecreaseFontSize], [KeyModifiers::CTRL, KeyCode::Char('0'), ResetFontSize], diff --git a/src/localtab.rs b/src/localtab.rs index 7483a0e83..64a2c08f0 100644 --- a/src/localtab.rs +++ b/src/localtab.rs @@ -91,6 +91,10 @@ impl Tab for LocalTab { self.domain_id } + fn erase_scrollback(&self) { + self.terminal.borrow_mut().erase_scrollback(); + } + fn is_mouse_grabbed(&self) -> bool { self.terminal.borrow().is_mouse_grabbed() } diff --git a/src/mux/tab.rs b/src/mux/tab.rs index 0d41be244..2133f2016 100644 --- a/src/mux/tab.rs +++ b/src/mux/tab.rs @@ -59,6 +59,8 @@ pub trait Tab: Downcast { fn palette(&self) -> ColorPalette; fn domain_id(&self) -> DomainId; + fn erase_scrollback(&self) {} + /// Returns true if the terminal has grabbed the mouse and wants to /// give the embedded application a chance to process events. /// In practice this controls whether the gui will perform local diff --git a/term/src/terminalstate.rs b/term/src/terminalstate.rs index bcdf286ea..d2b68370c 100644 --- a/term/src/terminalstate.rs +++ b/term/src/terminalstate.rs @@ -487,6 +487,10 @@ impl TerminalState { } } + pub fn erase_scrollback(&mut self) { + self.screen_mut().erase_scrollback(); + } + pub fn is_mouse_grabbed(&self) -> bool { self.sgr_mouse }