macOS: Add a global menu entry to reset the terminal
This commit is contained in:
@@ -999,6 +999,7 @@ process_global_state(void *data) {
|
|||||||
if (cocoa_pending_actions & DETACH_TAB) { call_boss(detach_tab, NULL); }
|
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 & NEW_WINDOW) { call_boss(new_window, NULL); }
|
||||||
if (cocoa_pending_actions & CLOSE_WINDOW) { call_boss(close_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_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_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); }
|
if (cocoa_pending_actions & NEW_TAB_WITH_WD) { call_boss(new_tab_with_wd, "s", cocoa_pending_actions_data.wd); }
|
||||||
|
|||||||
@@ -90,6 +90,7 @@ PENDING(next_tab, NEXT_TAB)
|
|||||||
PENDING(previous_tab, PREVIOUS_TAB)
|
PENDING(previous_tab, PREVIOUS_TAB)
|
||||||
PENDING(new_window, NEW_WINDOW)
|
PENDING(new_window, NEW_WINDOW)
|
||||||
PENDING(close_window, CLOSE_WINDOW)
|
PENDING(close_window, CLOSE_WINDOW)
|
||||||
|
PENDING(reset_terminal, RESET_TERMINAL)
|
||||||
|
|
||||||
- (void)open_kitty_website_url:(id)sender {
|
- (void)open_kitty_website_url:(id)sender {
|
||||||
(void)sender;
|
(void)sender;
|
||||||
@@ -117,7 +118,7 @@ typedef struct {
|
|||||||
} GlobalShortcut;
|
} GlobalShortcut;
|
||||||
typedef struct {
|
typedef struct {
|
||||||
GlobalShortcut new_os_window, close_os_window, close_tab, edit_config_file;
|
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;
|
} GlobalShortcuts;
|
||||||
static GlobalShortcuts global_shortcuts;
|
static GlobalShortcuts global_shortcuts;
|
||||||
|
|
||||||
@@ -131,7 +132,7 @@ cocoa_set_global_shortcut(PyObject *self UNUSED, PyObject *args) {
|
|||||||
#define Q(x) if (strcmp(name, #x) == 0) gs = &global_shortcuts.x
|
#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);
|
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_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
|
#undef Q
|
||||||
if (gs == NULL) { PyErr_SetString(PyExc_KeyError, "Unknown shortcut name"); return NULL; }
|
if (gs == NULL) { PyErr_SetString(PyExc_KeyError, "Unknown shortcut name"); return NULL; }
|
||||||
int cocoa_mods;
|
int cocoa_mods;
|
||||||
@@ -425,6 +426,8 @@ cocoa_create_global_menu(void) {
|
|||||||
MENU_ITEM(shellMenu, @"Close OS Window", close_os_window);
|
MENU_ITEM(shellMenu, @"Close OS Window", close_os_window);
|
||||||
MENU_ITEM(shellMenu, @"Close Tab", close_tab);
|
MENU_ITEM(shellMenu, @"Close Tab", close_tab);
|
||||||
MENU_ITEM(shellMenu, @"Close Window", close_window);
|
MENU_ITEM(shellMenu, @"Close Window", close_window);
|
||||||
|
[shellMenu addItem:[NSMenuItem separatorItem]];
|
||||||
|
MENU_ITEM(shellMenu, @"Reset", reset_terminal);
|
||||||
[shellMenu release];
|
[shellMenu release];
|
||||||
|
|
||||||
NSMenuItem* windowMenuItem =
|
NSMenuItem* windowMenuItem =
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import os
|
|||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
from contextlib import contextmanager, suppress
|
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 .borders import load_borders_program
|
||||||
from .boss import Boss
|
from .boss import Boss
|
||||||
@@ -104,11 +104,11 @@ def init_glfw(opts: Options, debug_keyboard: bool = False, debug_rendering: bool
|
|||||||
return glfw_module
|
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
|
ans = None
|
||||||
candidates = []
|
candidates = []
|
||||||
for k, v in opts.keymap.items():
|
for k, v in opts.keymap.items():
|
||||||
if v.func == function:
|
if v.func == function and v.args == args:
|
||||||
candidates.append(k)
|
candidates.append(k)
|
||||||
if candidates:
|
if candidates:
|
||||||
from .fast_data_types import cocoa_set_global_shortcut
|
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
|
# presumably because Apple reserves them for IME, see
|
||||||
# https://github.com/kovidgoyal/kitty/issues/3515
|
# https://github.com/kovidgoyal/kitty/issues/3515
|
||||||
continue
|
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
|
ans = candidate
|
||||||
break
|
break
|
||||||
return ans
|
return ans
|
||||||
@@ -140,6 +140,9 @@ def _run_app(opts: Options, args: CLIOptions, bad_lines: Sequence[BadLine] = ())
|
|||||||
val = get_macos_shortcut_for(opts, ac)
|
val = get_macos_shortcut_for(opts, ac)
|
||||||
if val is not None:
|
if val is not None:
|
||||||
global_shortcuts[ac] = val
|
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:
|
if is_macos and opts.macos_custom_beam_cursor:
|
||||||
set_custom_ibeam_cursor()
|
set_custom_ibeam_cursor()
|
||||||
if not is_wayland() and not is_macos: # no window icons on wayland
|
if not is_wayland() and not is_macos: # no window icons on wayland
|
||||||
|
|||||||
@@ -3275,6 +3275,12 @@ and clear the screen, instead of just clearing the screen::
|
|||||||
'''
|
'''
|
||||||
)
|
)
|
||||||
|
|
||||||
|
map('Reset the terminal',
|
||||||
|
'reset_terminal cmd+option+r clear_terminal reset active',
|
||||||
|
only="macos"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
map('Send arbitrary text on key presses',
|
map('Send arbitrary text on key presses',
|
||||||
'send_text ctrl+shift+alt+h send_text all Hello World',
|
'send_text ctrl+shift+alt+h send_text all Hello World',
|
||||||
add_to_default=False,
|
add_to_default=False,
|
||||||
|
|||||||
2
kitty/options/types.py
generated
2
kitty/options/types.py
generated
@@ -772,6 +772,7 @@ defaults.map = [
|
|||||||
KeyDefinition(True, KeyAction('set_background_opacity', ('1',)), 1024, False, 97, (SingleKey(mods=0, is_native=False, key=49),)),
|
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(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)), 1024, False, 57349, ()),
|
||||||
|
KeyDefinition(False, KeyAction('clear_terminal', ('reset', True)), 10, False, 114, ()),
|
||||||
]
|
]
|
||||||
if is_macos:
|
if is_macos:
|
||||||
defaults.map.append(KeyDefinition(False, KeyAction('copy_to_clipboard'), 8, False, 99, ()))
|
defaults.map.append(KeyDefinition(False, KeyAction('copy_to_clipboard'), 8, False, 99, ()))
|
||||||
@@ -811,6 +812,7 @@ if is_macos:
|
|||||||
defaults.map.append(KeyDefinition(False, KeyAction('change_font_size', (True, None, 0.0)), 8, False, 48, ()))
|
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('kitten', ('unicode_input',)), 12, False, 32, ()))
|
||||||
defaults.map.append(KeyDefinition(False, KeyAction('edit_config_file'), 8, False, 44, ()))
|
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 = [
|
defaults.mouse_map = [
|
||||||
MouseMapping(0, 0, -2, False, KeyAction('mouse_click_url_or_select')),
|
MouseMapping(0, 0, -2, False, KeyAction('mouse_click_url_or_select')),
|
||||||
MouseMapping(0, 1, -2, False, KeyAction('mouse_click_url_or_select')),
|
MouseMapping(0, 1, -2, False, KeyAction('mouse_click_url_or_select')),
|
||||||
|
|||||||
@@ -277,6 +277,7 @@ typedef enum {
|
|||||||
OPEN_FILE = 1024,
|
OPEN_FILE = 1024,
|
||||||
NEW_WINDOW = 2048,
|
NEW_WINDOW = 2048,
|
||||||
CLOSE_WINDOW = 4096,
|
CLOSE_WINDOW = 4096,
|
||||||
|
RESET_TERMINAL = 8192,
|
||||||
} CocoaPendingAction;
|
} CocoaPendingAction;
|
||||||
void set_cocoa_pending_action(CocoaPendingAction action, const char*);
|
void set_cocoa_pending_action(CocoaPendingAction action, const char*);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user