Skip to content

Commit

Permalink
macOS: Add menu items to the Edit menu to clear the screen and scroll…
Browse files Browse the repository at this point in the history
…back
  • Loading branch information
kovidgoyal committed Jan 5, 2025
1 parent c6ae4b0 commit cbefc72
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 3 deletions.
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
2 changes: 2 additions & 0 deletions kitty/child-monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
Expand Down
2 changes: 2 additions & 0 deletions kitty/cocoa_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 10 additions & 2 deletions kitty/cocoa_window.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:))
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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 =
Expand Down
6 changes: 6 additions & 0 deletions kitty/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion kitty/options/definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -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='''
Expand Down
2 changes: 2 additions & 0 deletions kitty/options/types.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cbefc72

Please sign in to comment.