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.

trying to fix the space and width issue of the terminal with mux

RoversX4d8a8dd9f440
diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rs
index 8112baca..d23e1565 100644
--- a/wezterm-gui/src/termwindow/mod.rs
+++ b/wezterm-gui/src/termwindow/mod.rs
@@ -1346,8 +1346,17 @@ impl TermWindow {
let size = match mux.get_active_tab_for_window(mux_window_id) {
Some(tab) => tab.get_size(),
None => {
+ // Window created ahead of its content (e.g. the connect flow
+ // creates the window before the domain attach populates it).
+ // A zero Default here would open a degenerate one-row window
+ // and set off a resize tug-of-war; start at the configured
+ // initial size instead.
log::debug!("new_window has no tabs... yet?");
- Default::default()
+ let dpi = config.dpi.unwrap_or_else(|| ::window::default_dpi());
+ config.initial_size(
+ dpi as u32,
+ crate::cell_pixel_dims(&config, dpi as f64).ok(),
+ )
}
};
let physical_rows = size.rows as usize;
@@ -2245,10 +2254,24 @@ impl TermWindow {
}
TermWindowNotif::OpenProjectPath(path) => {
let path = path.to_string_lossy();
- match crate::workspace_threads::create_project_from_path(
+ // In a mux-domain Space the path names a directory on the
+ // remote server and must not be resolved locally.
+ let result = if crate::workspace_threads::client_domain_for_space(
&self.active_space_id,
- path.as_ref(),
- ) {
+ )
+ .is_some()
+ {
+ crate::workspace_threads::create_remote_project_from_path(
+ &self.active_space_id,
+ path.as_ref(),
+ )
+ } else {
+ crate::workspace_threads::create_project_from_path(
+ &self.active_space_id,
+ path.as_ref(),
+ )
+ };
+ match result {
Ok(thread_id) => self.activate_workspace_thread(thread_id, window),
Err(err) => log::error!("failed to create ThinkTerm project: {err:#}"),
}
@@ -3950,6 +3973,36 @@ impl TermWindow {
let Some(window) = self.window.as_ref().cloned() else {
return;
};
+
+ // In a mux-domain Space the project path lives on the remote server;
+ // a local folder picker is meaningless there, so prompt for the path
+ // as text instead.
+ if let Some(domain_name) =
+ crate::workspace_threads::client_domain_for_space(&self.active_space_id)
+ {
+ let mux = Mux::get();
+ let Some(tab) = mux.get_active_tab_for_window(self.mux_window_id) else {
+ return;
+ };
+ let description =
+ format!("Add a project on {domain_name}: enter a remote directory path");
+ let (overlay, future) = start_overlay(self, &tab, move |_tab_id, term| {
+ let line = crate::overlay::prompt::read_line_prompt_overlay(
+ term,
+ &description,
+ "path> ",
+ Some("~/"),
+ )?;
+ if let Some(path) = line.map(|s| s.trim().to_string()).filter(|s| !s.is_empty()) {
+ window.notify(TermWindowNotif::OpenProjectPath(PathBuf::from(path)));
+ }
+ Ok(())
+ });
+ self.assign_overlay(tab.tab_id(), overlay);
+ promise::spawn::spawn(future).detach();
+ return;
+ }
+
context.pick_folder_async(Box::new(move |path| {
if let Some(path) = path {
window.notify(TermWindowNotif::OpenProjectPath(path));
diff --git a/wezterm-gui/src/termwindow/mouseevent.rs b/wezterm-gui/src/termwindow/mouseevent.rs
index b3e98284..6a18f8a0 100644
--- a/wezterm-gui/src/termwindow/mouseevent.rs
+++ b/wezterm-gui/src/termwindow/mouseevent.rs
@@ -3358,21 +3358,23 @@ impl super::TermWindow {
return;
}
- // Mux-client-domain threads (`wezterm connect` Spaces) cannot be
- // materialized locally: their content lives on the remote mux server.
- // The live case was handled by the adopt branch above; when the
- // workspace isn't live, spawning a local shell here would fight the
- // remote's ownership, so refuse.
- if let Some(domain_name) =
- crate::workspace_threads::client_domain_name_for_project_id(&plan.project_id)
- {
- log::info!(
- "thread {:?} belongs to mux domain {domain_name:?}; \
- use `wezterm connect {domain_name}` to attach it",
- plan.thread_id
- );
- context.invalidate();
- return;
+ // In a mux-client-domain Space every thread targets the remote
+ // server: panes spawn into the client domain, never a local shell.
+ // That requires the domain to be attached first.
+ let space_client_domain =
+ crate::workspace_threads::client_domain_for_space(&self.active_space_id);
+ if let Some(domain_name) = space_client_domain.as_deref() {
+ let attached = mux.get_domain_by_name(domain_name).map_or(false, |d| {
+ d.state() == mux::domain::DomainState::Attached
+ });
+ if !attached {
+ log::info!(
+ "Space is bound to mux domain {domain_name:?} which is not connected; \
+ use `wezterm connect {domain_name}` first"
+ );
+ context.invalidate();
+ return;
+ }
}
let workspace_name = plan.workspace_name.clone();
@@ -3409,6 +3411,20 @@ impl super::TermWindow {
return;
}
}
+ } else if let Some(domain_name) = space_client_domain {
+ // Thread in a mux-domain Space: spawn on the remote server, with
+ // the project path (a remote directory) as the starting cwd. The
+ // domain's own "main" project carries a wezterm-mux:// sentinel
+ // path, which is not a cwd.
+ let cwd = plan
+ .project_path
+ .to_str()
+ .filter(|path| !path.starts_with("wezterm-mux://"))
+ .map(|path| path.to_string());
+ (
+ cwd,
+ config::keyassignment::SpawnTabDomain::DomainName(domain_name),
+ )
} else {
(
plan.project_path.to_str().map(|path| path.to_string()),
diff --git a/wezterm-gui/src/workspace_threads.rs b/wezterm-gui/src/workspace_threads.rs
index 1486c80d..e812f990 100644
--- a/wezterm-gui/src/workspace_threads.rs
+++ b/wezterm-gui/src/workspace_threads.rs
@@ -3298,8 +3298,32 @@ pub fn is_mux_domain_project_id(project_id: &str) -> bool {
remote_host_id_for_project_id(project_id).starts_with(MUX_DOMAIN_HOST_PREFIX)
}
-pub fn client_domain_name_for_project_id(project_id: &str) -> Option<&str> {
- remote_host_id_for_project_id(project_id).strip_prefix(MUX_DOMAIN_HOST_PREFIX)
+/// The mux client domain a Space is dedicated to, if any. Every thread in
+/// such a Space targets the remote server: new panes spawn into this domain
+/// and project paths refer to the remote filesystem.
+pub fn client_domain_for_space(space_id: &str) -> Option<String> {
+ let store = THREAD_STORE.lock();
+ store
+ .spaces
+ .iter()
+ .find(|space| space.id == space_id)
+ .and_then(|space| space.client_domain.clone())
+}
+
+/// Create a project in a mux-domain Space. The path names a directory on the
+/// remote server, so it must not be resolved or canonicalized locally.
+pub fn create_remote_project_from_path(space_id: &str, path: &str) -> Result<WorkspaceThreadId> {
+ let trimmed = path.trim();
+ ensure!(!trimmed.is_empty(), "project path is empty");
+ ensure!(
+ trimmed == "~" || trimmed.starts_with("~/") || trimmed.starts_with('/'),
+ "remote project path must be absolute or start with ~: {trimmed}"
+ );
+ let mut store = THREAD_STORE.lock();
+ store.normalize_after_load();
+ let thread_id = store.create_project_from_path(space_id, PathBuf::from(trimmed));
+ persist_locked(&store);
+ Ok(thread_id)
}
/// Everything `wezterm connect` needs to route a client-domain attach into