macOS: Add a global menu entry to reset the terminal

This commit is contained in:
Kovid Goyal 2021-06-05 10:12:44 +05:30
parent d264c3d91e
commit 4cff3e51cb
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
6 changed files with 22 additions and 6 deletions

View file

@ -999,6 +999,7 @@ process_global_state(void *data) {
if (cocoa_pending_actions & DETACH_TAB) { call_boss(detach_tab, NULL); }
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_data.wd) {
if (cocoa_pending_actions & NEW_OS_WINDOW_WITH_WD) { call_boss(new_os_window_with_wd, "s", cocoa_pending_actions_data.wd); }
if (cocoa_pending_actions & NEW_TAB_WITH_WD) { call_boss(new_tab_with_wd, "s", cocoa_pending_actions_data.wd); }

View file

@ -90,6 +90,7 @@ @implementation GlobalMenuTarget
PENDING(previous_tab, PREVIOUS_TAB)
PENDING(new_window, NEW_WINDOW)
PENDING(close_window, CLOSE_WINDOW)
PENDING(reset_terminal, RESET_TERMINAL)
- (void)open_kitty_website_url:(id)sender {
(void)sender;
@ -117,7 +118,7 @@ + (GlobalMenuTarget *) shared_instance
} GlobalShortcut;
typedef struct {
GlobalShortcut new_os_window, close_os_window, close_tab, edit_config_file;
GlobalShortcut previous_tab, next_tab, new_tab, new_window, close_window;
GlobalShortcut previous_tab, next_tab, new_tab, new_window, close_window, reset_terminal;
} GlobalShortcuts;
static GlobalShortcuts global_shortcuts;
@ -131,7 +132,7 @@ + (GlobalMenuTarget *) shared_instance
#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(new_window); else Q(close_window); else Q(reset_terminal);
#undef Q
if (gs == NULL) { PyErr_SetString(PyExc_KeyError, "Unknown shortcut name"); return NULL; }
int cocoa_mods;
@ -425,6 +426,8 @@ - (BOOL)openFilesFromPasteboard:(NSPasteboard *)pasteboard type:(int)type {
MENU_ITEM(shellMenu, @"Close OS Window", close_os_window);
MENU_ITEM(shellMenu, @"Close Tab", close_tab);
MENU_ITEM(shellMenu, @"Close Window", close_window);
[shellMenu addItem:[NSMenuItem separatorItem]];
MENU_ITEM(shellMenu, @"Reset", reset_terminal);
[shellMenu release];
NSMenuItem* windowMenuItem =

View file

@ -7,7 +7,7 @@
import shutil
import sys
from contextlib import contextmanager, suppress
from typing import Dict, Generator, List, Optional, Sequence
from typing import Dict, Generator, List, Optional, Sequence, Tuple
from .borders import load_borders_program
from .boss import Boss
@ -104,11 +104,11 @@ def init_glfw(opts: Options, debug_keyboard: bool = False, debug_rendering: bool
return glfw_module
def get_macos_shortcut_for(opts: Options, function: str = 'new_os_window') -> Optional[SingleKey]:
def get_macos_shortcut_for(opts: Options, function: str = 'new_os_window', args: Tuple = (), lookup_name: str = '') -> Optional[SingleKey]:
ans = None
candidates = []
for k, v in opts.keymap.items():
if v.func == function:
if v.func == function and v.args == args:
candidates.append(k)
if candidates:
from .fast_data_types import cocoa_set_global_shortcut
@ -120,7 +120,7 @@ def get_macos_shortcut_for(opts: Options, function: str = 'new_os_window') -> Op
# presumably because Apple reserves them for IME, see
# https://github.com/kovidgoyal/kitty/issues/3515
continue
if cocoa_set_global_shortcut(function, candidate[0], candidate[2]):
if cocoa_set_global_shortcut(lookup_name or function, candidate[0], candidate[2]):
ans = candidate
break
return ans
@ -140,6 +140,9 @@ def _run_app(opts: Options, args: CLIOptions, bad_lines: Sequence[BadLine] = ())
val = get_macos_shortcut_for(opts, ac)
if val is not None:
global_shortcuts[ac] = val
val = get_macos_shortcut_for(opts, 'clear_terminal', args=('reset', True), lookup_name='reset_terminal')
if val is not None:
global_shortcuts['reset_terminal'] = val
if is_macos and opts.macos_custom_beam_cursor:
set_custom_ibeam_cursor()
if not is_wayland() and not is_macos: # no window icons on wayland

View file

@ -3275,6 +3275,12 @@
'''
)
map('Reset the terminal',
'reset_terminal cmd+option+r clear_terminal reset active',
only="macos"
)
map('Send arbitrary text on key presses',
'send_text ctrl+shift+alt+h send_text all Hello World',
add_to_default=False,

View file

@ -772,6 +772,7 @@ def __setattr__(self, key: str, val: typing.Any) -> typing.Any:
KeyDefinition(True, KeyAction('set_background_opacity', ('1',)), 1024, False, 97, (SingleKey(mods=0, is_native=False, key=49),)),
KeyDefinition(True, KeyAction('set_background_opacity', ('default',)), 1024, False, 97, (SingleKey(mods=0, is_native=False, key=100),)),
KeyDefinition(False, KeyAction('clear_terminal', ('reset', True)), 1024, False, 57349, ()),
KeyDefinition(False, KeyAction('clear_terminal', ('reset', True)), 10, False, 114, ()),
]
if is_macos:
defaults.map.append(KeyDefinition(False, KeyAction('copy_to_clipboard'), 8, False, 99, ()))
@ -811,6 +812,7 @@ def __setattr__(self, key: str, val: typing.Any) -> typing.Any:
defaults.map.append(KeyDefinition(False, KeyAction('change_font_size', (True, None, 0.0)), 8, False, 48, ()))
defaults.map.append(KeyDefinition(False, KeyAction('kitten', ('unicode_input',)), 12, False, 32, ()))
defaults.map.append(KeyDefinition(False, KeyAction('edit_config_file'), 8, False, 44, ()))
defaults.map.append(KeyDefinition(False, KeyAction('clear_terminal', ('reset', True)), 10, False, 114, ()))
defaults.mouse_map = [
MouseMapping(0, 0, -2, False, KeyAction('mouse_click_url_or_select')),
MouseMapping(0, 1, -2, False, KeyAction('mouse_click_url_or_select')),

View file

@ -277,6 +277,7 @@ typedef enum {
OPEN_FILE = 1024,
NEW_WINDOW = 2048,
CLOSE_WINDOW = 4096,
RESET_TERMINAL = 8192,
} CocoaPendingAction;
void set_cocoa_pending_action(CocoaPendingAction action, const char*);
#endif