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
feat(restore): keep pane output by default where the desktop runs
RoversX2c442cabf5e4
diff --git a/mux/src/kept_output.rs b/mux/src/kept_output.rsindex 83ac0f71..f614d70f 100644--- a/mux/src/kept_output.rs+++ b/mux/src/kept_output.rs@@ -1,6 +1,7 @@//! What a pane showed when the process holding it stopped, kept on disk//! until its Thread's layout is restored and then put back above the new-//! shell. Off unless Settings turns it on.+//! shell. On where the desktop runs unless Settings turns it off; off on a+//! remote host unless turned on there.//!//! Only a controlled exit keeps anything: a shutdown or logout, the session//! server being stopped, ThinkTerm quitting with its terminals inside it. A@@ -78,7 +79,8 @@ fn switch_path() -> PathBuf {}/// Whether this machine keeps pane output, read when it matters: at an exit-/// and at a restore.+/// and at a restore. Not until something turns it on: the desktop does on+/// its own machine (see `on_by_default`), a remote host only when told to.pub fn enabled() -> bool {enabled_at(&switch_path())}@@ -87,7 +89,9 @@ fn enabled_at(switch: &Path) -> bool {std::fs::read_to_string(switch).is_ok_and(|text| text.trim() == "on")}-/// Turn it on or off for this machine. Off removes what was kept, too.+/// Turn it on or off for this machine. Off removes what was kept, too, and+/// stays off: it is written down rather than the switch removed, which the+/// desktop would take for one never set.pub fn set_enabled(on: bool) -> anyhow::Result<()> {set_enabled_at(&switch_path(), on)?;if !on {@@ -97,20 +101,28 @@ pub fn set_enabled(on: bool) -> anyhow::Result<()> {}fn set_enabled_at(switch: &Path, on: bool) -> anyhow::Result<()> {- if on {- if let Some(dir) = switch.parent() {- std::fs::create_dir_all(dir)?;- }- let partial = switch.with_extension("partial");- std::fs::write(&partial, "on\n")?;- std::fs::rename(&partial, switch)?;- return Ok(());+ if let Some(dir) = switch.parent() {+ std::fs::create_dir_all(dir)?;}- match std::fs::remove_file(switch) {- Ok(()) => Ok(()),- Err(err) if err.kind() == std::io::ErrorKind::NotFound => Ok(()),- Err(err) => Err(err.into()),+ let partial = switch.with_extension("partial");+ std::fs::write(&partial, if on { "on\n" } else { "off\n" })?;+ std::fs::rename(&partial, switch)?;+ Ok(())+}++/// The desktop, as it starts: its own machine keeps pane output unless it+/// has been told either way.+pub fn on_by_default() {+ if let Err(err) = on_by_default_at(&switch_path()) {+ log::warn!("turning on kept pane output: {err:#}");+ }+}++fn on_by_default_at(switch: &Path) -> anyhow::Result<()> {+ if switch.try_exists()? {+ return Ok(());}+ set_enabled_at(switch, true)}fn root() -> PathBuf {diff --git a/mux/src/kept_output/tests.rs b/mux/src/kept_output/tests.rsindex 7c2f19c1..81218e63 100644--- a/mux/src/kept_output/tests.rs+++ b/mux/src/kept_output/tests.rs@@ -733,9 +733,21 @@ fn the_switch_is_a_file_that_says_on() {assert!(enabled_at(&switch));assert_eq!(std::fs::read_to_string(&switch).unwrap(), "on\n");set_enabled_at(&switch, false).unwrap();- assert!(!switch.exists());+ assert!(!enabled_at(&switch));+ assert_eq!(std::fs::read_to_string(&switch).unwrap(), "off\n");// Off twice is still off; anything but "on" is off.set_enabled_at(&switch, false).unwrap();std::fs::write(&switch, "yes").unwrap();assert!(!enabled_at(&switch));}++#[test]+fn the_desktop_turns_on_only_a_switch_never_set() {+ let dir = tempfile::tempdir().unwrap();+ let switch = dir.path().join("thinkterm").join("restore-pane-output");+ on_by_default_at(&switch).unwrap();+ assert!(enabled_at(&switch));+ set_enabled_at(&switch, false).unwrap();+ on_by_default_at(&switch).unwrap();+ assert!(!enabled_at(&switch));+}diff --git a/wezterm-gui/src/main.rs b/wezterm-gui/src/main.rsindex 53556681..22097bf7 100644--- a/wezterm-gui/src/main.rs+++ b/wezterm-gui/src/main.rs@@ -1479,6 +1479,8 @@ fn build_initial_mux(fn run_terminal_gui(opts: StartCommand, default_domain_name: Option<String>) -> anyhow::Result<()> {// Before anything reads the state: an import staged from Settings.crate::state_backup::enter_gui();+ // The desktop's own machine keeps pane output unless told not to.+ mux::kept_output::on_by_default();if let Some(cls) = opts.class.as_ref() {crate::set_window_class(cls);}diff --git a/wezterm/src/cli/restore_output.rs b/wezterm/src/cli/restore_output.rsindex f43b94e3..0ce602b1 100644--- a/wezterm/src/cli/restore_output.rs+++ b/wezterm/src/cli/restore_output.rs@@ -1,8 +1,8 @@//! `thinkterm cli restore-output …`: whether this machine keeps what its//! panes show when its terminals stop, and puts it back when their layout is//! restored. The desktop's Settings has the same switch for the machine it-//! runs on; on any other machine, a remote host say, this is how to turn it-//! on. See `mux::kept_output`.+//! runs on, where it is on unless turned off; on any other machine, a remote+//! host say, it is off until this turns it on. See `mux::kept_output`.use clap::Parser;