diff --git a/docs/changelog.rst b/docs/changelog.rst index 4bdb94a6f..a07b42405 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -28,6 +28,10 @@ Changelog - Allow running kitten via the remote control system (:iss:`738`) +- Add a keyboard shortcut to reset the terminal (:sc:`reset_terminal`). It + takes parameters so you can define your own shortcuts to clear the + screen/scrollback also (:iss:`747`) + 0.11.3 [2018-07-10] ------------------------------ diff --git a/docs/index.rst b/docs/index.rst index fb0dc5a26..d4b529805 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -165,6 +165,7 @@ Restore font size :sc:`reset_font_size` Toggle fullscreen :sc:`toggle_fullscreen` Input unicode character :sc:`input_unicode_character` Click URL using the keyboard :sc:`open_url` +Reset the terminal :sc:`reset_terminal` Pass current selection to program :sc:`pass_selection_to_program` Edit |kitty| config file :sc:`edit_config_file` Open a |kitty| shell :sc:`kitty_shell` diff --git a/kitty/boss.py b/kitty/boss.py index 0eb9db7a2..4c2c98711 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -322,6 +322,23 @@ class Boss: if tm is not None: tm.resize() + def clear_terminal(self, action, only_active): + if only_active: + windows = [] + w = self.active_window + if w is not None: + windows.append(w) + else: + windows = self.all_windows + reset = action == 'reset' + how = 3 if action == 'scrollback' else 2 + for w in windows: + w.screen.cursor.x = w.screen.cursor.y = 0 + if reset: + w.screen.reset() + else: + w.screen.erase_in_display(how, False) + def increase_font_size(self): # legacy cfs = global_font_size() self.set_font_size(min(self.opts.font_size * 5, cfs + 2.0)) diff --git a/kitty/config.py b/kitty/config.py index f34edd4c8..360bbef8a 100644 --- a/kitty/config.py +++ b/kitty/config.py @@ -121,6 +121,17 @@ def parse_change_font_size(func, rest): return func, args +@func_with_args('clear_terminal') +def clear_terminal(func, rest): + vals = rest.split(' ', 1) + if len(vals) != 2: + log_error('clear_terminal needs two arguments, using defaults') + args = ['reset', 'active'] + else: + args = [vals[0].lower(), vals[1].lower() == 'active'] + return func, args + + def parse_key_action(action): parts = action.split(' ', 1) func = parts[0] diff --git a/kitty/config_data.py b/kitty/config_data.py index ed4857df9..1b2f7e577 100644 --- a/kitty/config_data.py +++ b/kitty/config_data.py @@ -893,6 +893,17 @@ k('increase_background_opacity', 'kitty_mod+a>m', 'set_background_opacity +0.1', k('decrease_background_opacity', 'kitty_mod+a>l', 'set_background_opacity -0.1', _('Decrease background opacity')) k('full_background_opacity', 'kitty_mod+a>1', 'set_background_opacity 1', _('Make background fully opaque')) k('reset_background_opacity', 'kitty_mod+a>d', 'set_background_opacity default', _('Reset background opacity')) +k('reset_terminal', 'kitty_mod+delete', 'clear_terminal reset active', _('Reset the terminal'), + long_text=_(''' +You can create shortcuts to clear/reset the terminal. For example:: + + map kitty_mod+f9 clear_terminal reset active + map kitty_mod+f10 clear_terminal clear active + map kitty_mod+f11 clear_terminal scrollback active + +These will reset screen/clear screen/clear screen+scrollback respectively. If you want to +operate on all windows instead of just the current one, use :italic:`all` instead of :italic`active`. +''')) k('send_text', 'ctrl+shift+alt+h', 'send_text all Hello World', _('Send arbitrary text on key presses'), add_to_default=False, long_text=_(''' You can tell kitty to send arbitrary (UTF-8) encoded text to