Add a keyboard shortcut to reset the terminal

It takes parameters so you can define your own shortcuts to clear the screen/scrollback also. Fixes #747
This commit is contained in:
Kovid Goyal 2018-07-26 17:29:13 +05:30
parent 1486af8770
commit 011866a101
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
5 changed files with 44 additions and 0 deletions

View File

@ -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]
------------------------------

View File

@ -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`

View File

@ -322,6 +322,23 @@ def on_window_resize(self, os_window_id, w, h, dpi_changed):
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))

View File

@ -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]

View File

@ -893,6 +893,17 @@ def macos_titlebar_color(x):
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