T22: the macOS menu bar holds the PRD's menus, each item showing its key; Quit, Select All, Bigger, Smaller, Reset Size and Minimize take Ghostty's keys, Ctrl-Shift off macOS where Ctrl with a letter types a control byte; the font's size moves for every session, unsaved; Select All runs from the first character in the history to the last, as Ghostty's; shot lists the menus and says whether the app was active at each key
CI / platforms (windows-latest) (push) Failing after 8s
CI / macos (push) Failing after 8m29s
CI / platforms (ubuntu-24.04) (push) Canceled after 0s

This commit is contained in:
ZacharyZhang-NY committed 2026-10-15 01:51:46 -04:00
1 parent 149c1b5f02
commit 5ee67bd406
15 files changed
+770 -495

No files matched your search

+110
View File
@@ -0,0 +1,110 @@
use gpui::{App, InteractiveElement, KeyBinding, Menu, MenuItem, OsAction, actions};
use crate::{
settings::window::OpenSettings,
term::{
input::{Copy, Find, Paste, SelectAll},
zoom,
},
workspace::{CloseSession, NewSession, TogglePanel, ToggleSessions},
};
actions!(
elyterminal,
[Quit, Bigger, Smaller, ResetSize, Minimize, Zoom]
);
/// The menu bar the PRD lists; macOS draws it and names the first menu after the app.
pub fn menus() -> Vec<Menu> {
let menu = |name: &str, items| Menu {
name: name.to_string().into(),
items,
disabled: false,
};
vec![
menu(
"ELYTerminal",
vec![
MenuItem::action("Settings…", OpenSettings),
MenuItem::separator(),
MenuItem::action("Quit ELYTerminal", Quit),
],
),
menu(
"Shell",
vec![
MenuItem::action("New Session", NewSession),
MenuItem::action("Close Session", CloseSession),
],
),
menu(
"Edit",
vec![
MenuItem::os_action("Copy", Copy, OsAction::Copy),
MenuItem::os_action("Paste", Paste, OsAction::Paste),
MenuItem::os_action("Select All", SelectAll, OsAction::SelectAll),
MenuItem::separator(),
MenuItem::action("Find", Find),
],
),
menu(
"View",
vec![
MenuItem::action("Toggle Sessions", ToggleSessions),
MenuItem::action("Toggle Right Panel", TogglePanel),
MenuItem::separator(),
MenuItem::action("Bigger", Bigger),
MenuItem::action("Smaller", Smaller),
MenuItem::action("Reset Size", ResetSize),
],
),
// macOS lists the open windows here itself.
menu(
"Window",
vec![
MenuItem::action("Minimize", Minimize),
MenuItem::action("Zoom", Zoom),
],
),
]
}
/// Ghostty's keys for Quit and the font's size, Cmd on macOS and Ctrl elsewhere, Cmd-M to minimize; what they do; then the menus, which show the keys bound by now.
pub fn init(cx: &mut App) {
let (quit, modifier) = if cfg!(target_os = "macos") {
("cmd-q", "cmd")
} else {
("ctrl-shift-q", "ctrl")
};
cx.bind_keys([
KeyBinding::new(quit, Quit, None),
KeyBinding::new(&format!("{modifier}-="), Bigger, None),
KeyBinding::new(&format!("{modifier}-+"), Bigger, None),
KeyBinding::new(&format!("{modifier}--"), Smaller, None),
KeyBinding::new(&format!("{modifier}-0"), ResetSize, None),
]);
if cfg!(target_os = "macos") {
cx.bind_keys([KeyBinding::new("cmd-m", Minimize, None)]);
}
cx.set_global(zoom::Enlarged::default());
cx.on_action(|_: &Quit, cx| {
log::info!("app: quit asked");
cx.quit();
});
cx.on_action(|_: &Bigger, cx| zoom::step(Some(1.0), cx));
cx.on_action(|_: &Smaller, cx| zoom::step(Some(-1.0), cx));
cx.on_action(|_: &ResetSize, cx| zoom::step(None, cx));
cx.set_menus(menus());
}
/// Minimize and Zoom on a window's root: only a window answers them.
pub fn window_actions<E: InteractiveElement>(root: E) -> E {
root.on_action(|_: &Minimize, window, _| {
log::info!("window: minimized");
window.minimize_window();
})
.on_action(|_: &Zoom, window, _| {
log::info!("window: zoomed");
window.zoom_window();
})
}