Skip to content

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.

feat(gui): keep pane renames in the mux

RoversX1358f94cc259
diff --git a/wezterm-gui/src/frontend.rs b/wezterm-gui/src/frontend.rs
index e8285106..558c4cb3 100644
--- a/wezterm-gui/src/frontend.rs
+++ b/wezterm-gui/src/frontend.rs
@@ -310,7 +310,9 @@ impl GuiFrontEnd {
.detach();
}
MuxNotification::TabTitleChanged { .. } => {}
+ MuxNotification::PaneLabelChanged { .. } => {}
MuxNotification::WindowTitleChanged { .. } => {}
+ MuxNotification::ClientJoined(_) | MuxNotification::ClientLeft(_) => {}
MuxNotification::TabResized(_) => {}
// Server-side only: a GUI mux owns no ThinkTerm tree. The
// remote tree arrives as a pushed PDU, not as a notification.
@@ -1246,6 +1248,10 @@ pub fn try_new() -> Result<Rc<GuiFrontEnd>, Error> {
let front_end = GuiFrontEnd::try_new()?;
FRONT_END.with(|f| *f.borrow_mut() = Some(Rc::clone(&front_end)));
crate::notification_click::install();
+ // The CLI asks the desktop's own mux which thread a workspace is.
+ wezterm_mux_server_impl::thinkterm_tree::set_workspace_namer(
+ crate::workspace_threads::project_and_thread_names_for_workspace,
+ );
#[cfg(target_os = "macos")]
::window::os::macos::set_dock_menu_items(dock_menu_spaces);
diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rs
index 36784071..b46ebb4d 100644
--- a/wezterm-gui/src/termwindow/mod.rs
+++ b/wezterm-gui/src/termwindow/mod.rs
@@ -1873,14 +1873,20 @@ enum InlineTabRenameTarget {
struct InlineTabRename {
target: InlineTabRenameTarget,
input: TextInputState,
+ /// The text the editor opened with.
+ initial: String,
}
impl InlineTabRename {
fn new(target: InlineTabRenameTarget, text: String) -> Self {
let mut input = TextInputState::new();
- input.set_text_end(text);
+ input.set_text_end(text.clone());
input.caret_select_all();
- Self { target, input }
+ Self {
+ target,
+ input,
+ initial: text,
+ }
}
/// Legacy tab surfaces still paint their inline editor as title text. File
@@ -2867,7 +2873,6 @@ pub struct TermWindow {
tab_wheel_surface_lock: Option<(TabWheelSurface, Instant)>,
tab_wheel_direction_lock: Option<(TabWheelSurface, i16, Instant)>,
inline_tab_rename: Option<InlineTabRename>,
- pane_tab_title_overrides: HashMap<PaneId, String>,
pub right_status: String,
pub left_status: String,
last_ui_item: Option<UIItem>,
@@ -4656,7 +4661,6 @@ impl TermWindow {
tab_wheel_surface_lock: None,
tab_wheel_direction_lock: None,
inline_tab_rename: None,
- pane_tab_title_overrides: HashMap::new(),
right_status: String::new(),
left_status: String::new(),
last_mouse_coords: (0, -1),
@@ -6076,6 +6080,10 @@ impl TermWindow {
MuxNotification::TabTitleChanged { .. } => {
self.update_title_post_status();
}
+ MuxNotification::PaneLabelChanged { .. } => {
+ self.update_title_post_status();
+ self.persist_workspace_layout_after_mutation("pane label changed");
+ }
MuxNotification::PaneAdded(pane_id) => {
self.push_window_config_to_pane(pane_id);
self.refresh_thread_work_for_pane(pane_id);
@@ -6116,6 +6124,8 @@ impl TermWindow {
}
self.sync_current_workspace_thread();
}
+ // Filtered out before they get here; for event subscribers.
+ MuxNotification::ClientJoined(_) | MuxNotification::ClientLeft(_) => {}
MuxNotification::Empty => {}
},
TermWindowNotif::EmitStatusUpdate => {
@@ -6778,6 +6788,15 @@ impl TermWindow {
return true;
}
}
+ MuxNotification::PaneLabelChanged { pane_id, .. } => {
+ let mux = Mux::get();
+ match mux.resolve_pane_id(pane_id) {
+ Some((_domain_id, window_id, _tab_id)) if window_id == mux_window_id => {
+ // fall through
+ }
+ _ => return true,
+ }
+ }
MuxNotification::FrontendLeaseChanged(ref state) => {
let mux = Mux::get();
if mux.window_containing_tab(state.tab_id) == Some(mux_window_id) {
@@ -6804,6 +6823,8 @@ impl TermWindow {
| MuxNotification::ThinkTermTreeChanged
| MuxNotification::DefaultPaletteChanged
| MuxNotification::ThinkTermSessionChanged
+ | MuxNotification::ClientJoined(_)
+ | MuxNotification::ClientLeft(_)
| MuxNotification::WindowWorkspaceChanged(_) => return true,
MuxNotification::Alert {
alert: Alert::PaletteChanged { .. },
@@ -9491,13 +9512,11 @@ impl TermWindow {
}
fn prompt_rename_pane_tab(&mut self, pane_id: PaneId) {
- let initial_title = self
- .pane_tab_title_overrides
- .get(&pane_id)
- .cloned()
+ let mux = Mux::get();
+ let initial_title = mux
+ .pane_label(pane_id)
.or_else(|| {
- Mux::get()
- .get_pane(pane_id)
+ mux.get_pane(pane_id)
.map(|pane| ui::terminal_title_for_display(&pane.get_title()).to_string())
})
.unwrap_or_default();
@@ -9693,10 +9712,15 @@ impl TermWindow {
}
}
InlineTabRenameTarget::PaneTab(pane_id) => {
- if title.is_empty() {
- self.pane_tab_title_overrides.remove(&pane_id);
- } else {
- self.pane_tab_title_overrides.insert(pane_id, title);
+ // The pane's label: kept by the mux that owns the pane,
+ // so the CLI and other windows know the pane by it. An
+ // unlabelled pane's editor opens on its title; left as
+ // it was, the pane goes on following its title.
+ let mux = Mux::get();
+ let untouched =
+ mux.pane_label(pane_id).is_none() && title == rename.initial.trim();
+ if !untouched {
+ mux.set_pane_label(pane_id, Some(&title));
}
}
InlineTabRenameTarget::Space(space_id) => {
@@ -9920,9 +9944,8 @@ impl TermWindow {
return title;
}
- self.pane_tab_title_overrides
- .get(&pane_id)
- .cloned()
+ Mux::get()
+ .pane_label(pane_id)
.unwrap_or_else(|| ui::terminal_title_for_display(title).to_string())
}
diff --git a/wezterm-gui/src/workspace_threads.rs b/wezterm-gui/src/workspace_threads.rs
index 42449809..268010f9 100644
--- a/wezterm-gui/src/workspace_threads.rs
+++ b/wezterm-gui/src/workspace_threads.rs
@@ -245,6 +245,9 @@ pub struct TerminalSpawnSpec {
pub cwd: Option<String>,
pub domain: Option<String>,
pub title: String,
+ /// The label the pane was given; the pane that replaces it gets it.
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub label: Option<String>,
}
#[derive(Debug, Clone)]
@@ -1443,6 +1446,7 @@ fn store_with_session_import(
cwd: working_dir_from_entry(entry),
domain: Some("local".into()),
title: entry.title.clone(),
+ label: None,
},
font_scale: None,
})
@@ -2190,6 +2194,14 @@ pub fn thread_display_name_for_workspace(workspace: &str) -> Option<String> {
Some(project_thread_name(project, thread))
}
+/// The project and thread names behind a thread-backed workspace, for the
+/// names the CLI knows panes by. `None` for workspaces no thread claims.
+pub fn project_and_thread_names_for_workspace(workspace: &str) -> Option<(String, String)> {
+ let store = THREAD_STORE.lock();
+ let (project, thread) = project_and_thread_for_workspace(&store, workspace)?;
+ Some((project.name.clone(), thread.name.clone()))
+}
+
fn project_thread_name(project: &Project, thread: &WorkspaceThread) -> String {
if project.name.is_empty() || project.name == thread.name {
thread.name.clone()
@@ -9068,7 +9080,8 @@ fn restore_node<'a>(
) -> LocalBoxFuture<'a, Result<()>> {
Box::pin(async move {
match node {
- PaneNode::Empty | PaneNode::Leaf(_) => {}
+ PaneNode::Empty => {}
+ PaneNode::Leaf(entry) => restore_label(&mux, base_pane_id, entry, terminal_specs),
PaneNode::Stack(stack) => {
restore_stack(
mux,
@@ -9160,12 +9173,30 @@ async fn restore_stack(
pane_ids.push(pane.pane_id());
}
+ for (pane_id, entry) in pane_ids.iter().zip(&stack.panes) {
+ restore_label(&mux, *pane_id, entry, terminal_specs);
+ }
if let Some(pane_id) = pane_ids.get(stack.active).copied() {
let _ = mux.activate_pane_in_stack(pane_id);
}
Ok(())
}
+/// Give `pane_id` the label the pane it stands in for had.
+fn restore_label(
+ mux: &Mux,
+ pane_id: PaneId,
+ entry: &PaneEntry,
+ terminal_specs: &HashMap<PaneId, TerminalSpawnSpec>,
+) {
+ if let Some(label) = terminal_specs
+ .get(&entry.pane_id)
+ .and_then(|spec| spec.label.as_deref())
+ {
+ mux.set_pane_label(pane_id, Some(label));
+ }
+}
+
fn split_second_percent(
direction: SplitDirection,
first: TerminalSize,
@@ -9266,6 +9297,7 @@ fn collect_terminal_spec<F>(
cwd: working_dir_from_entry(entry),
domain,
title: entry.title.clone(),
+ label: mux.pane_label(entry.pane_id),
},
font_scale: valid_font_scale(pane_font_scale(entry.pane_id)),
});