macOS: Add the default shortcut cmd+k to clear the terminal screen and scrollback up to the cursor

Fixes #4625
This commit is contained in:
Kovid Goyal 2022-02-04 11:58:52 +05:30
parent 7d496f20a1
commit 50bc5b0302
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
8 changed files with 24 additions and 4 deletions

View File

@ -88,6 +88,9 @@ Detailed list of changes
- macOS: Fix a regression in the previous release that broke switching input
sources by keyboard (:iss:`4621`)
- macOS: Add the default shortcut :kbd:`cmd+k` to clear the terminal screen and
scrollback up to the cursor (:iss:`4625`)
0.24.2 [2022-02-03]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -1038,6 +1038,7 @@ process_cocoa_pending_actions(void) {
if (cocoa_pending_actions[NEW_WINDOW]) { call_boss(new_window, NULL); }
if (cocoa_pending_actions[CLOSE_WINDOW]) { call_boss(close_window, NULL); }
if (cocoa_pending_actions[RESET_TERMINAL]) { call_boss(clear_terminal, "sO", "reset", Py_True ); }
if (cocoa_pending_actions[CLEAR_TERMINAL_AND_SCROLLBACK]) { call_boss(clear_terminal, "sO", "to_cursor", Py_True ); }
if (cocoa_pending_actions[RELOAD_CONFIG]) { call_boss(load_config_file, NULL); }
if (cocoa_pending_actions[TOGGLE_MACOS_SECURE_KEYBOARD_ENTRY]) { call_boss(toggle_macos_secure_keyboard_entry, NULL); }
if (cocoa_pending_actions_data.wd) {

View File

@ -231,6 +231,7 @@ PENDING(previous_tab, PREVIOUS_TAB)
PENDING(new_window, NEW_WINDOW)
PENDING(close_window, CLOSE_WINDOW)
PENDING(reset_terminal, RESET_TERMINAL)
PENDING(clear_terminal_and_scrollback, CLEAR_TERMINAL_AND_SCROLLBACK)
PENDING(reload_config, RELOAD_CONFIG)
PENDING(toggle_macos_secure_keyboard_entry, TOGGLE_MACOS_SECURE_KEYBOARD_ENTRY)
@ -270,7 +271,7 @@ typedef struct {
} GlobalShortcut;
typedef struct {
GlobalShortcut new_os_window, close_os_window, close_tab, edit_config_file, reload_config;
GlobalShortcut previous_tab, next_tab, new_tab, new_window, close_window, reset_terminal;
GlobalShortcut previous_tab, next_tab, new_tab, new_window, close_window, reset_terminal, clear_terminal_and_scrollback;
GlobalShortcut toggle_macos_secure_keyboard_entry;
} GlobalShortcuts;
static GlobalShortcuts global_shortcuts;
@ -285,7 +286,7 @@ cocoa_set_global_shortcut(PyObject *self UNUSED, PyObject *args) {
#define Q(x) if (strcmp(name, #x) == 0) gs = &global_shortcuts.x
Q(new_os_window); else Q(close_os_window); else Q(close_tab); else Q(edit_config_file);
else Q(new_tab); else Q(next_tab); else Q(previous_tab);
else Q(new_window); else Q(close_window); else Q(reset_terminal); else Q(reload_config);
else Q(new_window); else Q(close_window); else Q(reset_terminal); else Q(clear_terminal_and_scrollback); else Q(reload_config);
else Q(toggle_macos_secure_keyboard_entry);
#undef Q
if (gs == NULL) { PyErr_SetString(PyExc_KeyError, "Unknown shortcut name"); return NULL; }
@ -593,6 +594,7 @@ cocoa_create_global_menu(void) {
MENU_ITEM(shellMenu, @"Close Window", close_window);
[shellMenu addItem:[NSMenuItem separatorItem]];
MENU_ITEM(shellMenu, @"Reset", reset_terminal);
MENU_ITEM(shellMenu, @"Clear up to cursor line", clear_terminal_and_scrollback);
[shellMenu release];
NSMenuItem* windowMenuItem =

View File

@ -158,6 +158,9 @@ def _run_app(opts: Options, args: CLIOptions, bad_lines: Sequence[BadLine] = ())
val = get_macos_shortcut_for(func_map, 'clear_terminal reset active', lookup_name='reset_terminal')
if val is not None:
global_shortcuts['reset_terminal'] = val
val = get_macos_shortcut_for(func_map, 'clear_terminal to_cursor active', lookup_name='clear_terminal_and_scrollback')
if val is not None:
global_shortcuts['clear_terminal_and_scrollback'] = val
val = get_macos_shortcut_for(func_map, 'load_config_file', lookup_name='reload_config')
if val is not None:
global_shortcuts['reload_config'] = val

View File

@ -3627,6 +3627,11 @@ map('Reset the terminal',
only='macos',
)
map('Clear up to cursor line',
'clear_terminal_and_scrollback cmd+k clear_terminal to_cursor active',
only='macos',
)
map('Reload kitty.conf',
'reload_config_file kitty_mod+f5 load_config_file',
long_text='''

View File

@ -902,6 +902,7 @@ if is_macos:
defaults.map.append(KeyDefinition(trigger=SingleKey(mods=12, key=32), definition='kitten unicode_input')) # noqa
defaults.map.append(KeyDefinition(trigger=SingleKey(mods=8, key=44), definition='edit_config_file')) # noqa
defaults.map.append(KeyDefinition(trigger=SingleKey(mods=10, key=114), definition='clear_terminal reset active')) # noqa
defaults.map.append(KeyDefinition(trigger=SingleKey(mods=8, key=107), definition='clear_terminal to_cursor active')) # noqa
defaults.map.append(KeyDefinition(trigger=SingleKey(mods=12, key=44), definition='load_config_file')) # noqa
defaults.map.append(KeyDefinition(trigger=SingleKey(mods=10, key=44), definition='debug_config')) # noqa
defaults.mouse_map = [

View File

@ -163,9 +163,13 @@ def clear_terminal(func: str, rest: str) -> FuncArgsType:
vals = rest.strip().split(maxsplit=1)
if len(vals) != 2:
log_error('clear_terminal needs two arguments, using defaults')
args: List[Union[str, bool]] = ['reset', 'active']
args = ['reset', True]
else:
args = [vals[0].lower(), vals[1].lower() == 'active']
action = vals[0].lower()
if action not in ('reset', 'scroll', 'scrollback', 'clear', 'to_cursor',):
log_error(f'{action} is unknown for clear_terminal, using reset')
action = 'reset'
args = [action, vals[1].lower() == 'active']
return func, args

View File

@ -302,6 +302,7 @@ typedef enum {
NEW_WINDOW,
CLOSE_WINDOW,
RESET_TERMINAL,
CLEAR_TERMINAL_AND_SCROLLBACK,
RELOAD_CONFIG,
TOGGLE_MACOS_SECURE_KEYBOARD_ENTRY,