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.

wezterm-gui, cli: stop the session server on purpose

RoversXbd541b30ccef
diff --git a/config/src/keyassignment.rs b/config/src/keyassignment.rs
index 461872e3..b919c26f 100644
--- a/config/src/keyassignment.rs
+++ b/config/src/keyassignment.rs
@@ -637,6 +637,8 @@ pub enum KeyAssignment {
ResetTerminal,
OpenUri(String),
OpenSettings,
+ /// Quit, and stop the background session server with its terminals.
+ QuitAndStopSessionServer,
CheckForUpdates,
OpenSshHosts,
/// Open the SSH host manager on a blank host form. Distinct from
diff --git a/config/src/lib.rs b/config/src/lib.rs
index 9aaeb0b3..7bd1bc93 100644
--- a/config/src/lib.rs
+++ b/config/src/lib.rs
@@ -33,7 +33,7 @@ pub mod keyassignment;
mod keys;
pub mod lua;
pub mod meta;
-mod scheme_data;
+pub mod scheme_data;
mod serial;
mod ssh;
mod terminal;
diff --git a/mux/src/lib.rs b/mux/src/lib.rs
index 81122b70..6066c373 100644
--- a/mux/src/lib.rs
+++ b/mux/src/lib.rs
@@ -48,6 +48,7 @@ pub mod localpane;
pub mod pane;
mod parse_watchdog;
pub mod renderable;
+pub mod session_server;
pub mod ssh;
pub mod ssh_agent;
pub mod tab;
@@ -118,6 +119,9 @@ pub enum MuxNotification {
FrontendLeaseChanged(FrontendViewportState),
/// The connection-wide A/B mode or the exclusive handoff owner changed.
FrontendAccessChanged(FrontendAccessState),
+ /// The server's configuration reloaded and its resolved colour scheme may
+ /// have changed; every connection re-sends its default palette.
+ DefaultPaletteChanged,
}
static SUB_ID: AtomicUsize = AtomicUsize::new(0);
diff --git a/mux/src/session_server.rs b/mux/src/session_server.rs
new file mode 100644
index 00000000..34ead17f
--- /dev/null
+++ b/mux/src/session_server.rs
@@ -0,0 +1,117 @@
+//! Stopping the session server at the default socket: the one thing the
+//! desktop, the CLI and the settings switch all do to it, in one place.
+//! The server is found through the pid file it holds locked, never by
+//! name, so a stale file or somebody else's process is left alone.
+
+use std::path::Path;
+use std::time::{Duration, Instant};
+
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum StopOutcome {
+ /// Nothing holds the pid file: no server to stop.
+ NotRunning,
+ /// Asked to stop, and its socket went away within the wait.
+ Stopped { pid: u32 },
+ /// Asked to stop; its socket still answered when the wait ran out.
+ Lingering { pid: u32 },
+}
+
+/// The pid of the server holding `pid_file`'s lock, if one does.
+#[cfg(unix)]
+pub fn pid_holding(pid_file: &Path) -> Option<u32> {
+ use std::os::unix::io::AsRawFd as _;
+ let file = std::fs::File::open(pid_file).ok()?;
+ let locked_by_someone =
+ unsafe { libc::flock(file.as_raw_fd(), libc::LOCK_EX | libc::LOCK_NB) } != 0;
+ if !locked_by_someone {
+ // We hold it now: no server does. The lock goes with the file.
+ return None;
+ }
+ std::fs::read_to_string(pid_file)
+ .ok()?
+ .trim()
+ .parse::<u32>()
+ .ok()
+ .filter(|pid| *pid > 1)
+}
+
+#[cfg(not(unix))]
+pub fn pid_holding(_pid_file: &Path) -> Option<u32> {
+ None
+}
+
+/// Whether something accepts on the unix socket at `path`: a non-blocking
+/// connect, so a full backlog cannot hang the caller.
+#[cfg(unix)]
+pub fn socket_answers(path: &Path) -> bool {
+ use std::os::unix::ffi::OsStrExt;
+ let bytes = path.as_os_str().as_bytes();
+ let mut addr: libc::sockaddr_un = unsafe { std::mem::zeroed() };
+ if bytes.len() >= addr.sun_path.len() {
+ return false;
+ }
+ addr.sun_family = libc::AF_UNIX as libc::sa_family_t;
+ for (dst, src) in addr.sun_path.iter_mut().zip(bytes) {
+ *dst = *src as libc::c_char;
+ }
+ let fd = unsafe { libc::socket(libc::AF_UNIX, libc::SOCK_STREAM, 0) };
+ if fd < 0 {
+ return false;
+ }
+ unsafe {
+ let flags = libc::fcntl(fd, libc::F_GETFL);
+ libc::fcntl(fd, libc::F_SETFL, flags | libc::O_NONBLOCK);
+ }
+ let rc = unsafe {
+ libc::connect(
+ fd,
+ &addr as *const libc::sockaddr_un as *const libc::sockaddr,
+ std::mem::size_of::<libc::sockaddr_un>() as libc::socklen_t,
+ )
+ };
+ let err = std::io::Error::last_os_error();
+ unsafe { libc::close(fd) };
+ rc == 0
+ || matches!(
+ err.raw_os_error(),
+ Some(libc::EINPROGRESS) | Some(libc::EAGAIN) | Some(libc::EWOULDBLOCK)
+ )
+}
+
+#[cfg(not(unix))]
+pub fn socket_answers(_path: &Path) -> bool {
+ false
+}
+
+/// Whether a server holds the pid file and answers on the socket.
+pub fn is_running(pid_file: &Path, socket: &Path) -> bool {
+ pid_holding(pid_file).is_some() && socket_answers(socket)
+}
+
+/// Stop the server holding `pid_file` (SIGTERM: it ends its panes and
+/// exits), waiting up to `wait` for its socket to close.
+#[cfg(unix)]
+pub fn stop(pid_file: &Path, socket: &Path, wait: Duration) -> anyhow::Result<StopOutcome> {
+ let Some(pid) = pid_holding(pid_file) else {
+ return Ok(StopOutcome::NotRunning);
+ };
+ if unsafe { libc::kill(pid as libc::pid_t, libc::SIGTERM) } != 0 {
+ anyhow::bail!(
+ "could not stop the session server (pid {pid}): {}",
+ std::io::Error::last_os_error()
+ );
+ }
+ let started = Instant::now();
+ while started.elapsed() < wait {
+ if !socket_answers(socket) && pid_holding(pid_file).is_none() {
+ return Ok(StopOutcome::Stopped { pid });
+ }
+ std::thread::sleep(Duration::from_millis(50));
+ }
+ Ok(StopOutcome::Lingering { pid })
+}
+
+#[cfg(not(unix))]
+pub fn stop(_pid_file: &Path, _socket: &Path, _wait: Duration) -> anyhow::Result<StopOutcome> {
+ anyhow::bail!("stopping the session server is not supported on this platform")
+}
diff --git a/thinkterm-i18n/i18n/de-DE.ftl b/thinkterm-i18n/i18n/de-DE.ftl
index cca7e2fd..38d5b984 100644
--- a/thinkterm-i18n/i18n/de-DE.ftl
+++ b/thinkterm-i18n/i18n/de-DE.ftl
@@ -536,6 +536,15 @@ settings-status-remote-update-keep-sessions-error = Die Einstellung für Remote-
settings-status-local-sessions-via-mux-on = Lokale Terminals laufen ab dem nächsten Start in einem Hintergrund-Sitzungsserver.
settings-status-local-sessions-via-mux-off = Lokale Terminals laufen ab dem nächsten Start innerhalb von ThinkTerm.
settings-status-local-sessions-via-mux-error = Die Einstellung für lokale Sitzungen konnte nicht gespeichert werden: { $error }
+settings-stop-session-server = Sitzungsserver stoppen
+settings-stop-session-server-description = Beendet jetzt alle Terminals im Sitzungsserver im Hintergrund. Die Fenster, die sie zeigen, schließen sich; er startet wieder, sobald ThinkTerm ihn das nächste Mal braucht.
+settings-stop-session-server-now = Stoppen…
+settings-stop-session-server-confirm = Jetzt stoppen
+settings-status-stop-session-server-confirm = Noch einmal drücken, um den Sitzungsserver zu stoppen; seine Terminals werden beendet.
+settings-status-stop-session-server-done = Der Sitzungsserver wurde gestoppt.
+settings-status-stop-session-server-none = Es läuft kein Sitzungsserver.
+settings-status-stop-session-server-lingering = Der Sitzungsserver wurde zum Stoppen aufgefordert und fährt noch herunter.
+settings-status-stop-session-server-error = Der Sitzungsserver konnte nicht gestoppt werden: { $error }
settings-status-window-restore-off = Wiederherstellen des Fensterrahmens für neue macOS-Fenster deaktiviert.
settings-status-window-restore-error = Einstellung zum Wiederherstellen des Fensters konnte nicht gespeichert werden: { $error }
settings-status-renderer = Renderer des Hauptfensters auf { $renderer } gesetzt; starten Sie ThinkTerm neu, um ihn anzuwenden.
@@ -733,6 +742,14 @@ web-card-busy-title = Das Terminal wird auf einem anderen Gerät verwendet
web-card-busy-hint = Klicken oder scrollen, um fortzufahren
web-card-free-title = Das Terminal ist verfügbar
web-card-free-hint = Klicken oder scrollen, um zu übernehmen
+web-card-busy-on = Das Terminal wird auf { $host } verwendet
+web-card-taking-title = Terminal wird übernommen…
+web-card-taking-hint = Warten, bis der Server es übergibt
+web-card-refused-title = Das andere Gerät hat das Terminal behalten
+web-card-refused-hint = Dort wird es noch verwendet; gleich noch einmal versuchen
+web-card-take-over = Übernehmen
+web-card-take-control = Steuerung übernehmen
+web-card-try-again = Erneut versuchen
web-toast-pane-closed = das Pane wurde auf dem Server geschlossen
web-toast-no-panes = der Server hat keine Panes zum Anzeigen
web-toast-taking-over = das Terminal wird übernommen…
@@ -744,6 +761,8 @@ web-act-close-tab = Schließen des Tabs
web-act-new-tab = Öffnen eines neuen Tabs
web-act-resize-pane = Ändern der Pane-Größe
web-act-split-pane = Teilen des Panes
+web-act-move-tab = Tab verschieben
+web-act-move-pane = Bereich verschieben
web-act-zoom-pane = Vergrößern des Panes
web-act-start-thread = Starten eines Threads
web-act-open-thread = Öffnen des Threads
@@ -753,7 +772,11 @@ web-act-resize-tab = Ändern der Tab-Größe
web-act-take-over = Übernehmen
web-act-size-font = Ändern der Schriftgröße
web-sidebar-other-windows = Andere Fenster
-web-path-placeholder = ~/projekt oder /pfad auf dem Server
+web-path-placeholder = ~/projekte/app
+web-add-workspace = Workspace hinzufügen…
+web-add-workspace-hint = Ein Verzeichnis auf dem Server: ~/dir oder /dir
+web-add-workspace-empty = Gib einen Verzeichnispfad ein
+web-add-workspace-relative = Ein Workspace ist ein Verzeichnis: ~/dir oder /dir
web-tip-space = Space
web-tip-new-thread = Neuer Thread im angezeigten Projekt
web-tip-new-thread-here = Neuer Thread hier
@@ -762,19 +785,18 @@ web-tip-restore = Wiederherstellen
web-tip-archive = Dieses Projekt archivieren (beendet seine Programme)
web-tip-pin = Anheften
web-tip-unpin = Lösen
-web-tip-delete-thread = Diesen Thread löschen und seine Programme beenden. Fragt zweimal nach.
+web-tip-delete-thread = Diesen Thread löschen und seine Programme beenden.
web-confirm-delete = löschen?
web-confirm-close = schließen?
-web-tip-close-pane = Dieses Pane schließen und sein Programm beenden. Fragt zweimal nach.
-web-tip-close-tab = Diesen Tab schließen und seine Programme beenden. Fragt zweimal nach.
+web-tip-close-pane = Dieses Pane schließen und sein Programm beenden.
+web-tip-close-tab = Diesen Tab schließen und seine Programme beenden.
web-tip-new-tab = Neuer Tab
+web-tip-new-pane = Neuer Tab in diesem Bereich
web-tip-split-down = Unten teilen
web-tip-split-right = Rechts teilen
web-tip-zoom = Dieses Pane auf den ganzen Tab vergrößern
web-tip-unzoom = Vergrößerung aufheben
web-tip-sidebar = Seitenleiste ein- oder ausblenden
-web-fitted = angepasst
-web-tip-fitted = Der Tab ist an dieses Fenster angepasst; Ctrl+Shift+F gibt die Größe zurück
web-menu-frontend-access = Frontend-Zugriff
web-menu-access-shared = A · Geteilt (wie tmux)
web-menu-access-handoff = B · Übergabe (exklusiv)
@@ -794,6 +816,7 @@ web-cmd-font-reset = Schriftgröße zurücksetzen
web-cmd-language = Sprache: { $language }
web-tip-search = Threads, Tabs und Befehle suchen (Cmd+K)
web-agents-title = Agents
+web-panel-desktop-only = Im Browser noch nicht verfügbar
web-tip-agents = Agents-Panel ein- oder ausblenden
web-tip-settings = Einstellungen
web-settings-theme = Design
@@ -815,6 +838,11 @@ web-settings-language-description = Die Sprache der Seite. „Systemeinstellung
web-settings-hotkey-description = Öffnet die Suche von überall auf der Seite.
web-settings-theme-description = Dunkel, hell oder wie das System eingestellt ist.
web-settings-font-description = Der Zelle des Desktops folgen, damit beide dasselbe Raster zeigen, oder eine eigene Größe für diese Seite behalten.
+web-settings-scheme = Farbschema
+web-settings-scheme-description = Dem im Server eingestellten Farbschema folgen oder eines nur für diesen Browser wählen.
+web-scheme-desktop = Dem Desktop folgen
+web-scheme-search = Farbschemata durchsuchen
+web-scheme-preview = Vorschau
web-settings-hover-reveal-description = Bei eingeklappter Seitenleiste zeigt ein Zeiger am linken Rand sie an, bis er sich entfernt.
web-settings-agents-panel-description = Ein Panel rechts, das jedes Pane auflistet, in dem ein Agent läuft.
web-settings-sidebar-reset-description = Setzt die Seitenleiste auf ihre Standardbreite zurück.
diff --git a/thinkterm-i18n/i18n/en-US.ftl b/thinkterm-i18n/i18n/en-US.ftl
index 4d122b15..8934f4c6 100644
--- a/thinkterm-i18n/i18n/en-US.ftl
+++ b/thinkterm-i18n/i18n/en-US.ftl
@@ -536,6 +536,15 @@ settings-status-remote-update-keep-sessions-error = Could not save the remote up
settings-status-local-sessions-via-mux-on = Local terminals will run in a background session server from the next launch.
settings-status-local-sessions-via-mux-off = Local terminals will run inside ThinkTerm from the next launch.
settings-status-local-sessions-via-mux-error = Could not save the local sessions setting: { $error }
+settings-stop-session-server = Stop the session server
+settings-stop-session-server-description = Ends every terminal running in the background session server now. The windows showing them close; it starts again the next time ThinkTerm needs it.
+settings-stop-session-server-now = Stop…
+settings-stop-session-server-confirm = Stop now
+settings-status-stop-session-server-confirm = Press again to stop the session server; the terminals in it end.
+settings-status-stop-session-server-done = The session server has stopped.
+settings-status-stop-session-server-none = No session server is running.
+settings-status-stop-session-server-lingering = The session server was asked to stop and is still shutting down.
+settings-status-stop-session-server-error = Could not stop the session server: { $error }
settings-status-window-restore-off = Main window frame restore disabled for new macOS windows.
settings-status-window-restore-error = Unable to save window restore setting: { $error }
settings-status-renderer = Main window renderer set to { $renderer }; restart ThinkTerm to apply it.
@@ -725,6 +734,14 @@ web-card-busy-title = Terminal is being used on another device
web-card-busy-hint = Click or scroll to continue
web-card-free-title = Terminal is available
web-card-free-hint = Click or scroll to take control
+web-card-busy-on = Terminal is being used on { $host }
+web-card-taking-title = Taking the terminal over…
+web-card-taking-hint = Waiting for the server to hand it over
+web-card-refused-title = The other device kept the terminal
+web-card-refused-hint = Something there is still using it; try again in a moment
+web-card-take-over = Take over
+web-card-take-control = Take control
+web-card-try-again = Try again
web-toast-pane-closed = the pane was closed on the server
web-toast-no-panes = the server has no panes to show
web-toast-taking-over = taking the terminal over…
@@ -736,6 +753,8 @@ web-act-close-tab = close the tab
web-act-new-tab = open a new tab
web-act-resize-pane = resize the pane
web-act-split-pane = split the pane
+web-act-move-tab = move the tab
+web-act-move-pane = move the pane
web-act-zoom-pane = zoom the pane
web-act-start-thread = start a thread
web-act-open-thread = open the thread
@@ -745,7 +764,11 @@ web-act-resize-tab = resize the tab
web-act-take-over = take over
web-act-size-font = size the font
web-sidebar-other-windows = Other windows
-web-path-placeholder = ~/project or /path on the server
+web-path-placeholder = ~/projects/app
+web-add-workspace = Add workspace…
+web-add-workspace-hint = A directory on the server: ~/dir or /dir
+web-add-workspace-empty = Type a directory path
+web-add-workspace-relative = A workspace is a directory: ~/dir or /dir
web-tip-space = Space
web-tip-new-thread = New thread in the project on show
web-tip-new-thread-here = New thread here
@@ -754,19 +777,18 @@ web-tip-restore = Restore
web-tip-archive = Archive this project (ends its programs)
web-tip-pin = Pin
web-tip-unpin = Unpin
-web-tip-delete-thread = Delete this thread and end its programs. Asks twice.
+web-tip-delete-thread = Delete this thread and end its programs.
web-confirm-delete = delete?
web-confirm-close = close?
-web-tip-close-pane = Close this pane and end its program. Asks twice.
-web-tip-close-tab = Close this tab and end its programs. Asks twice.
+web-tip-close-pane = Close this pane and end its program.
+web-tip-close-tab = Close this tab and end its programs.
web-tip-new-tab = New tab
+web-tip-new-pane = New tab in this pane
web-tip-split-down = Split down
web-tip-split-right = Split right
web-tip-zoom = Zoom this pane to the whole tab
web-tip-unzoom = Unzoom
web-tip-sidebar = Show or hide the sidebar
-web-fitted = fitted
-web-tip-fitted = The tab is fitted to this window; Ctrl+Shift+F gives the size back
web-menu-frontend-access = Frontend access
web-menu-access-shared = A · Shared (tmux-like)
web-menu-access-handoff = B · Handoff (exclusive)
@@ -786,6 +808,7 @@ web-cmd-font-reset = Reset font size
web-cmd-language = Language: { $language }
web-tip-search = Search threads, tabs and commands (Cmd+K)
web-agents-title = Agents
+web-panel-desktop-only = Not available in the browser yet
web-tip-agents = Show or hide the agents panel
web-tip-settings = Settings
web-settings-theme = Theme
@@ -815,6 +838,11 @@ web-settings-language-description = The language of the page. "Follow System" ta
web-settings-hotkey-description = Opens the search from anywhere on the page.
web-settings-theme-description = Dark, light, or whatever the system is set to.
web-settings-font-description = Follow the desktop's cell so both show the same grid, or keep a size of this page's own.
+web-settings-scheme = Color scheme
+web-settings-scheme-description = Follow the color scheme the server is configured with, or pick one for this browser alone.
+web-scheme-desktop = Follow the desktop
+web-scheme-search = Search color schemes
+web-scheme-preview = Preview
web-settings-hover-reveal-description = With the sidebar put away, resting on the left edge shows it until the pointer leaves.
web-settings-agents-panel-description = A panel on the right listing every pane an agent runs in.
web-settings-sidebar-reset-description = Put the sidebar back to its default width.
diff --git a/thinkterm-i18n/i18n/fr-FR.ftl b/thinkterm-i18n/i18n/fr-FR.ftl
index dc7bd2f3..897f91b1 100644
--- a/thinkterm-i18n/i18n/fr-FR.ftl
+++ b/thinkterm-i18n/i18n/fr-FR.ftl
@@ -536,6 +536,15 @@ settings-status-remote-update-keep-sessions-error = Impossible d’enregistrer l
settings-status-local-sessions-via-mux-on = Les terminaux locaux tourneront dans un serveur de sessions dès le prochain lancement.
settings-status-local-sessions-via-mux-off = Les terminaux locaux tourneront dans ThinkTerm dès le prochain lancement.
settings-status-local-sessions-via-mux-error = Impossible d’enregistrer le réglage des sessions locales : { $error }
+settings-stop-session-server = Arrêter le serveur de session
+settings-stop-session-server-description = Met fin maintenant à tous les terminaux du serveur de session en arrière-plan. Les fenêtres qui les affichent se ferment ; il redémarrera la prochaine fois que ThinkTerm en aura besoin.
+settings-stop-session-server-now = Arrêter…
+settings-stop-session-server-confirm = Arrêter maintenant
+settings-status-stop-session-server-confirm = Appuyez encore pour arrêter le serveur de session ; ses terminaux prendront fin.
+settings-status-stop-session-server-done = Le serveur de session est arrêté.
+settings-status-stop-session-server-none = Aucun serveur de session ne tourne.
+settings-status-stop-session-server-lingering = L’arrêt du serveur de session a été demandé ; il se termine encore.
+settings-status-stop-session-server-error = Impossible d’arrêter le serveur de session : { $error }
settings-status-window-restore-off = Restauration de la taille et position désactivée pour les nouvelles fenêtres macOS.
settings-status-window-restore-error = Impossible d’enregistrer la restauration de fenêtre : { $error }
settings-status-renderer = Moteur de rendu principal défini sur { $renderer } ; redémarrez ThinkTerm pour l’appliquer.
@@ -730,6 +739,14 @@ web-card-busy-title = Le terminal est utilisé sur un autre appareil
web-card-busy-hint = Cliquez ou faites défiler pour continuer
web-card-free-title = Le terminal est disponible
web-card-free-hint = Cliquez ou faites défiler pour prendre la main
+web-card-busy-on = Le terminal est utilisé sur { $host }
+web-card-taking-title = Reprise du terminal…
+web-card-taking-hint = En attente que le serveur le cède
+web-card-refused-title = L’autre appareil a gardé le terminal
+web-card-refused-hint = Il y est encore utilisé ; réessayez dans un instant
+web-card-take-over = Reprendre
+web-card-take-control = Prendre la main
+web-card-try-again = Réessayer
web-toast-pane-closed = le volet a été fermé sur le serveur
web-toast-no-panes = le serveur n’a aucun volet à afficher
web-toast-taking-over = reprise du terminal en cours…
@@ -741,6 +758,8 @@ web-act-close-tab = la fermeture de l’onglet
web-act-new-tab = l’ouverture d’un nouvel onglet
web-act-resize-pane = le redimensionnement du volet
web-act-split-pane = la division du volet
+web-act-move-tab = déplacement de l’onglet
+web-act-move-pane = déplacement du panneau
web-act-zoom-pane = l’agrandissement du volet
web-act-start-thread = le démarrage d’une session
web-act-open-thread = l’ouverture de la session
@@ -750,7 +769,11 @@ web-act-resize-tab = le redimensionnement de l’onglet
web-act-take-over = la prise de contrôle
web-act-size-font = le réglage de la taille de police
web-sidebar-other-windows = Autres fenêtres
-web-path-placeholder = ~/projet ou /chemin sur le serveur
+web-path-placeholder = ~/projets/app
+web-add-workspace = Ajouter un espace de travail…
+web-add-workspace-hint = Un dossier sur le serveur : ~/dir ou /dir
+web-add-workspace-empty = Saisissez un chemin de dossier
+web-add-workspace-relative = Un espace de travail est un dossier : ~/dir ou /dir
web-tip-space = Espace
web-tip-new-thread = Nouvelle session dans le projet affiché
web-tip-new-thread-here = Nouvelle session ici
@@ -759,19 +782,18 @@ web-tip-restore = Restaurer
web-tip-archive = Archiver ce projet (met fin à ses programmes)
web-tip-pin = Épingler
web-tip-unpin = Désépingler
-web-tip-delete-thread = Supprimer cette session et mettre fin à ses programmes. Demande deux fois.
+web-tip-delete-thread = Supprimer cette session et mettre fin à ses programmes.
web-confirm-delete = supprimer ?
web-confirm-close = fermer ?
-web-tip-close-pane = Fermer ce volet et mettre fin à son programme. Demande deux fois.
-web-tip-close-tab = Fermer cet onglet et mettre fin à ses programmes. Demande deux fois.
+web-tip-close-pane = Fermer ce volet et mettre fin à son programme.
+web-tip-close-tab = Fermer cet onglet et mettre fin à ses programmes.
web-tip-new-tab = Nouvel onglet
+web-tip-new-pane = Nouvel onglet dans ce panneau
web-tip-split-down = Scinder en bas
web-tip-split-right = Scinder à droite
web-tip-zoom = Agrandir ce volet à tout l’onglet
web-tip-unzoom = Annuler l’agrandissement
web-tip-sidebar = Afficher ou masquer la barre latérale
-web-fitted = ajusté
-web-tip-fitted = L’onglet est ajusté à cette fenêtre ; Ctrl+Shift+F rend la taille d’origine
web-menu-frontend-access = Accès du frontend
web-menu-access-shared = A · Partagé (façon tmux)
web-menu-access-handoff = B · Passation (exclusif)
@@ -791,6 +813,7 @@ web-cmd-font-reset = Réinitialiser la taille de police
web-cmd-language = Langue : { $language }
web-tip-search = Rechercher des sessions, des onglets et des commandes (Cmd+K)
web-agents-title = Agents
+web-panel-desktop-only = Pas encore disponible dans le navigateur
web-tip-agents = Afficher ou masquer le panneau des agents
web-tip-settings = Réglages
web-settings-theme = Thème
@@ -812,6 +835,11 @@ web-settings-language-description = La langue de la page. « Suivre le système
web-settings-hotkey-description = Ouvre la recherche depuis n’importe où sur la page.
web-settings-theme-description = Sombre, clair, ou ce que le système a choisi.
web-settings-font-description = Suivre la cellule du bureau pour afficher la même grille des deux côtés, ou garder une taille propre à cette page.
+web-settings-scheme = Palette de couleurs
+web-settings-scheme-description = Suivre la palette configurée sur le serveur, ou en choisir une pour ce navigateur seulement.
+web-scheme-desktop = Suivre le bureau
+web-scheme-search = Rechercher une palette
+web-scheme-preview = Aperçu
web-settings-hover-reveal-description = Barre latérale rangée, poser le pointeur sur le bord gauche la fait apparaître jusqu’à ce qu’il s’éloigne.
web-settings-agents-panel-description = Un panneau à droite qui liste chaque volet où tourne un agent.
web-settings-sidebar-reset-description = Remettre la barre latérale à sa largeur par défaut.
diff --git a/thinkterm-i18n/i18n/ja-JP.ftl b/thinkterm-i18n/i18n/ja-JP.ftl
index 1c46b3c2..44ebfc49 100644
--- a/thinkterm-i18n/i18n/ja-JP.ftl
+++ b/thinkterm-i18n/i18n/ja-JP.ftl
@@ -527,6 +527,15 @@ settings-status-remote-update-keep-sessions-error = リモート更新の設定
settings-status-local-sessions-via-mux-on = 次回起動からローカル端末はバックグラウンドのセッションサーバーで動作します。
settings-status-local-sessions-via-mux-off = 次回起動からローカル端末は ThinkTerm 内で動作します。
settings-status-local-sessions-via-mux-error = ローカルセッションの設定を保存できませんでした: { $error }
+settings-stop-session-server = セッションサーバーを停止
+settings-stop-session-server-description = バックグラウンドのセッションサーバーで動いているターミナルをすべて今すぐ終了します。それらを表示していたウィンドウも閉じます。次に ThinkTerm が必要とするときに再び起動します。
+settings-stop-session-server-now = 停止…
+settings-stop-session-server-confirm = 今すぐ停止
+settings-status-stop-session-server-confirm = もう一度押すとセッションサーバーを停止し、その中のターミナルは終了します。
+settings-status-stop-session-server-done = セッションサーバーを停止しました。
+settings-status-stop-session-server-none = 動作中のセッションサーバーはありません。
+settings-status-stop-session-server-lingering = セッションサーバーに停止を要求しました。まだ終了処理中です。
+settings-status-stop-session-server-error = セッションサーバーを停止できませんでした: { $error }
settings-status-window-restore-off = 新しい macOS ウィンドウで位置とサイズの復元を無効にしました。
settings-status-window-restore-error = ウィンドウ復元設定を保存できません:{ $error }
settings-status-renderer = メインウィンドウのレンダラーを { $renderer } に設定しました。ThinkTerm の再起動後に適用されます。
@@ -711,6 +720,14 @@ web-card-busy-title = ターミナルは別のデバイスで使用中です
web-card-busy-hint = クリックまたはスクロールで続行
web-card-free-title = ターミナルは利用できます
web-card-free-hint = クリックまたはスクロールで操作を引き継ぐ
+web-card-busy-on = ターミナルは { $host } で使用中です
+web-card-taking-title = ターミナルを引き継いでいます…
+web-card-taking-hint = サーバーの引き渡しを待っています
+web-card-refused-title = 相手のデバイスがターミナルを手放しませんでした
+web-card-refused-hint = まだそちらで使用中です。しばらくしてからもう一度お試しください
+web-card-take-over = 引き継ぐ
+web-card-take-control = 操作を始める
+web-card-try-again = もう一度試す
web-toast-pane-closed = サーバー側でペインが閉じられました
web-toast-no-panes = サーバーに表示できるペインがありません
web-toast-taking-over = ターミナルを引き継いでいます…
@@ -722,6 +739,8 @@ web-act-close-tab = タブを閉じる
web-act-new-tab = 新しいタブを開く
web-act-resize-pane = ペインのサイズを変える
web-act-split-pane = ペインを分割する
+web-act-move-tab = タブの移動
+web-act-move-pane = ペインの移動
web-act-zoom-pane = ペインを拡大する
web-act-start-thread = セッションを開始する
web-act-open-thread = セッションを開く
@@ -731,7 +750,11 @@ web-act-resize-tab = タブのサイズを変える
web-act-take-over = 引き継ぐ
web-act-size-font = フォントサイズを変える
web-sidebar-other-windows = 他のウィンドウ
-web-path-placeholder = ~/project またはサーバー上の /path
+web-path-placeholder = ~/projects/app
+web-add-workspace = ワークスペースを追加…
+web-add-workspace-hint = サーバー上のディレクトリ:~/dir または /dir
+web-add-workspace-empty = ディレクトリのパスを入力してください
+web-add-workspace-relative = ワークスペースはディレクトリです:~/dir または /dir
web-tip-space = スペース
web-tip-new-thread = 表示中のプロジェクトに新しいセッション
web-tip-new-thread-here = ここに新しいセッション
@@ -740,19 +763,18 @@ web-tip-restore = 復元
web-tip-archive = このプロジェクトをアーカイブ(プログラムを終了します)
web-tip-pin = ピン留め
web-tip-unpin = ピン留めを解除
-web-tip-delete-thread = このセッションを削除してプログラムを終了します。2 回確認します。
+web-tip-delete-thread = このセッションを削除してプログラムを終了します。
web-confirm-delete = 削除?
web-confirm-close = 閉じる?
-web-tip-close-pane = このペインを閉じてプログラムを終了します。2 回確認します。
-web-tip-close-tab = このタブを閉じてプログラムを終了します。2 回確認します。
+web-tip-close-pane = このペインを閉じてプログラムを終了します。
+web-tip-close-tab = このタブを閉じてプログラムを終了します。
web-tip-new-tab = 新しいタブ
+web-tip-new-pane = このペインに新しいタブ
web-tip-split-down = 下に分割
web-tip-split-right = 右に分割
web-tip-zoom = このペインをタブ全体に拡大
web-tip-unzoom = 拡大を解除
web-tip-sidebar = サイドバーを表示または非表示
-web-fitted = 調整済み
-web-tip-fitted = タブはこのウィンドウに合わせてあります。Ctrl+Shift+F で元のサイズに戻せます
web-menu-frontend-access = フロントエンドのアクセス方式
web-menu-access-shared = A · 共有(tmux 風)
web-menu-access-handoff = B · 引き継ぎ(排他)
@@ -772,6 +794,7 @@ web-cmd-font-reset = フォントサイズをリセット
web-cmd-language = 言語:{ $language }
web-tip-search = セッション、タブ、コマンドを検索(Cmd+K)
web-agents-title = エージェント
+web-panel-desktop-only = ブラウザーではまだ使えません
web-tip-agents = エージェントパネルを表示または非表示
web-tip-settings = 設定
web-settings-theme = テーマ
@@ -793,6 +816,11 @@ web-settings-language-description = ページの言語。「システム設定
web-settings-hotkey-description = ページのどこからでも検索を開きます。
web-settings-theme-description = ダーク、ライト、またはシステムの設定に従います。
web-settings-font-description = デスクトップのセルに合わせて同じグリッドを表示するか、このページ独自のサイズを保ちます。
+web-settings-scheme = カラースキーム
+web-settings-scheme-description = サーバーに設定されたカラースキームに従うか、このブラウザーだけのものを選びます。
+web-scheme-desktop = デスクトップに従う
+web-scheme-search = カラースキームを検索
+web-scheme-preview = プレビュー
web-settings-hover-reveal-description = サイドバーを閉じているとき、左端にポインターを置くと表示され、離れると戻ります。
web-settings-agents-panel-description = エージェントが動いているペインを一覧する右側のパネル。
web-settings-sidebar-reset-description = サイドバーを既定の幅に戻します。
diff --git a/thinkterm-i18n/i18n/zh-CN.ftl b/thinkterm-i18n/i18n/zh-CN.ftl
index 8bfae29a..5c70bf0a 100644
--- a/thinkterm-i18n/i18n/zh-CN.ftl
+++ b/thinkterm-i18n/i18n/zh-CN.ftl
@@ -527,6 +527,15 @@ settings-status-remote-update-keep-sessions-error = 无法保存远端更新设
settings-status-local-sessions-via-mux-on = 已开启:下次启动起本地终端跑在后台会话 server 里。
settings-status-local-sessions-via-mux-off = 已关闭:下次启动起本地终端跑在 ThinkTerm 进程内。
settings-status-local-sessions-via-mux-error = 无法保存本地会话设置:{ $error }
+settings-stop-session-server = 停止会话服务器
+settings-stop-session-server-description = 立即结束后台会话服务器里的全部终端。显示它们的窗口会随之关闭;下次 ThinkTerm 需要时会重新启动它。
+settings-stop-session-server-now = 停止…
+settings-stop-session-server-confirm = 确认停止
+settings-status-stop-session-server-confirm = 再按一次即停止会话服务器,其中的终端会结束。
+settings-status-stop-session-server-done = 会话服务器已停止。
+settings-status-stop-session-server-none = 没有正在运行的会话服务器。
+settings-status-stop-session-server-lingering = 已要求会话服务器停止,它仍在关闭中。
+settings-status-stop-session-server-error = 无法停止会话服务器:{ $error }
settings-status-window-restore-off = 已为新的 macOS 窗口关闭主窗口位置与大小恢复。
settings-status-window-restore-error = 无法保存窗口恢复设置:{ $error }
settings-status-renderer = 主窗口渲染器已设为 { $renderer };重启 ThinkTerm 后生效。
@@ -711,6 +720,14 @@ web-card-busy-title = 终端正在另一台设备上使用
web-card-busy-hint = 点击或滚动即可继续
web-card-free-title = 终端可以使用
web-card-free-hint = 点击或滚动即可接管
+web-card-busy-on = 终端正在 { $host } 上使用
+web-card-taking-title = 正在接管终端…
+web-card-taking-hint = 等待服务端交出终端
+web-card-refused-title = 另一台设备没有交出终端
+web-card-refused-hint = 那边还在使用它,稍后再试
+web-card-take-over = 接管
+web-card-take-control = 开始使用
+web-card-try-again = 再试一次
web-toast-pane-closed = 服务端上的这个窗格已被关闭
web-toast-no-panes = 服务端没有可显示的窗格
web-toast-taking-over = 正在接管终端…
@@ -722,6 +739,8 @@ web-act-close-tab = 关闭标签页
web-act-new-tab = 新建标签页
web-act-resize-pane = 调整窗格大小
web-act-split-pane = 分屏
+web-act-move-tab = 移动标签页
+web-act-move-pane = 移动窗格
web-act-zoom-pane = 放大窗格
web-act-start-thread = 新建会话
web-act-open-thread = 打开会话
@@ -731,7 +750,11 @@ web-act-resize-tab = 调整标签页大小
web-act-take-over = 接管
web-act-size-font = 调整字号
web-sidebar-other-windows = 其他窗口
-web-path-placeholder = ~/project 或服务端上的 /path
+web-path-placeholder = ~/projects/app
+web-add-workspace = 添加工作区…
+web-add-workspace-hint = 服务端上的一个目录:~/dir 或 /dir
+web-add-workspace-empty = 请输入目录路径
+web-add-workspace-relative = 工作区是一个目录:~/dir 或 /dir
web-tip-space = 空间
web-tip-new-thread = 在当前显示的项目中新建会话
web-tip-new-thread-here = 在此新建会话
@@ -740,19 +763,18 @@ web-tip-restore = 恢复
web-tip-archive = 归档这个项目(会结束其中的程序)
web-tip-pin = 置顶
web-tip-unpin = 取消置顶
-web-tip-delete-thread = 删除这个会话并结束其中的程序。会问两次。
+web-tip-delete-thread = 删除这个会话并结束其中的程序。
web-confirm-delete = 删除?
web-confirm-close = 关闭?
-web-tip-close-pane = 关闭这个窗格并结束其中的程序。会问两次。
-web-tip-close-tab = 关闭这个标签页并结束其中的程序。会问两次。
+web-tip-close-pane = 关闭这个窗格并结束其中的程序。
+web-tip-close-tab = 关闭这个标签页并结束其中的程序。
web-tip-new-tab = 新建标签页
+web-tip-new-pane = 在此窗格新建标签页
web-tip-split-down = 向下分屏
web-tip-split-right = 向右分屏
web-tip-zoom = 把这个窗格放大到整个标签页
web-tip-unzoom = 取消放大
web-tip-sidebar = 显示或隐藏侧栏
-web-fitted = 已适配
-web-tip-fitted = 标签页已适配这个窗口;按 Ctrl+Shift+F 把尺寸还回去
web-menu-frontend-access = 前端访问模式
web-menu-access-shared = A · 共享(类似 tmux)
web-menu-access-handoff = B · 交接(独占)
@@ -772,6 +794,7 @@ web-cmd-font-reset = 重置字号
web-cmd-language = 语言:{ $language }
web-tip-search = 搜索会话、标签页和命令(Cmd+K)
web-agents-title = Agent
+web-panel-desktop-only = 浏览器端还没有这个功能
web-tip-agents = 显示或隐藏 Agent 面板
web-tip-settings = 设置
web-settings-theme = 主题
@@ -793,6 +816,11 @@ web-settings-language-description = 页面的语言。“跟随系统”使用
web-settings-hotkey-description = 在页面任意位置打开搜索。
web-settings-theme-description = 深色、浅色,或跟随系统设置。
web-settings-font-description = 跟随桌面端的单元格,让两边显示同样的网格;或使用本页面自己的固定字号。
+web-settings-scheme = 配色方案
+web-settings-scheme-description = 跟随服务端配置的配色方案,或只为这个浏览器单独选一套。
+web-scheme-desktop = 跟随桌面端
+web-scheme-search = 搜索配色方案
+web-scheme-preview = 预览
web-settings-hover-reveal-description = 侧栏收起时,鼠标停在左边缘会临时展开它,离开后收回。
web-settings-agents-panel-description = 右侧的面板,列出每个运行着 Agent 的窗格。
web-settings-sidebar-reset-description = 把侧栏恢复到默认宽度。
diff --git a/wezterm-gui/src/commands.rs b/wezterm-gui/src/commands.rs
index 50dbd2d5..39e6dbbd 100644
--- a/wezterm-gui/src/commands.rs
+++ b/wezterm-gui/src/commands.rs
@@ -763,6 +763,14 @@ pub fn derive_command_from_key_assignment(action: &KeyAssignment) -> Option<Comm
menubar: &["ThinkTerm"],
icon: Some("cod_settings_gear"),
},
+ QuitAndStopSessionServer => CommandDef {
+ brief: "Quit and Stop Session Server".into(),
+ doc: "Quits ThinkTerm and stops the background session server; the terminals in it end".into(),
+ keys: vec![],
+ args: &[ArgType::ActiveWindow],
+ menubar: &["ThinkTerm"],
+ icon: Some("md_power"),
+ },
CheckForUpdates => CommandDef {
brief: "Check for Updates...".into(),
doc: "Opens Settings on the Software Update page".into(),
@@ -2382,6 +2390,7 @@ fn compute_default_actions() -> Vec<KeyAssignment> {
HideApplication,
#[cfg(target_os = "macos")]
QuitApplication,
+ QuitAndStopSessionServer,
// ----------------- Shell
ToggleLiveOverview,
OpenSshHosts,
diff --git a/wezterm-gui/src/local_sessions.rs b/wezterm-gui/src/local_sessions.rs
index dad37e6f..5d8d1544 100644
--- a/wezterm-gui/src/local_sessions.rs
+++ b/wezterm-gui/src/local_sessions.rs
@@ -145,7 +145,7 @@ pub(crate) fn stop_background_server_when_off(config: &ConfigHandle) {
return;
}
let pid_file = config.daemon_options.pid_file();
- let Some(pid) = pid_of_server_holding(&pid_file) else {
+ if mux::session_server::pid_holding(&pid_file).is_none() {
log::warn!(
"local sessions: the setting is off but a server answers at {}; nothing holds {}, \
so it is left running",
@@ -153,43 +153,70 @@ pub(crate) fn stop_background_server_when_off(config: &ConfigHandle) {
pid_file.display()
);
return;
- };
+ }
log::info!(
- "local sessions: the setting is off; stopping the session server (pid {pid}) at {}",
+ "local sessions: the setting is off; stopping the session server at {}",
socket.display()
);
- if unsafe { libc::kill(pid as libc::pid_t, libc::SIGTERM) } != 0 {
- log::warn!(
- "local sessions: could not stop the session server (pid {pid}): {}",
- std::io::Error::last_os_error()
- );
- return;
+ match mux::session_server::stop(&pid_file, &socket, std::time::Duration::from_secs(5)) {
+ Ok(_) => {
+ std::fs::remove_file(&marker).ok();
+ }
+ Err(err) => log::warn!("local sessions: {err:#}"),
}
- std::fs::remove_file(&marker).ok();
}
#[cfg(not(unix))]
pub(crate) fn stop_background_server_when_off(_config: &ConfigHandle) {}
-/// The pid written in `pid_file`, when a running server holds its lock.
-#[cfg(unix)]
-fn pid_of_server_holding(pid_file: &std::path::Path) -> Option<u32> {
- use std::os::unix::io::AsRawFd as _;
- let file = std::fs::File::open(pid_file).ok()?;
- let locked_by_someone =
- unsafe { libc::flock(file.as_raw_fd(), libc::LOCK_EX | libc::LOCK_NB) } != 0;
- if !locked_by_someone {
- // We hold it now: no server does. The lock goes with the file.
- return None;
+/// The pid file and socket of the session server at the default socket.
+fn server_files(config: &ConfigHandle) -> (std::path::PathBuf, std::path::PathBuf) {
+ (
+ config.daemon_options.pid_file(),
+ config::RUNTIME_DIR.join(config::runtime_file_name("sock")),
+ )
+}
+
+/// Whether a session server runs at the default socket right now.
+pub(crate) fn server_running(config: &ConfigHandle) -> bool {
+ let (pid_file, socket) = server_files(config);
+ mux::session_server::is_running(&pid_file, &socket)
+}
+
+/// Stop the session server now, on the user's say-so: its terminals end
+/// with it. Whoever started it -- this setting, a hand-run
+/// `thinkterm-mux-server` -- it is the one at the default socket.
+pub(crate) fn stop_server_now(config: &ConfigHandle) -> anyhow::Result<mux::session_server::StopOutcome> {
+ let (pid_file, socket) = server_files(config);
+ let outcome = mux::session_server::stop(&pid_file, &socket, std::time::Duration::from_secs(5))?;
+ if !matches!(outcome, mux::session_server::StopOutcome::NotRunning) {
+ std::fs::remove_file(managed_marker()).ok();
+ }
+ Ok(outcome)
+}
+
+/// "Quit and stop the session server": the stop is done once the GUI's
+/// message loop has ended, so the windows close first and nothing here
+/// reconnects to a server that is going away.
+static STOP_AT_EXIT: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
+
+pub(crate) fn stop_server_at_exit() {
+ STOP_AT_EXIT.store(true, std::sync::atomic::Ordering::SeqCst);
+}
+
+pub(crate) fn finish_stop_at_exit(config: &ConfigHandle) {
+ if !STOP_AT_EXIT.swap(false, std::sync::atomic::Ordering::SeqCst) {
+ return;
+ }
+ match stop_server_now(config) {
+ Ok(outcome) => log::info!("session server at exit: {outcome:?}"),
+ Err(err) => log::warn!("stopping the session server at exit: {err:#}"),
}
- std::fs::read_to_string(pid_file)
- .ok()?
- .trim()
- .parse::<u32>()
- .ok()
- .filter(|pid| *pid > 1)
}
+/// The pid written in `pid_file`, when a running server holds its lock.
+#[cfg(unix)]
+
/// The host's domain name for this launch, if local sessions run in it.
pub(crate) fn host_domain_name() -> Option<String> {
if *FELL_BACK.lock().unwrap() {
diff --git a/wezterm-gui/src/main.rs b/wezterm-gui/src/main.rs
index cd4b6278..0ed2fa8f 100644
--- a/wezterm-gui/src/main.rs
+++ b/wezterm-gui/src/main.rs
@@ -218,7 +218,9 @@ fn run_ssh(opts: SshCommand) -> anyhow::Result<()> {
.detach();
maybe_show_configuration_error_window();
- gui.run_forever()
+ let outcome = gui.run_forever();
+ crate::local_sessions::finish_stop_at_exit(&config::configuration());
+ outcome
}
async fn async_run_serial(opts: SerialCommand) -> anyhow::Result<()> {
@@ -269,7 +271,9 @@ fn run_serial(config: config::ConfigHandle, opts: SerialCommand) -> anyhow::Resu
.detach();
maybe_show_configuration_error_window();
- gui.run_forever()
+ let outcome = gui.run_forever();
+ crate::local_sessions::finish_stop_at_exit(&config::configuration());
+ outcome
}
fn have_panes_in_domain_and_ws(domain: &Arc<dyn Domain>, workspace: &Option<String>) -> bool {
diff --git a/wezterm-gui/src/settings_window.rs b/wezterm-gui/src/settings_window.rs
index 2b61ed77..67e00c14 100644
--- a/wezterm-gui/src/settings_window.rs
+++ b/wezterm-gui/src/settings_window.rs
@@ -788,6 +788,7 @@ enum SettingsAction {
ToggleNotificationSounds,
ToggleRemoteUpdateKeepsSessions,
ToggleLocalSessionsViaMux,
+ StopSessionServer,
/// The ⓘ after a label; hovering it shows the text under this i18n key.
Hint(&'static str),
/// Turn one right-sidebar panel on or off.
@@ -1332,6 +1333,8 @@ struct SettingsUiState {
/// Two-step delete: the project id whose Delete button was clicked
/// once. A second click executes; any other action clears it.
confirm_delete_archived: Option<String>,
+ /// The stop-server row was pressed once; the next press stops it.
+ confirm_stop_server: bool,
input_diagnostics_copied_until: Option<Instant>,
/// The Update page's view of the on-disk check cache. Read when the
/// section is entered and when Check Now is clicked, never while
@@ -1383,6 +1386,7 @@ impl SettingsUiState {
web_tokens: Vec::new(),
shell_catalog: Vec::new(),
confirm_delete_archived: None,
+ confirm_stop_server: false,
input_diagnostics_copied_until: None,
update_status: None,
update_checked_until: None,
@@ -3475,15 +3479,22 @@ impl SettingsWindow {
/// Where the listener binds: every address when the page is to be
/// reachable from other devices, else the configured or default one.
fn web_bind_address(&self) -> String {
+ // The address the listener is up on comes first: one started by
+ // the CLI on another port is what the switch must keep.
let state = crate::web_settings::state();
let configured = state
.status
.as_ref()
- .and_then(|status| status.configured.first().cloned())
+ .and_then(|status| status.listening.first().or(status.configured.first()).cloned())
.unwrap_or_else(|| config::WebServer::default().bind_address);
+ let port = configured.rsplit_once(':').and_then(|(_, p)| p.parse::<u16>().ok()).unwrap_or(8088);
+ let wildcard = configured.starts_with("0.0.0.0:") || configured.starts_with("[::]:");
if self.native_settings.web.reachable {
- let port = configured.rsplit_once(':').and_then(|(_, p)| p.parse::<u16>().ok()).unwrap_or(8088);
format!("0.0.0.0:{port}")
+ } else if wildcard {
+ // Off means off the network: a listener found on the wildcard
+ // goes back to loopback on the same port.
+ format!("127.0.0.1:{port}")
} else {
configured
}
@@ -3836,6 +3847,30 @@ impl SettingsWindow {
conn.terminate_message_loop();
}
}
+ SettingsAction::StopSessionServer => {
+ self.ui.open_dropdown = None;
+ if !self.ui.confirm_stop_server {
+ self.ui.confirm_stop_server = true;
+ self.status = crate::i18n::tr("settings-status-stop-session-server-confirm");
+ } else {
+ self.ui.confirm_stop_server = false;
+ self.status = match crate::local_sessions::stop_server_now(&config::configuration()) {
+ Ok(mux::session_server::StopOutcome::Stopped { .. }) => {
+ crate::i18n::tr("settings-status-stop-session-server-done")
+ }
+ Ok(mux::session_server::StopOutcome::NotRunning) => {
+ crate::i18n::tr("settings-status-stop-session-server-none")
+ }
+ Ok(mux::session_server::StopOutcome::Lingering { .. }) => {
+ crate::i18n::tr("settings-status-stop-session-server-lingering")
+ }
+ Err(err) => settings_tr(
+ "settings-status-stop-session-server-error",
+ &[("error", format!("{err:#}"))],
+ ),
+ };
+ }
+ }
SettingsAction::ToggleBottomQuote => {
self.ui.open_dropdown = None;
self.native_settings.terminal.bottom_quote_enabled =
@@ -5384,9 +5419,11 @@ impl SettingsWindow {
let card_height = self.settings_card_height(row_count);
// One more card under the rows, where the platform can run local
// sessions in a server.
+ let server_running = crate::local_sessions::supported()
+ && crate::local_sessions::server_running(&config::configuration());
let sessions_card = crate::local_sessions::supported().then(|| {
let y = card_y + card_height + self.settings_section_card_gap();
- (y, self.compact_card_height(1))
+ (y, self.compact_card_height(if server_running { 2 } else { 1 }))
});
let content_bottom = sessions_card
.map(|(y, height)| y + height)
@@ -5491,6 +5528,25 @@ impl SettingsWindow {
self.native_settings.workspaces.local_sessions_via_mux,
SettingsAction::ToggleLocalSessionsViaMux,
)?;
+ if server_running {
+ let button = crate::i18n::tr(if self.ui.confirm_stop_server {
+ "settings-stop-session-server-confirm"
+ } else {
+ "settings-stop-session-server-now"
+ });
+ self.paint_button_setting_row_with_hint(
+ layers,
+ row_x,
+ sessions_card_y + self.ui_px(12.0) + self.compact_row_step(),
+ row_width,
+ self.compact_row_step(),
+ &crate::i18n::tr("settings-stop-session-server"),
+ "settings-stop-session-server-description",
+ &button,
+ SettingsAction::StopSessionServer,
+ true,
+ )?;
+ }
}
Ok(())
}
@@ -8907,6 +8963,75 @@ impl SettingsWindow {
/// A toggle row whose explanation lives behind an ⓘ after the label:
/// hovering the icon shows it in a bubble (`paint_hint_overlay`), so a
/// long one is neither cut short nor given a line of its own.
+ /// A single-line band like `paint_toggle_setting_row_with_hint`, with a
+ /// button on the right instead of a switch: the label and its hint
+ /// icon on the left, the button centred in the band.
+ fn paint_button_setting_row_with_hint(
+ &mut self,
+ layers: &mut TripleLayerQuadAllocator<'_>,
+ x: f32,
+ y: f32,
+ width: f32,
+ band_height: f32,
+ label: &str,
+ hint_key: &'static str,
+ button: &str,
+ action: SettingsAction,
+ draw_top_rule: bool,
+ ) -> anyhow::Result<()> {
+ let palette = self.palette();
+ let ui_font = Rc::clone(&self.ui_font);
+ if draw_top_rule {
+ self.paint_separator(layers, x, y, width)?;
+ }
+ let control_height = self.ui_px(CONTROL_HEIGHT);
+ let control_y = y + ((band_height - control_height) / 2.0).max(0.0);
+ let button_width = self.button_width_for_label(button, 120.0);
+ let button_x = x + width - button_width;
+ let cell_height = self.metrics.cell_size.height as f32;
+ let icon_size = self.ui_px(20.0);
+ let icon_gap = self.ui_px(8.0);
+ let text_width = (button_x - x - icon_size - icon_gap - 24.0).max(width * 0.45);
+
+ let label_y = control_y + (control_height - cell_height) / 2.0;
+ self.draw_text(layers, &ui_font, x, label_y, label, palette.text, text_width)?;
+ let shown = self.text_with_ellipsis(&ui_font, label, text_width);
+ let label_width = self.measure_text_width(&ui_font, &shown);
+
+ let icon_x = x + label_width + icon_gap;
+ let icon_y = label_y + (cell_height - icon_size) / 2.0;
+ let hint = SettingsAction::Hint(hint_key);
+ let reach = self.ui_px(6.0);
+ self.ui_context.push(
+ rect(
+ icon_x - reach,
+ icon_y - reach,
+ icon_size + reach * 2.0,
+ icon_size + reach * 2.0,
+ ),
+ WidgetKind::Hint,
+ hint,
+ );
+ let icon_hovered = self.ui.interaction.hovered == Some(hint);
+ self.draw_svg_icon(
+ layers,
+ SvgIcon::Info,
+ icon_x,
+ icon_y,
+ icon_size,
+ if icon_hovered {
+ palette.text
+ } else {
+ palette.muted_text
+ },
+ )?;
+ if icon_hovered {
+ self.ui.hint = Some((hint_key, icon_x, icon_y, icon_size));
+ }
+
+ self.draw_button(layers, button_x, control_y, button_width, button, action)
+ }
+
fn paint_toggle_setting_row_with_hint(
&mut self,
layers: &mut TripleLayerQuadAllocator<'_>,
diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rs
index d6455173..28f79525 100644
--- a/wezterm-gui/src/termwindow/mod.rs
+++ b/wezterm-gui/src/termwindow/mod.rs
@@ -4601,6 +4601,7 @@ impl TermWindow {
MuxNotification::SaveToDownloads { .. } => {
// Handled by frontend
}
+ MuxNotification::DefaultPaletteChanged => {}
MuxNotification::ThinkTermTreeChanged => {
// Server-side only; the remote tree reaches this process
// as a pushed ThinkTermTreeState PDU instead.
@@ -5210,6 +5211,7 @@ impl TermWindow {
| MuxNotification::WorkspaceRenamed { .. }
| MuxNotification::Empty
| MuxNotification::ThinkTermTreeChanged
+ | MuxNotification::DefaultPaletteChanged
| MuxNotification::ThinkTermSessionChanged
| MuxNotification::WindowWorkspaceChanged(_) => return true,
MuxNotification::Alert {
@@ -9112,6 +9114,12 @@ impl TermWindow {
OpenSettings => {
crate::settings_window::show();
}
+ QuitAndStopSessionServer => {
+ // The stop happens after the loop ends; the quit itself
+ // goes through the same confirmation as any quit.
+ crate::local_sessions::stop_server_at_exit();
+ return self.perform_key_assignment(pane, &QuitApplication);
+ }
CheckForUpdates => {
crate::settings_window::show_update_page();
}
diff --git a/wezterm/src/cli/color_schemes.rs b/wezterm/src/cli/color_schemes.rs
new file mode 100644
index 00000000..d2c3ca92
--- /dev/null
+++ b/wezterm/src/cli/color_schemes.rs
@@ -0,0 +1,72 @@
+//! `thinkterm cli color-schemes`: the built-in colour schemes, resolved to
+//! plain hex colours.
+//!
+//! Nothing here talks to a mux server: the table is compiled in. The browser
+//! client is the consumer -- `ci/build-web.sh` runs this into
+//! `thinkterm-web/www/schemes.json`, which the scheme picker fetches.
+
+use clap::Parser;
+use config::ColorSchemeFile;
+use serde::Serialize;
+use wezterm_term::color::ColorPalette;
+
+#[derive(Debug, Parser, Clone)]
+pub struct ColorSchemesCommand {
+ /// Print the schemes and their colours as a JSON array.
+ #[arg(long = "json")]
+ json: bool,
+}
+
+#[derive(Debug, Serialize)]
+struct Scheme {
+ name: String,
+ foreground: String,
+ background: String,
+ cursor_bg: String,
+ cursor_fg: String,
+ cursor_border: String,
+ selection_bg: String,
+ selection_fg: String,
+ ansi: Vec<String>,
+ brights: Vec<String>,
+}
+
+/// The scheme's own colours over the stock palette, so that a scheme that
+/// names only `ansi`/`foreground`/`background` still answers for the cursor
+/// and the selection.
+fn resolve(name: &str, toml: &str) -> anyhow::Result<Scheme> {
+ let scheme = ColorSchemeFile::from_toml_str(toml)?;
+ let p = ColorPalette::from(scheme.colors);
+ Ok(Scheme {
+ name: name.to_string(),
+ foreground: p.foreground.to_rgb_string(),
+ background: p.background.to_rgb_string(),
+ cursor_bg: p.cursor_bg.to_rgb_string(),
+ cursor_fg: p.cursor_fg.to_rgb_string(),
+ cursor_border: p.cursor_border.to_rgb_string(),
+ selection_bg: p.selection_bg.to_rgb_string(),
+ selection_fg: p.selection_fg.to_rgb_string(),
+ ansi: (0..8).map(|i| p.colors.0[i].to_rgb_string()).collect(),
+ brights: (8..16).map(|i| p.colors.0[i].to_rgb_string()).collect(),
+ })
+}
+
+impl ColorSchemesCommand {
+ pub fn run(&self) -> anyhow::Result<()> {
+ let mut schemes = Vec::with_capacity(config::scheme_data::SCHEMES.len());
+ for (name, toml) in config::scheme_data::SCHEMES.iter() {
+ match resolve(name, toml) {
+ Ok(scheme) => schemes.push(scheme),
+ Err(err) => log::warn!("color scheme {name:?} did not parse: {err:#}"),
+ }
+ }
+ if self.json {
+ println!("{}", serde_json::to_string(&schemes)?);
+ } else {
+ for scheme in &schemes {
+ println!("{}", scheme.name);
+ }
+ }
+ Ok(())
+ }
+}
diff --git a/wezterm/src/cli/mod.rs b/wezterm/src/cli/mod.rs
index d52f26ab..042195f2 100644
--- a/wezterm/src/cli/mod.rs
+++ b/wezterm/src/cli/mod.rs
@@ -8,6 +8,7 @@ mod activate_pane_direction;
mod activate_tab;
mod adjust_pane_size;
mod agent;
+mod color_schemes;
mod get_pane_direction;
mod get_text;
mod kill_pane;
@@ -21,6 +22,7 @@ mod set_tab_title;
mod set_window_title;
mod spawn_command;
mod split_pane;
+mod stop_server;
mod tls_creds;
mod web_server;
mod web_token;
@@ -179,9 +181,27 @@ Outputs the pane-id for the newly created pane on success"
/// Query agent statuses
#[command(name = "agent")]
Agent(agent::AgentCommand),
+
+ /// List the built-in color schemes and their colors
+ #[command(name = "color-schemes", rename_all = "kebab")]
+ ColorSchemes(color_schemes::ColorSchemesCommand),
+
+ /// Stop the background session server; the terminals in it end
+ #[command(name = "stop-server")]
+ StopServer(stop_server::StopServerCommand),
}
async fn run_cli_async(opts: &crate::Opt, cli: CliCommand) -> anyhow::Result<()> {
+ // The scheme table is compiled in; asking a server for it (or starting
+ // one) would only get in the way.
+ if let CliSubCommand::ColorSchemes(cmd) = &cli.sub {
+ return cmd.run();
+ }
+ // Stopping must not start one: handled before a client is made.
+ if let CliSubCommand::StopServer(cmd) = &cli.sub {
+ return cmd.run(&crate::init_config(opts)?);
+ }
+
let mut ui = mux::connui::ConnectionUI::new_headless();
let initial = true;
@@ -237,6 +257,9 @@ async fn run_cli_async(opts: &crate::Opt, cli: CliCommand) -> anyhow::Result<()>
CliSubCommand::RenameWorkspace(cmd) => cmd.run(client).await,
CliSubCommand::ZoomPane(cmd) => cmd.run(client).await,
CliSubCommand::Agent(cmd) => cmd.run(client).await,
+ CliSubCommand::ColorSchemes(_) | CliSubCommand::StopServer(_) => {
+ unreachable!("handled without a client above")
+ }
}
}
diff --git a/wezterm/src/cli/stop_server.rs b/wezterm/src/cli/stop_server.rs
new file mode 100644
index 00000000..8a1cd30c
--- /dev/null
+++ b/wezterm/src/cli/stop_server.rs
@@ -0,0 +1,47 @@
+//! `thinkterm cli stop-server`: stop the background session server at the
+//! default socket. Its terminals end with it; the next launch, `connect`
+//! or CLI command that needs it starts a fresh one.
+
+use anyhow::Context;
+use clap::Parser;
+use mux::session_server::StopOutcome;
+use std::io::IsTerminal;
+use std::time::Duration;
+
+#[derive(Debug, Parser, Clone)]
+pub struct StopServerCommand {
+ /// Stop without asking, even at a terminal.
+ #[arg(long)]
+ force: bool,
+}
+
+impl StopServerCommand {
+ pub fn run(&self, config: &config::ConfigHandle) -> anyhow::Result<()> {
+ let pid_file = config.daemon_options.pid_file();
+ let socket = config::RUNTIME_DIR.join(config::runtime_file_name("sock"));
+ let Some(pid) = mux::session_server::pid_holding(&pid_file) else {
+ println!("no session server is running (nothing holds {})", pid_file.display());
+ return Ok(());
+ };
+ if !self.force && std::io::stdin().is_terminal() {
+ eprint!(
+ "Stop the session server (pid {pid}) at {}? Every terminal in it ends. [y/N] ",
+ socket.display()
+ );
+ let mut answer = String::new();
+ std::io::stdin().read_line(&mut answer).context("reading the answer")?;
+ if !matches!(answer.trim(), "y" | "Y" | "yes") {
+ println!("left running");
+ return Ok(());
+ }
+ }
+ match mux::session_server::stop(&pid_file, &socket, Duration::from_secs(10))? {
+ StopOutcome::Stopped { pid } => println!("stopped the session server (pid {pid})"),
+ StopOutcome::Lingering { pid } => {
+ println!("asked the session server (pid {pid}) to stop; it is still shutting down")
+ }
+ StopOutcome::NotRunning => println!("no session server is running"),
+ }
+ Ok(())
+ }
+}