A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.
Rust agentagent-orchestrationaiai-agentsclaude-codecodexcoding-agentlinuxmacosmultiplayermultiplexerrustterminalterminal-emulatorterminal-multiplexertmuxtuiweztermwindows
Refine workspace menus and macOS deployment
RoversXe83ef1ebfa72
diff --git a/.github/workflows/gen_macos.yml b/.github/workflows/gen_macos.ymlindex 373923f0..5a553593 100644--- a/.github/workflows/gen_macos.yml+++ b/.github/workflows/gen_macos.yml@@ -31,7 +31,7 @@ jobs:CARGO_INCREMENTAL: "0"SCCACHE_GHA_ENABLED: "true"RUSTC_WRAPPER: "sccache"- MACOSX_DEPLOYMENT_TARGET: "10.12"+ MACOSX_DEPLOYMENT_TARGET: "14.0"steps:- name: "checkout repo"diff --git a/.github/workflows/gen_macos_continuous.yml b/.github/workflows/gen_macos_continuous.ymlindex 8c6c870a..7563b399 100644--- a/.github/workflows/gen_macos_continuous.yml+++ b/.github/workflows/gen_macos_continuous.yml@@ -34,7 +34,7 @@ jobs:CARGO_INCREMENTAL: "0"SCCACHE_GHA_ENABLED: "true"RUSTC_WRAPPER: "sccache"- MACOSX_DEPLOYMENT_TARGET: "10.12"+ MACOSX_DEPLOYMENT_TARGET: "14.0"steps:- name: "checkout repo"diff --git a/.github/workflows/gen_macos_tag.yml b/.github/workflows/gen_macos_tag.ymlindex 76d275a0..9e9fc908 100644--- a/.github/workflows/gen_macos_tag.yml+++ b/.github/workflows/gen_macos_tag.yml@@ -18,7 +18,7 @@ jobs:CARGO_INCREMENTAL: "0"SCCACHE_GHA_ENABLED: "true"RUSTC_WRAPPER: "sccache"- MACOSX_DEPLOYMENT_TARGET: "10.12"+ MACOSX_DEPLOYMENT_TARGET: "14.0"steps:- name: "checkout repo"diff --git a/.gitignore b/.gitignoreindex 5d336f1b..6d245d8c 100644--- a/.gitignore+++ b/.gitignore@@ -67,7 +67,7 @@ dhat-heap.json__pycache__/*.py[cod]/nix/result-/research+/research//docs/ThinkTerm-macos-v0.1.0.zip*.mddiff --git a/assets/macos/ThinkTerm.app/Contents/Info.plist b/assets/macos/ThinkTerm.app/Contents/Info.plistindex 91820b80..3ce441a3 100644--- a/assets/macos/ThinkTerm.app/Contents/Info.plist+++ b/assets/macos/ThinkTerm.app/Contents/Info.plist@@ -26,6 +26,8 @@<string>ThinkTerm_simple.icns</string><key>LSApplicationCategoryType</key><string>public.app-category.utilities</string>+ <key>LSMinimumSystemVersion</key>+ <string>14.0</string><key>NSHighResolutionCapable</key><true/><key>NSMainNibFile</key>diff --git a/ci/generate-workflows.py b/ci/generate-workflows.pyindex 710028c7..18153c64 100755--- a/ci/generate-workflows.py+++ b/ci/generate-workflows.py@@ -742,7 +742,7 @@ rustup default {toolchain}self.env["SCCACHE_GHA_ENABLED"] = "true"self.env["RUSTC_WRAPPER"] = "sccache"if "macos" in self.name:- self.env["MACOSX_DEPLOYMENT_TARGET"] = "10.12"+ self.env["MACOSX_DEPLOYMENT_TARGET"] = "14.0"if "alpine" in self.name:self.env["RUSTFLAGS"] = "-C target-feature=-crt-static"if "win" in self.name:diff --git a/deps/freetype/build.rs b/deps/freetype/build.rsindex 356ce032..a95915d5 100644--- a/deps/freetype/build.rs+++ b/deps/freetype/build.rs@@ -243,5 +243,5 @@ fn main() {freetype();let out_dir = env::var("OUT_DIR").unwrap();println!("cargo:outdir={}", out_dir);- println!("cargo:rustc-env=MACOSX_DEPLOYMENT_TARGET=10.12");+ println!("cargo:rustc-env=MACOSX_DEPLOYMENT_TARGET=14.0");}diff --git a/deps/harfbuzz/build.rs b/deps/harfbuzz/build.rsindex 5e6aae78..02a7698e 100644--- a/deps/harfbuzz/build.rs+++ b/deps/harfbuzz/build.rs@@ -68,5 +68,5 @@ fn main() {harfbuzz();let out_dir = env::var("OUT_DIR").unwrap();println!("cargo:outdir={}", out_dir);- println!("cargo:rustc-env=MACOSX_DEPLOYMENT_TARGET=10.12");+ println!("cargo:rustc-env=MACOSX_DEPLOYMENT_TARGET=14.0");}diff --git a/docs/install/macos.md b/docs/install/macos.mdindex 526a1f35..adfe8903 100644--- a/docs/install/macos.md+++ b/docs/install/macos.md@@ -1,11 +1,11 @@## Installing on macOS-The CI system builds the package on macOS Big Sur and should run on systems as-"old" as Mojave. It may run on earlier versions of macOS, but that has not-been tested.+macOS 14 (Sonoma) or later is required. The app bundle declares that minimum,+so earlier systems refuse to launch it rather than failing later in a way that+is harder to diagnose.-Starting with version 20210203-095643-70a364eb, WezTerm is a Universal binary-with support for both Apple Silicon and Intel hardware.+The package is a Universal binary with support for both Apple Silicon and Intel+hardware.[:simple-apple: Download for macOS :material-tray-arrow-down:]({{ macos_zip_stable }}){ .md-button }[:simple-apple: Nightly for macOS :material-tray-arrow-down:]({{ macos_zip_nightly }}){ .md-button }diff --git a/wezterm-gui/i18n/en-US.ftl b/wezterm-gui/i18n/en-US.ftlindex 3ba65f14..d421e5b8 100644--- a/wezterm-gui/i18n/en-US.ftl+++ b/wezterm-gui/i18n/en-US.ftl@@ -153,9 +153,11 @@ menu-rename-space = Rename Space…menu-rename-named-space = Rename “{ $name }”…menu-disconnect-space = Disconnect “{ $name }” (Server Keeps Running)menu-delete-space = Delete “{ $name }”-menu-delete-space-everywhere = Delete “{ $name }” on the Server (All Devices)-menu-delete-space-and-sessions = Delete “{ $name }” & End Remote Sessions-menu-delete-other-space = Delete Other Space+menu-remove-named-space = Remove “{ $name }”+menu-space-disconnect-short = Disconnect (Server Keeps Running)+menu-space-delete-everywhere-short = Delete on the Server (All Devices)+menu-space-delete-and-sessions-short = Delete & End Remote Sessions+menu-remove-other-space = Remove Other Spacemenu-status-running = Runningmenu-status-attention = Needs Attentionmenu-status-done = Donediff --git a/wezterm-gui/i18n/fr-FR.ftl b/wezterm-gui/i18n/fr-FR.ftlindex e77a825a..4a1ff820 100644--- a/wezterm-gui/i18n/fr-FR.ftl+++ b/wezterm-gui/i18n/fr-FR.ftl@@ -153,9 +153,11 @@ menu-rename-space = Renommer l’espace…menu-rename-named-space = Renommer « { $name } »…menu-disconnect-space = Déconnecter « { $name } » (le serveur reste actif)menu-delete-space = Supprimer « { $name } »-menu-delete-space-everywhere = Supprimer « { $name } » sur le serveur (tous les appareils)-menu-delete-space-and-sessions = Supprimer « { $name } » et terminer les sessions distantes-menu-delete-other-space = Supprimer un autre espace+menu-remove-named-space = Retirer « { $name } »+menu-space-disconnect-short = Déconnecter (le serveur reste actif)+menu-space-delete-everywhere-short = Supprimer sur le serveur (tous les appareils)+menu-space-delete-and-sessions-short = Supprimer et terminer les sessions distantes+menu-remove-other-space = Retirer un autre espacemenu-status-running = En coursmenu-status-attention = Attention requisemenu-status-done = Terminédiff --git a/wezterm-gui/i18n/ja-JP.ftl b/wezterm-gui/i18n/ja-JP.ftlindex 549e5ed0..45d8cf19 100644--- a/wezterm-gui/i18n/ja-JP.ftl+++ b/wezterm-gui/i18n/ja-JP.ftl@@ -153,9 +153,11 @@ menu-rename-space = スペース名を変更…menu-rename-named-space = 「{ $name }」の名前を変更…menu-disconnect-space = 「{ $name }」を切断(サーバーは実行を継続)menu-delete-space = 「{ $name }」を削除-menu-delete-space-everywhere = サーバー上の「{ $name }」を削除(全デバイス)-menu-delete-space-and-sessions = 「{ $name }」を削除してリモートセッションを終了-menu-delete-other-space = 別のスペースを削除+menu-remove-named-space = 「{ $name }」を削除/切断+menu-space-disconnect-short = 切断(サーバーは実行を継続)+menu-space-delete-everywhere-short = サーバー上で削除(全デバイス)+menu-space-delete-and-sessions-short = 削除してリモートセッションを終了+menu-remove-other-space = 別のスペースを削除/切断menu-status-running = 実行中menu-status-attention = 要確認menu-status-done = 完了diff --git a/wezterm-gui/i18n/zh-CN.ftl b/wezterm-gui/i18n/zh-CN.ftlindex fc7c4413..1ce08c9a 100644--- a/wezterm-gui/i18n/zh-CN.ftl+++ b/wezterm-gui/i18n/zh-CN.ftl@@ -153,9 +153,11 @@ menu-rename-space = 重命名空间…menu-rename-named-space = 重命名“{ $name }”…menu-disconnect-space = 断开“{ $name }”(服务器继续运行)menu-delete-space = 删除“{ $name }”-menu-delete-space-everywhere = 在服务器上删除“{ $name }”(所有设备)-menu-delete-space-and-sessions = 删除“{ $name }”并结束远程会话-menu-delete-other-space = 删除其他空间+menu-remove-named-space = 移除“{ $name }”+menu-space-disconnect-short = 断开连接(服务器继续运行)+menu-space-delete-everywhere-short = 在服务器上删除(所有设备)+menu-space-delete-and-sessions-short = 删除并结束远程会话+menu-remove-other-space = 移除其他空间menu-status-running = 运行中menu-status-attention = 需要关注menu-status-done = 已完成diff --git a/wezterm-gui/src/termwindow/mouseevent.rs b/wezterm-gui/src/termwindow/mouseevent.rsindex 136211a2..e089781c 100644--- a/wezterm-gui/src/termwindow/mouseevent.rs+++ b/wezterm-gui/src/termwindow/mouseevent.rs@@ -51,6 +51,56 @@ fn tr_with_name(id: &'static str, name: &str) -> String {crate::i18n::tr_args(id, &args)}+/// The entries that get rid of the active Space.+///+/// A remote Space has up to three of them and each one wants the Space named to+/// be unambiguous, which made the menu four lines of the same name. They fold+/// into one submenu instead: the name is said once, on the parent, and the+/// children say only what they do. A local Space has a single action, so it+/// stays flat — a submenu holding one item is just an extra click.+fn space_destructive_menu_items(+ space: &crate::workspace_threads::SpaceView,+ offer_remote_kill: bool,+) -> Vec<ContextMenuItem> {+ if !space.is_remote {+ return vec![ContextMenuItem::item_with_icon(+ tr_with_name("menu-delete-space", &space.name),+ ContextMenuIcon::Delete,+ KeyAssignment::DeleteSpace(space.id.clone()),+ )];+ }++ // A remote Space lives on its server, so removing it here only drops this+ // device's copy: the Space is untouched for everyone else and returns on+ // the next connect. Deleting it for real is a separate, more-consequential+ // entry offered alongside.+ let mut children = vec![+ ContextMenuItem::item_with_icon(+ crate::i18n::tr("menu-space-disconnect-short"),+ ContextMenuIcon::Unplug,+ KeyAssignment::DeleteSpace(space.id.clone()),+ ),+ ContextMenuItem::item_with_icon(+ crate::i18n::tr("menu-space-delete-everywhere-short"),+ ContextMenuIcon::Delete,+ KeyAssignment::DeleteSpaceEverywhere(space.id.clone()),+ ),+ ];+ if offer_remote_kill {+ children.push(ContextMenuItem::item_with_icon(+ crate::i18n::tr("menu-space-delete-and-sessions-short"),+ ContextMenuIcon::Delete,+ KeyAssignment::DeleteSpaceAndRemoteSessions(space.id.clone()),+ ));+ }++ vec![ContextMenuItem::submenu_with_icon(+ tr_with_name("menu-remove-named-space", &space.name),+ ContextMenuIcon::Delete,+ children,+ )]+}+fn note_drag_scroll_delta(pointer_y: f32,top: f32,@@ -4484,15 +4534,11 @@ impl super::TermWindow {tr_with_name("menu-space-server-group-offline", domain)}};- // Disabled: a server is a heading, not something to switch to.- items.push(- ContextMenuItem::item_with_icon(- header,- ContextMenuIcon::Server,- KeyAssignment::Nop,- )- .disabled(),- );+ // A server is a heading, not something to switch to. Saying that+ // with a section header rather than a disabled row is what makes it+ // *look* like a heading: the platform styles it as a caption and+ // never highlights it under the pointer.+ items.push(ContextMenuItem::section_header(header));for space in spaces.iter().filter(|space| space.domain.as_deref() == Some(domain))@@ -4525,10 +4571,9 @@ impl super::TermWindow {.iter().find(|space| space.is_active).map(|space| space.id.clone());- // A remote Space lives on its server, so removing it here only drops- // this device's copy: the Space is untouched for everyone else and- // returns on the next connect. Deleting it for real is a separate,- // more-consequential entry offered alongside.+ // For a Space other than the active one there is only ever the one+ // action, so it is named in full here; the active Space's several+ // actions are grouped by `space_destructive_menu_items` instead.let delete_item = |space: crate::workspace_threads::SpaceView| {ContextMenuItem::item_with_icon(if space.is_remote {@@ -4536,7 +4581,11 @@ impl super::TermWindow {} else {tr_with_name("menu-delete-space", &space.name)},- ContextMenuIcon::Delete,+ if space.is_remote {+ ContextMenuIcon::Unplug+ } else {+ ContextMenuIcon::Delete+ },KeyAssignment::DeleteSpace(space.id),)};@@ -4550,31 +4599,15 @@ impl super::TermWindow {.find(|space| active_space_id.as_deref() == Some(space.id.as_str())).cloned();if let Some(space) = active_delete {- let is_remote = space.is_remote;// Ending the sessions too only makes sense while we are actually// connected to the server.- let offer_remote_kill = is_remote+ let offer_remote_kill = space.is_remote&& crate::workspace_threads::client_domain_for_space(&space.id).and_then(|name| Mux::get().get_domain_by_name(&name)).map_or(false, |domain| {domain.state() == mux::domain::DomainState::Attached});- let (name, id) = (space.name.clone(), space.id.clone());- items.push(delete_item(space));- if is_remote {- items.push(ContextMenuItem::item_with_icon(- tr_with_name("menu-delete-space-everywhere", &name),- ContextMenuIcon::Delete,- KeyAssignment::DeleteSpaceEverywhere(id.clone()),- ));- }- if offer_remote_kill {- items.push(ContextMenuItem::item_with_icon(- tr_with_name("menu-delete-space-and-sessions", &name),- ContextMenuIcon::Delete,- KeyAssignment::DeleteSpaceAndRemoteSessions(id),- ));- }+ items.extend(space_destructive_menu_items(&space, offer_remote_kill));}let other_delete_candidates = delete_candidates@@ -4584,7 +4617,7 @@ impl super::TermWindow {.collect::<Vec<_>>();if !other_delete_candidates.is_empty() {items.push(ContextMenuItem::submenu_with_icon(- crate::i18n::tr("menu-delete-other-space"),+ crate::i18n::tr("menu-remove-other-space"),ContextMenuIcon::Delete,other_delete_candidates,));@@ -4636,12 +4669,9 @@ impl super::TermWindow {}vec![- ContextMenuItem::item_with_icon(- crate::i18n::tr("menu-group-by"),- ContextMenuIcon::Stack,- KeyAssignment::Nop,- )- .disabled(),+ ContextMenuItem::section_header(crate::i18n::tr("menu-group-by")),+ // Not a heading: it is the one grouping mode there is, shown ticked+ // and unclickable because there is nothing to switch it to.ContextMenuItem::item_with_icon(crate::i18n::tr("menu-workspace"),ContextMenuIcon::Folder,@@ -4650,12 +4680,7 @@ impl super::TermWindow {.checked(true).disabled(),ContextMenuItem::Separator,- ContextMenuItem::item_with_icon(- crate::i18n::tr("menu-show"),- ContextMenuIcon::Info,- KeyAssignment::Nop,- )- .disabled(),+ ContextMenuItem::section_header(crate::i18n::tr("menu-show")),ContextMenuItem::submenu_with_icon(crate::i18n::tr("menu-status"),ContextMenuIcon::Check,@@ -7314,3 +7339,90 @@ mod sidebar_drag_tests {assert_eq!(sidebar_insert_position(&[], 10), None);}}++#[cfg(test)]+mod space_menu_tests {+ use super::space_destructive_menu_items;+ use crate::workspace_threads::SpaceView;+ use config::keyassignment::KeyAssignment;+ use window::ContextMenuAction;+ use window::ContextMenuItem;++ fn space(is_remote: bool) -> SpaceView {+ SpaceView {+ id: "s1".to_string(),+ name: "Remote 2".to_string(),+ is_active: true,+ is_default: false,+ is_occupied_by_other_window: false,+ is_remote,+ domain: is_remote.then(|| "DO SYD X user".to_string()),+ }+ }++ /// The submenu's shape is the contract; the labels come from whichever+ /// locale happens to be active, so asserting on them would be asserting on+ /// the test machine's settings.+ fn actions(items: &[ContextMenuItem]) -> Vec<KeyAssignment> {+ items+ .iter()+ .map(|item| match item {+ ContextMenuItem::Item {+ action: ContextMenuAction::KeyAssignment(action),+ ..+ } => action.clone(),+ other => panic!("expected a key assignment item, got {:?}", other),+ })+ .collect()+ }++ fn submenu_of(item: &ContextMenuItem) -> &[ContextMenuItem] {+ match item {+ ContextMenuItem::Item { submenu, .. } => submenu,+ other => panic!("expected an item, got {:?}", other),+ }+ }++ /// One action does not deserve a submenu: a local Space keeps the single+ /// named row it has always had.+ #[test]+ fn a_local_space_stays_flat() {+ let items = space_destructive_menu_items(&space(false), false);+ assert_eq!(items.len(), 1);+ assert!(submenu_of(&items[0]).is_empty());+ assert_eq!(+ actions(&items),+ vec![KeyAssignment::DeleteSpace("s1".to_string())]+ );+ }++ /// The four lines that prompted this: one parent row carrying the name,+ /// with the actions underneath.+ #[test]+ fn a_remote_space_folds_its_actions_into_one_submenu() {+ let items = space_destructive_menu_items(&space(true), true);+ assert_eq!(items.len(), 1);+ assert_eq!(+ actions(submenu_of(&items[0])),+ vec![+ KeyAssignment::DeleteSpace("s1".to_string()),+ KeyAssignment::DeleteSpaceEverywhere("s1".to_string()),+ KeyAssignment::DeleteSpaceAndRemoteSessions("s1".to_string()),+ ]+ );+ }++ /// Ending the remote sessions needs a live connection to end them over, so+ /// a detached domain offers only the two that work offline.+ #[test]+ fn a_detached_remote_space_omits_the_session_kill() {+ let items = space_destructive_menu_items(&space(true), false);+ assert_eq!(+ actions(submenu_of(&items[0])),+ vec![+ KeyAssignment::DeleteSpace("s1".to_string()),+ KeyAssignment::DeleteSpaceEverywhere("s1".to_string()),+ ]+ );+ }+}diff --git a/wezterm-gui/src/termwindow/ui/context_menu.rs b/wezterm-gui/src/termwindow/ui/context_menu.rsindex 4381d5aa..44120fdc 100644--- a/wezterm-gui/src/termwindow/ui/context_menu.rs+++ b/wezterm-gui/src/termwindow/ui/context_menu.rs@@ -73,6 +73,9 @@ enum MenuRow<'a> {index: usize,item: &'a ContextMenuItem,},+ SectionHeader {+ label: &'a str,+ },Separator,}@@ -575,6 +578,10 @@ fn render_rows(items: &[ContextMenuItem]) -> Vec<MenuRow<'_>> {rows.push(MenuRow::Item { index, item });last_was_separator = false;}+ ContextMenuItem::SectionHeader { label } => {+ rows.push(MenuRow::SectionHeader { label });+ last_was_separator = false;+ }ContextMenuItem::Separator => {if !last_was_separator {rows.push(MenuRow::Separator);@@ -584,7 +591,12 @@ fn render_rows(items: &[ContextMenuItem]) -> Vec<MenuRow<'_>> {}}- while matches!(rows.last(), Some(MenuRow::Separator)) {+ // A trailing separator or a header captioning nothing is noise; both can+ // appear once a caller filters the entries that were supposed to follow.+ while matches!(+ rows.last(),+ Some(MenuRow::Separator) | Some(MenuRow::SectionHeader { .. })+ ) {rows.pop();}@@ -610,13 +622,23 @@ fn compute_menu_metrics(}height = height.saturating_add(row_height);}+ // Headers share the item label column, so they measure the same way.+ MenuRow::SectionHeader { label } => {+ label_width =+ label_width.max(term.sidebar_text_width(font, label)?.ceil() as usize);+ height = height.saturating_add(row_height);+ }MenuRow::Separator => {height = height.saturating_add(term.ui_px(MENU_SEPARATOR_HEIGHT));}}}+ // Rows are laid out inside the border, not across it, so the width owed to+ // the widest label has to include the border it sits between; without this+ // that one label is the only one that ends up ellipsized.let ideal_width = term.ui_px(MENU_PADDING_X) * 2+ + (term.ui_f32(MENU_BORDER_WIDTH) as usize) * 2+ term.ui_px(MENU_CHECK_SLOT)+ term.ui_px(MENU_ICON_SLOT)+ term.ui_px(MENU_LABEL_GAP)@@ -741,6 +763,36 @@ fn paint_menu_rows()?;cursor_y += term.ui_px(MENU_SEPARATOR_HEIGHT);}+ // A caption, not a command: muted, never highlighted, and left out+ // of `ui_items`/`layout` so the mouse cannot land on it at all.+ MenuRow::SectionHeader { label } => {+ let label_x = x+ + term.ui_f32(MENU_BORDER_WIDTH) as usize+ + term.ui_px(MENU_PADDING_X)+ + term.ui_px(MENU_CHECK_SLOT)+ + term.ui_px(MENU_ICON_SLOT)+ + term.ui_px(MENU_LABEL_GAP);+ let text_y = cursor_y+ + (metrics+ .row_height+ .saturating_sub(font_metrics.cell_size.height as usize))+ / 2;+ let label_width = metrics+ .width+ .saturating_sub(label_x.saturating_sub(x))+ .saturating_sub(term.ui_px(MENU_PADDING_X));+ term.paint_sidebar_text(+ layers,+ font,+ font_metrics,+ label,+ label_x,+ text_y,+ label_width,+ palette.muted_text,+ )?;+ cursor_y += metrics.row_height;+ }MenuRow::Item { index, item } => {let mut path = menu_path.to_vec();path.push(*index);@@ -756,7 +808,7 @@ fn paint_menu_rows(ContextMenuItem::Item { submenu, .. } => {ContextMenuState::has_renderable_items(submenu)}- ContextMenuItem::Separator => false,+ ContextMenuItem::SectionHeader { .. } | ContextMenuItem::Separator => false,};let hovered = active_path.is_some_and(|active| {active == path.as_slice() || (has_submenu && active.starts_with(&path))@@ -958,7 +1010,70 @@ fn menu_icon(icon: &ContextMenuIcon) -> Option<SvgIcon> {ContextMenuIcon::Terminal => Some(SvgIcon::Terminal),ContextMenuIcon::Undo => Some(SvgIcon::RotateCcw),ContextMenuIcon::Unpin => Some(SvgIcon::PinOff),+ ContextMenuIcon::Unplug => Some(SvgIcon::Unplug),ContextMenuIcon::Vault => Some(SvgIcon::FolderTree),ContextMenuIcon::Warning => Some(SvgIcon::CircleAlert),}}++#[cfg(test)]+mod tests {+ use super::{render_rows, ContextMenuState, MenuRow};+ use config::keyassignment::KeyAssignment;+ use window::ContextMenuItem;++ fn item(label: &str) -> ContextMenuItem {+ ContextMenuItem::item(label, KeyAssignment::Nop)+ }++ fn shape(rows: &[MenuRow<'_>]) -> Vec<&'static str> {+ rows.iter()+ .map(|row| match row {+ MenuRow::Item { .. } => "item",+ MenuRow::SectionHeader { .. } => "header",+ MenuRow::Separator => "separator",+ })+ .collect()+ }++ /// A header captions the rows beneath it, so one with nothing beneath is+ /// left over from a caller that filtered them all away — drop it, the same+ /// way a trailing separator is dropped.+ #[test]+ fn a_header_with_nothing_under_it_is_dropped() {+ let items = vec![+ item("Space 6"),+ ContextMenuItem::Separator,+ ContextMenuItem::section_header("DO SYD X user"),+ ];+ assert_eq!(shape(&render_rows(&items)), vec!["item"]);+ }++ /// The real shape of the Space menu: a header is content, so the separator+ /// before it survives and the rows under it render normally.+ #[test]+ fn a_header_keeps_the_separator_that_introduces_it() {+ let items = vec![+ item("Space 6"),+ ContextMenuItem::Separator,+ ContextMenuItem::section_header("DO SYD X user"),+ item("Remote 2"),+ ];+ assert_eq!(+ shape(&render_rows(&items)),+ vec!["item", "separator", "header", "item"]+ );+ }++ /// Headers are not commands: a submenu holding only headers has nothing to+ /// activate, so it must not present itself as openable.+ #[test]+ fn headers_alone_do_not_make_a_menu_renderable() {+ let headers = vec![ContextMenuItem::section_header("Group by")];+ assert!(!ContextMenuState::has_renderable_items(&headers));+ assert!(ContextMenuState::has_renderable_items(&[+ ContextMenuItem::section_header("Group by"),+ item("Workspace"),+ ]));+ }+}diff --git a/wezterm-gui/src/termwindow/ui/icons.rs b/wezterm-gui/src/termwindow/ui/icons.rsindex c8de7f52..7c4c4dbd 100644--- a/wezterm-gui/src/termwindow/ui/icons.rs+++ b/wezterm-gui/src/termwindow/ui/icons.rs@@ -52,6 +52,7 @@ pub enum SvgIcon {Pin,PinOff,Plus,+ Unplug,RotateCcw,RotateCw,Save,@@ -175,6 +176,7 @@ impl SvgIcon {Self::Pencil => include_bytes!("../../../../third_party/lucide/icons/pencil.svg"),Self::Pin => include_bytes!("../../../../third_party/lucide/icons/pin.svg"),Self::PinOff => include_bytes!("../../../../third_party/lucide/icons/pin-off.svg"),+ Self::Unplug => include_bytes!("../../../../third_party/lucide/icons/unplug.svg"),Self::Plus => include_bytes!("../../../../third_party/lucide/icons/plus.svg"),Self::RotateCcw => {include_bytes!("../../../../third_party/lucide/icons/rotate-ccw.svg")@@ -538,6 +540,7 @@ mod tests {SvgIcon::Pin,SvgIcon::PinOff,SvgIcon::Plus,+ SvgIcon::Unplug,SvgIcon::RotateCcw,SvgIcon::RotateCw,SvgIcon::Search,diff --git a/window/src/lib.rs b/window/src/lib.rsindex 36217061..2b746b40 100644--- a/window/src/lib.rs+++ b/window/src/lib.rs@@ -196,6 +196,12 @@ pub enum ContextMenuItem {enabled: bool,submenu: Vec<ContextMenuItem>,},+ /// A caption naming the group of items that follows. Never selectable and+ /// never highlighted, so it cannot be mistaken for a command; macOS renders+ /// it with the system's own section-header style.+ SectionHeader {+ label: String,+ },Separator,}@@ -243,6 +249,7 @@ pub enum ContextMenuIcon {Terminal,Undo,Unpin,+ Unplug,Vault,Warning,Window,@@ -305,6 +312,9 @@ impl ContextMenuIcon {Self::Terminal => "terminal",Self::Undo => "arrow.uturn.backward",Self::Unpin => "pin.slash",+ // Only in recent SF Symbols releases; older systems fall through to+ // the bundled Lucide unplug glyph, which is the same picture.+ Self::Unplug => "powerplug.portrait.slash",Self::Warning => "exclamationmark.circle",Self::Window => "macwindow",}@@ -360,6 +370,7 @@ impl ContextMenuIcon {Self::Terminal => include_bytes!("../../third_party/lucide/icons/terminal.svg"),Self::Undo => include_bytes!("../../third_party/lucide/icons/undo.svg"),Self::Unpin => include_bytes!("../../third_party/lucide/icons/pin-off.svg"),+ Self::Unplug => include_bytes!("../../third_party/lucide/icons/unplug.svg"),Self::Vault => include_bytes!("../../third_party/lucide/icons/folder-tree.svg"),Self::Warning => include_bytes!("../../third_party/lucide/icons/circle-alert.svg"),Self::Window => include_bytes!("../../third_party/lucide/icons/panels-top-left.svg"),@@ -405,6 +416,12 @@ impl ContextMenuItem {}}+ pub fn section_header(label: impl Into<String>) -> Self {+ Self::SectionHeader {+ label: label.into(),+ }+ }+pub fn disabled(mut self) -> Self {if let Self::Item { enabled, .. } = &mut self {*enabled = false;diff --git a/window/src/os/macos/menu.rs b/window/src/os/macos/menu.rsindex d0d7c5b8..9e18cd13 100644--- a/window/src/os/macos/menu.rs+++ b/window/src/os/macos/menu.rs@@ -96,6 +96,18 @@ impl Menu {}}+ /// With automatic enabling left on (the AppKit default) an item is enabled+ /// whenever its target responds to its action, which silently overrides+ /// every `setEnabled: NO` we make. Context menus set their own enabled+ /// state, so they must turn it off; the main menu bar relies on the+ /// automatic validation and must not.+ pub fn set_autoenables_items(&self, enabled: bool) {+ unsafe {+ let enabled: BOOL = if enabled { YES } else { NO };+ let () = msg_send![*self.menu, setAutoenablesItems: enabled];+ }+ }+/// Tracks the menu and returns whether the user selected an item.pub fn pop_up_at(&self, view: id, x: f64, y: f64) -> bool {unsafe {@@ -231,6 +243,31 @@ impl MenuItem {Self { item }}+ /// The system's own section-header item: a caption that is never selectable+ /// and never highlights.+ ///+ /// `None` when the running AppKit has no such constructor. A selector name+ /// cannot be checked at compile time, and sending an unrecognized one is+ /// fatal, so the caller keeps a plain disabled item as the fallback — the+ /// same shape `set_system_symbol_image` uses for SF Symbols.+ pub fn new_section_header(title: &str) -> Option<Self> {+ unsafe {+ let cls = class!(NSMenuItem);+ let responds: BOOL = msg_send![cls, respondsToSelector: sel!(sectionHeaderWithTitle:)];+ if responds == NO {+ return None;+ }+ let item: id = msg_send![cls, sectionHeaderWithTitle: *nsstring(title)];+ if item.is_null() {+ return None;+ }+ // Autoreleased, so take our own reference.+ Some(Self {+ item: StrongPtr::retain(item),+ })+ }+ }+pub fn new_with(title: &str, action: Option<SEL>, key: &str) -> Self {unsafe {let item = NSMenuItem::alloc(nil);diff --git a/window/src/os/macos/window.rs b/window/src/os/macos/window.rsindex e355057f..b855cdf0 100644--- a/window/src/os/macos/window.rs+++ b/window/src/os/macos/window.rs@@ -1672,6 +1672,7 @@ impl WindowInner {menu_item.set_enabled(enabled);if has_submenu {let child_menu = Menu::new_with_title(&label);+ child_menu.set_autoenables_items(false);if add_context_menu_items(&child_menu, view, submenu) {menu_item.set_sub_menu(&child_menu);menu.add_item(&menu_item);@@ -1685,6 +1686,17 @@ impl WindowInner {has_items = true;}}+ ContextMenuItem::SectionHeader { label } => {+ // Falls back to a disabled item where the system has no+ // section-header constructor; with automatic enabling+ // off that still renders as grey, unhighlightable text.+ let menu_item = MenuItem::new_section_header(&label).unwrap_or_else(|| {+ let item = MenuItem::new_with(&label, None, "");+ item.set_enabled(false);+ item+ });+ menu.add_item(&menu_item);+ }ContextMenuItem::Separator => {if has_items {menu.add_item(&MenuItem::new_separator());@@ -1696,6 +1708,7 @@ impl WindowInner {}let menu = Menu::new_with_title("");+ menu.set_autoenables_items(false);let has_items = add_context_menu_items(&menu, *self.view, items);if !has_items {