Add "Clear scrollback" action

This commit is contained in:
Joel Höner 2024-09-15 23:53:13 +02:00 committed by Jeremy Soller
parent 29aa3b4027
commit 4beabca14d
6 changed files with 23 additions and 0 deletions

View file

@ -83,6 +83,7 @@ copy = Kopieren
paste = Einfügen
select-all = Alles auswählen
find = Suchen
clear-scrollback = Scrollverlauf löschen
## Ansicht
view = Ansicht

View file

@ -83,6 +83,7 @@ copy = Copy
paste = Paste
select-all = Select all
find = Find
clear-scrollback = Clear scrollback
## View
view = View

View file

@ -83,6 +83,7 @@ copy = Copy
paste = Paste
select-all = Select all
find = Find
clear-scrollback = Clear scrollback
## View
view = View

View file

@ -75,5 +75,8 @@ pub fn key_binds() -> HashMap<KeyBind, Action> {
bind!([Ctrl, Shift], Key::Named(Named::ArrowRight), PaneFocusRight);
bind!([Ctrl, Shift], Key::Character("L".into()), PaneFocusRight);
// CTRL+Alt+L clears the scrollback.
bind!([Ctrl, Alt], Key::Character("L".into()), ClearScrollback);
key_binds
}

View file

@ -180,6 +180,7 @@ pub struct Flags {
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Action {
About,
ClearScrollback,
ColorSchemes(ColorSchemeKind),
Copy,
CopyOrSigint,
@ -224,6 +225,7 @@ impl Action {
fn message(&self, entity_opt: Option<segmented_button::Entity>) -> Message {
match self {
Self::About => Message::ToggleContextPage(ContextPage::About),
Self::ClearScrollback => Message::ClearScrollback(entity_opt),
Self::ColorSchemes(color_scheme_kind) => {
Message::ToggleContextPage(ContextPage::ColorSchemes(*color_scheme_kind))
}
@ -280,6 +282,7 @@ impl MenuAction for Action {
#[derive(Clone, Debug)]
pub enum Message {
AppTheme(AppTheme),
ClearScrollback(Option<segmented_button::Entity>),
ColorSchemeCollapse,
ColorSchemeDelete(ColorSchemeKind, ColorSchemeId),
ColorSchemeExpand(ColorSchemeKind, Option<ColorSchemeId>),
@ -1576,6 +1579,16 @@ impl Application for App {
config_set!(app_theme, app_theme);
return self.update_config();
}
Message::ClearScrollback(entity_opt) => {
if let Some(tab_model) = self.pane_model.active() {
let entity = entity_opt.unwrap_or_else(|| tab_model.active());
if let Some(terminal) = tab_model.data::<Mutex<Terminal>>(entity) {
let terminal = terminal.lock().unwrap();
let mut term = terminal.term.lock();
term.grid_mut().clear_history();
}
}
}
Message::ColorSchemeCollapse => {
self.color_scheme_expanded = None;
}

View file

@ -62,6 +62,8 @@ pub fn context_menu<'a>(
menu_item(fl!("paste"), Action::Paste),
menu_item(fl!("select-all"), Action::SelectAll),
horizontal_rule(1),
menu_item(fl!("clear-scrollback"), Action::ClearScrollback),
horizontal_rule(1),
menu_item(fl!("split-horizontal"), Action::PaneSplitHorizontal),
menu_item(fl!("split-vertical"), Action::PaneSplitVertical),
menu_item(fl!("pane-toggle-maximize"), Action::PaneToggleMaximized),
@ -178,6 +180,8 @@ pub fn menu_bar<'a>(config: &Config, key_binds: &HashMap<KeyBind, Action>) -> El
MenuItem::Button(fl!("paste"), Action::Paste),
MenuItem::Button(fl!("select-all"), Action::SelectAll),
MenuItem::Divider,
MenuItem::Button(fl!("clear-scrollback"), Action::ClearScrollback),
MenuItem::Divider,
MenuItem::Button(fl!("find"), Action::Find),
],
),