From cbefc72a7e444308cc762a62ce2901e2d1ceb074 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 5 Jan 2025 14:03:08 +0530 Subject: [PATCH] macOS: Add menu items to the Edit menu to clear the screen and scrollback --- docs/changelog.rst | 2 ++ kitty/child-monitor.c | 2 ++ kitty/cocoa_window.h | 2 ++ kitty/cocoa_window.m | 12 ++++++++++-- kitty/main.py | 6 ++++++ kitty/options/definition.py | 14 +++++++++++++- kitty/options/types.py | 2 ++ 7 files changed, 37 insertions(+), 3 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index f07a0a8ee45..c4675ec0327 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -101,6 +101,8 @@ Detailed list of changes - macOS: Allow using the Passwords app to autofill passwords via the Edit->Autofill menu mimicking other macOS applications (:pull:`8195`) +- macOS: Add menu items to the Edit menu to clear the screen and scrollback + 0.38.1 [2024-12-26] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/kitty/child-monitor.c b/kitty/child-monitor.c index a0f1eb47f7e..5cf946a8931 100644 --- a/kitty/child-monitor.c +++ b/kitty/child-monitor.c @@ -1222,6 +1222,8 @@ process_cocoa_pending_actions(void) { 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[CLEAR_SCROLLBACK]) { call_boss(clear_terminal, "sO", "scrollback", Py_True ); } + if (cocoa_pending_actions[CLEAR_SCREEN]) { call_boss(clear_terminal, "sO", "to_cursor_scroll", 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[TOGGLE_FULLSCREEN]) { call_boss(toggle_fullscreen, NULL); } diff --git a/kitty/cocoa_window.h b/kitty/cocoa_window.h index 793a613a247..b9df9187a77 100644 --- a/kitty/cocoa_window.h +++ b/kitty/cocoa_window.h @@ -25,6 +25,8 @@ typedef enum { CLOSE_WINDOW, RESET_TERMINAL, CLEAR_TERMINAL_AND_SCROLLBACK, + CLEAR_SCROLLBACK, + CLEAR_SCREEN, RELOAD_CONFIG, TOGGLE_MACOS_SECURE_KEYBOARD_ENTRY, TOGGLE_FULLSCREEN, diff --git a/kitty/cocoa_window.m b/kitty/cocoa_window.m index 14ccb2e9726..1e46817a3e1 100644 --- a/kitty/cocoa_window.m +++ b/kitty/cocoa_window.m @@ -252,6 +252,8 @@ - (void)user_menu_action:(id)sender { PENDING(close_window, CLOSE_WINDOW) PENDING(reset_terminal, RESET_TERMINAL) PENDING(clear_terminal_and_scrollback, CLEAR_TERMINAL_AND_SCROLLBACK) +PENDING(clear_scrollback, CLEAR_SCROLLBACK) +PENDING(clear_screen, CLEAR_SCREEN) PENDING(reload_config, RELOAD_CONFIG) PENDING(toggle_macos_secure_keyboard_entry, TOGGLE_MACOS_SECURE_KEYBOARD_ENTRY) PENDING(toggle_fullscreen, TOGGLE_FULLSCREEN) @@ -275,6 +277,8 @@ - (BOOL)validateMenuItem:(NSMenuItem *)item { item.action == @selector(close_window:) || item.action == @selector(reset_terminal:) || item.action == @selector(clear_terminal_and_scrollback:) || + item.action == @selector(clear_scrollback:) || + item.action == @selector(clear_screen:) || item.action == @selector(previous_tab:) || item.action == @selector(next_tab:) || item.action == @selector(detach_tab:)) @@ -308,7 +312,8 @@ + (GlobalMenuTarget *) shared_instance } 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, clear_terminal_and_scrollback; + GlobalShortcut previous_tab, next_tab, new_tab, new_window, close_window, reset_terminal; + GlobalShortcut clear_terminal_and_scrollback, clear_screen, clear_scrollback; GlobalShortcut toggle_macos_secure_keyboard_entry, toggle_fullscreen, open_kitty_website; GlobalShortcut hide_macos_app, hide_macos_other_apps, minimize_macos_window, quit; } GlobalShortcuts; @@ -324,7 +329,8 @@ + (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(reset_terminal); else Q(clear_terminal_and_scrollback); else Q(reload_config); + else Q(new_window); else Q(close_window); else Q(reset_terminal); + else Q(clear_terminal_and_scrollback); else Q(clear_scrollback); else Q(clear_screen); else Q(reload_config); else Q(toggle_macos_secure_keyboard_entry); else Q(toggle_fullscreen); else Q(open_kitty_website); else Q(hide_macos_app); else Q(hide_macos_other_apps); else Q(minimize_macos_window); else Q(quit); #undef Q @@ -772,6 +778,8 @@ - (BOOL)openFileURLs:(NSPasteboard*)pasteboard NSMenu* editMenu = [[NSMenu alloc] initWithTitle:@"Edit"]; [editMenuItem setSubmenu:editMenu]; MENU_ITEM(editMenu, @"Clear to Start", clear_terminal_and_scrollback); + MENU_ITEM(editMenu, @"Clear Scrollback", clear_scrollback); + MENU_ITEM(editMenu, @"Clear Screen", clear_screen); [editMenu release]; NSMenuItem* windowMenuItem = diff --git a/kitty/main.py b/kitty/main.py index 68c561eb2ce..5bab34bd6bd 100644 --- a/kitty/main.py +++ b/kitty/main.py @@ -192,6 +192,12 @@ def set_cocoa_global_shortcuts(opts: Options) -> dict[str, SingleKey]: 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, 'clear_terminal scrollback active', lookup_name='clear_scrollback') + if val is not None: + global_shortcuts['clear_scrollback'] = val + val = get_macos_shortcut_for(func_map, 'clear_terminal to_cursor_scroll active', lookup_name='clear_screen') + if val is not None: + global_shortcuts['clear_screen'] = 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 diff --git a/kitty/options/definition.py b/kitty/options/definition.py index d32316f0bc6..bc3ef36b192 100644 --- a/kitty/options/definition.py +++ b/kitty/options/definition.py @@ -4331,11 +4331,23 @@ only='macos', ) -map('Clear up to cursor line', +map('Clear to start', 'clear_terminal_and_scrollback cmd+k clear_terminal to_cursor active', only='macos', ) +map('Clear scrollback', + 'clear_scrollback option+cmd+k clear_terminal scrollback active', + only='macos', + ) + +map('Clear screen', + 'clear_screen cmd+ctrl+l clear_terminal to_cursor_scroll active', + only='macos', + ) + + + map('Reload kitty.conf', 'reload_config_file kitty_mod+f5 load_config_file', long_text=''' diff --git a/kitty/options/types.py b/kitty/options/types.py index a9bc54b282b..f07f0bb91ac 100644 --- a/kitty/options/types.py +++ b/kitty/options/types.py @@ -970,6 +970,8 @@ def __setattr__(self, key: str, val: typing.Any) -> typing.Any: defaults.map.append(KeyDefinition(trigger=SingleKey(mods=8, key=44), definition='edit_config_file')) defaults.map.append(KeyDefinition(trigger=SingleKey(mods=10, key=114), definition='clear_terminal reset active')) defaults.map.append(KeyDefinition(trigger=SingleKey(mods=8, key=107), definition='clear_terminal to_cursor active')) + defaults.map.append(KeyDefinition(trigger=SingleKey(mods=10, key=107), definition='clear_terminal scrollback active')) + defaults.map.append(KeyDefinition(trigger=SingleKey(mods=12, key=108), definition='clear_terminal to_cursor_scroll active')) defaults.map.append(KeyDefinition(trigger=SingleKey(mods=12, key=44), definition='load_config_file')) defaults.map.append(KeyDefinition(trigger=SingleKey(mods=10, key=44), definition='debug_config')) defaults.map.append(KeyDefinition(trigger=SingleKey(mods=9, key=47), definition='open_url https://sw.kovidgoyal.net/kitty/'))