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(plugins): tell a panel the terminal beside it

RoversX90bfa1915c5f
diff --git a/docs/thinkterm/plugins.md b/docs/thinkterm/plugins.md
index 4734c3b2..dd8c2615 100644
--- a/docs/thinkterm/plugins.md
+++ b/docs/thinkterm/plugins.md
@@ -158,6 +158,9 @@ sorts first is used, and the other is shown as invalid.
- **Typing and keys.** A panel can have fields to type in, and be sent the
keys it takes while the user gives it the keyboard. See [Fields and the
keyboard](#fields-and-the-keyboard).
+- **The terminal beside its panel.** A panel is told how `thinkterm cli`
+ reaches it, to read what it shows and follow what runs in it. See [The
+ terminal beside a panel](#the-terminal-beside-a-panel).
- **Another machine's files.** When the terminal beside its panel runs on
another machine reached over SSH, a plugin has ThinkTerm run programs and
read files there. See [A terminal on another
@@ -265,10 +268,12 @@ how tall one is), whether the theme is dark, the language ThinkTerm speaks
pane in focus in its window -- when that terminal runs on the machine the
plugin runs on, and left out when there is none or it does not; `remote`
when it runs on another machine instead (see [A terminal on another
-machine](#a-terminal-on-another-machine)); `can_extend` (see [The
-extended view](#the-extended-view)); and `features`, what the client does
-besides drawing and sending clicks: `fields` when it shows fields, `keys`
-when it gives a panel the keyboard on the user's key (see [Fields and the
+machine](#a-terminal-on-another-machine)); `terminal`, how `thinkterm cli`
+reaches that terminal (see [The terminal beside a
+panel](#the-terminal-beside-a-panel)); `can_extend` (see [The extended
+view](#the-extended-view)); and `features`, what the client does besides
+drawing and sending clicks: `fields` when it shows fields, `keys` when it
+gives a panel the keyboard on the user's key (see [Fields and the
keyboard](#fields-and-the-keyboard)). It comes with `open` and again when any of it
changes -- no more than ten times a second while a window is resized, the
last always -- and the `rows` asked for after it are drawn for it. A click's
@@ -406,6 +411,45 @@ types next was meant for the panel, and goes nowhere until they press
Escape or press somewhere. What a stopped plugin, or one starting again,
last drew takes no typing: a press in its field gives it no keyboard.
+### The terminal beside a panel
+
+A panel's environment names the terminal beside it -- the pane in focus in
+its window -- as `thinkterm cli` on the plugin's machine reaches it, so the
+plugin reads what it shows and follows what runs in it with the command
+line any program has:
+
+```json
+"terminal":{"pane":12,"socket":"/home/user/.local/share/thinkterm/sock"}
+```
+
+For a terminal on the plugin's machine these are what the programs in it
+are given, `WEZTERM_PANE` and `WEZTERM_UNIX_SOCKET`: the plugin reaches it
+as they do. One on another machine is reached through the ThinkTerm that
+shows it, which passes on what is asked. Without a `socket` -- a browser's
+page cannot name a path on the server -- it is the session server on the
+plugin's machine, which `thinkterm cli --prefer-mux` finds. `terminal`
+names the pane in focus as soon as the user moves to it; `cwd` and `remote`
+follow once that pane has said where it is, so for a moment they can still
+be the last pane's. While the window has no pane in focus -- on the way to
+a new tab's -- it stays what it was.
+
+The plugin runs the `thinkterm` that ThinkTerm ships with, which
+`THINKTERM_CLI` names, with those two set:
+
+```sh
+WEZTERM_UNIX_SOCKET=/home/user/.local/share/thinkterm/sock WEZTERM_PANE=12 \
+ "$THINKTERM_CLI" cli --no-auto-start get-text --trim
+```
+
+A command about one pane is about that one when it names none: `get-text`
+reads what it shows. `list` says what runs in every pane, and `events`
+prints what happens in every one as it happens -- programs and commands
+finishing, titles, agents' status -- unless `--pane-id` names one.
+`thinkterm cli --help` lists the rest. The plugin's own standard input and
+output carry the protocol: a command it runs is given neither. In the Rust
+SDK, `view.cli()` is the command, ready for its arguments, with nothing on
+its input and its output piped back to the plugin.
+
### A terminal on another machine
When the terminal beside a panel runs on another machine reached over SSH --
@@ -478,9 +522,12 @@ The program starts with these environment variables, in its own directory:
| `THINKTERM_PLUGIN_DIR` | its directory |
| `THINKTERM_PLUGIN_DATA` | a directory for its own files, created before start |
| `THINKTERM_PLUGIN_API` | `2`, the newest this ThinkTerm speaks |
+| `THINKTERM_CLI` | the `thinkterm` program ThinkTerm ships with |
`WEZTERM_PANE` and `WEZTERM_UNIX_SOCKET` are not passed on: the pane or mux
the plugin server happened to be started from says nothing about a plugin.
+A panel's environment says which terminal is beside it (see [The terminal
+beside a panel](#the-terminal-beside-a-panel)).
The program's first line must be, with the API it speaks -- 1, or 2 for a
plugin with a panel -- and no newer than `THINKTERM_PLUGIN_API`: a ThinkTerm
@@ -585,6 +632,10 @@ fn main() -> std::io::Result<()> {
is drawn again when it comes and when it goes. A click in either draws
both again. `Input::Close` in an extended view is its close button:
`view.env.close` is where that is.
+- `view.cli()` is `thinkterm cli` aimed at the terminal beside panel
+ `view`, as `view.env.terminal` names it: `None` while there is none.
+ Running it waits for the program: run it from a thread of the plugin's
+ own.
- `Emitter::ask(view, machine, &ask, wait)` asks ThinkTerm to do something
on the machine the terminal beside panel `view` runs on, when that is
another -- `machine` from `view.env.remote` -- and waits for the answer.
diff --git a/plugins/diff/src/main.rs b/plugins/diff/src/main.rs
index b358bda7..43be67b5 100644
--- a/plugins/diff/src/main.rs
+++ b/plugins/diff/src/main.rs
@@ -941,6 +941,7 @@ mod tests {
locale: "en-US".into(),
cwd: Some(DIR.into()),
remote: None,
+ terminal: None,
can_extend: false,
close: None,
features: Vec::new(),
diff --git a/plugins/stocks/src/main.rs b/plugins/stocks/src/main.rs
index 7aa2437a..26404f54 100644
--- a/plugins/stocks/src/main.rs
+++ b/plugins/stocks/src/main.rs
@@ -665,6 +665,7 @@ mod tests {
locale: String::new(),
cwd: None,
remote: None,
+ terminal: None,
can_extend: false,
close: None,
features: vec![feature::FIELDS.into(), feature::KEYS.into()],
diff --git a/thinkterm-plugin-panel/src/lib.rs b/thinkterm-plugin-panel/src/lib.rs
index 81e9bc66..ed435b50 100644
--- a/thinkterm-plugin-panel/src/lib.rs
+++ b/thinkterm-plugin-panel/src/lib.rs
@@ -60,5 +60,5 @@ pub use scene::{
};
pub use wire::{
feature, Answer, Ask, Button, Bytes, Click, CloseButton, Entry, EntryKind, Env, Focus, Input,
- Key, Mods, MonoMetrics, Remote, Rows, RowsWanted, TextMetrics, Typed,
+ Key, Mods, MonoMetrics, Remote, Rows, RowsWanted, Terminal, TextMetrics, Typed,
};
diff --git a/thinkterm-plugin-panel/src/player.rs b/thinkterm-plugin-panel/src/player.rs
index 225e2d25..5c572871 100644
--- a/thinkterm-plugin-panel/src/player.rs
+++ b/thinkterm-plugin-panel/src/player.rs
@@ -365,7 +365,16 @@ impl Player {
if env == self.env {
return false;
}
+ // Another terminal beside the panel -- a pane in the same directory
+ // picked -- is news for the plugin, not another size.
+ let terminal_only = Env {
+ terminal: self.env.terminal.clone(),
+ ..env.clone()
+ } == self.env;
self.env = env;
+ if terminal_only {
+ return true;
+ }
// Rows are drawn for a size: the ones on show are asked for again,
// and what was asked for the old size is not taken when it comes,
// nor asked for if it is not yet.
@@ -1678,7 +1687,7 @@ pub fn field_radius(field: &Field) -> f32 {
mod tests {
use super::*;
use crate::scene::{Color, Jump, Token};
- use crate::wire::{MonoMetrics, TextMetrics};
+ use crate::wire::{MonoMetrics, Terminal, TextMetrics};
use serde_json::json;
fn env(width: f32, height: f32) -> Env {
@@ -1702,6 +1711,7 @@ mod tests {
locale: String::new(),
cwd: None,
remote: None,
+ terminal: None,
can_extend: false,
close: None,
features: Vec::new(),
@@ -2005,6 +2015,29 @@ mod tests {
assert!(!player.wanted().is_empty());
}
+ #[test]
+ fn another_terminal_beside_the_panel_is_news_but_not_a_new_size() {
+ let mut player = Player::new(env(300.0, 400.0));
+ player.frame(Frame {
+ items: vec![list(1_000, "a", None)],
+ ..Frame::default()
+ });
+ let asked = player.wanted();
+ answer_these(&mut player, &asked);
+ assert_eq!(texts(&player)[0], "row 0");
+ let beside = Env {
+ terminal: Some(Terminal {
+ pane: 7,
+ socket: None,
+ }),
+ ..env(300.0, 400.0)
+ };
+ assert!(player.set_env(beside.clone()), "the plugin is told");
+ assert!(player.wanted().is_empty(), "no rows are asked for again");
+ assert_eq!(texts(&player)[0], "row 0");
+ assert!(!player.set_env(beside));
+ }
+
#[test]
fn rows_are_asked_for_again_from_a_plugin_started_again() {
let mut player = Player::new(env(300.0, 400.0));
diff --git a/thinkterm-plugin-panel/src/wire.rs b/thinkterm-plugin-panel/src/wire.rs
index 9d21cb68..a710d9b7 100644
--- a/thinkterm-plugin-panel/src/wire.rs
+++ b/thinkterm-plugin-panel/src/wire.rs
@@ -36,6 +36,14 @@ pub struct Env {
/// ThinkTerm for ([`Ask`]).
#[serde(default, skip_serializing_if = "Option::is_none")]
pub remote: Option<Remote>,
+ /// That terminal, here or on another machine, as `thinkterm cli` on
+ /// the plugin's machine reaches it: to read what it shows and follow
+ /// what runs in it. It names the pane in focus as soon as the user
+ /// moves to it, before `cwd` and `remote` follow, and stays what it was
+ /// for the moment the window has none -- on the way to a new tab's.
+ /// None from a ThinkTerm that does not say.
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub terminal: Option<Terminal>,
/// Whether the panel would get its extended view were its frame to ask
/// for one: the client shows them, and has the room. So a plugin knows
/// whether to fit what it would put there into the panel itself. Never
@@ -71,6 +79,22 @@ impl Env {
}
}
+/// A terminal as `thinkterm cli` reaches it ([`Env::terminal`]). For one on
+/// the plugin's machine, these are what the programs in it are given --
+/// `WEZTERM_PANE` and `WEZTERM_UNIX_SOCKET` -- so the plugin reaches it as
+/// they do; one on another machine it reaches through the ThinkTerm that
+/// shows it, which passes on what is asked of it.
+#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
+pub struct Terminal {
+ /// Its pane id there, which `--pane-id` takes.
+ pub pane: u64,
+ /// The socket to reach it through, for `WEZTERM_UNIX_SOCKET`; none for
+ /// the session server on the plugin's machine, which `--prefer-mux`
+ /// finds -- a browser's page cannot name a path on the server.
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub socket: Option<String>,
+}
+
/// The other machine the terminal beside a panel runs on.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Remote {
diff --git a/thinkterm-plugin-sdk/src/lib.rs b/thinkterm-plugin-sdk/src/lib.rs
index 41d21d9a..294067c4 100644
--- a/thinkterm-plugin-sdk/src/lib.rs
+++ b/thinkterm-plugin-sdk/src/lib.rs
@@ -58,7 +58,8 @@
//! When the terminal beside a panel runs on another machine, the view's
//! [`Env::remote`](panel::Env::remote) says which, and the plugin has
//! ThinkTerm run programs and read files there with [`Emitter::ask`], over
-//! ThinkTerm's own connection to it.
+//! ThinkTerm's own connection to it. Wherever it runs, [`View::cli`] is
+//! `thinkterm cli` aimed at it: what it shows, what runs in it.
//!
//! The plugins built into ThinkTerm implement the same trait, and run
//! inside the plugin host instead of in a program of their own.
@@ -183,6 +184,53 @@ impl View {
pub fn panel(&self) -> u64 {
self.extends.unwrap_or(self.id)
}
+
+ /// `thinkterm cli`, aimed at the terminal beside the view
+ /// ([`Env::terminal`]): the arguments that follow are one of its
+ /// commands. One about a single pane, `get-text` say, is about that
+ /// terminal when it names none; `list` and `events` are about every
+ /// pane, and `events --pane-id` with the terminal's narrows it. What it
+ /// prints comes back to the plugin, through `output()` or the child's
+ /// own output, and it reads nothing: the plugin's own input and output
+ /// are ThinkTerm's. It starts no server. `None` while the view is
+ /// beside no terminal, or its ThinkTerm does not say which.
+ ///
+ /// ```no_run
+ /// # fn screen(view: &thinkterm_plugin_sdk::View) -> Option<String> {
+ /// let out = view.cli()?.args(["get-text", "--trim"]).output().ok()?;
+ /// String::from_utf8(out.stdout).ok()
+ /// # }
+ /// ```
+ pub fn cli(&self) -> Option<std::process::Command> {
+ let terminal = self.env.terminal.as_ref()?;
+ // The one ThinkTerm ships beside the plugin host; on the PATH for
+ // a plugin started some other way.
+ let program = std::env::var_os("THINKTERM_CLI").unwrap_or_else(|| "thinkterm".into());
+ let mut command = std::process::Command::new(program);
+ command.arg("cli").arg("--no-auto-start");
+ match &terminal.socket {
+ Some(socket) => {
+ command.env("WEZTERM_UNIX_SOCKET", socket);
+ }
+ None => {
+ command
+ .env_remove("WEZTERM_UNIX_SOCKET")
+ .arg("--prefer-mux");
+ }
+ }
+ command
+ .env("WEZTERM_PANE", terminal.pane.to_string())
+ .stdin(std::process::Stdio::null())
+ .stdout(std::process::Stdio::piped());
+ #[cfg(windows)]
+ {
+ // A console program, which would open a window of its own.
+ use std::os::windows::process::CommandExt;
+ const CREATE_NO_WINDOW: u32 = 0x0800_0000;
+ command.creation_flags(CREATE_NO_WINDOW);
+ }
+ Some(command)
+ }
}
/// What a call does besides answering, all of it sent once the answer is.
diff --git a/thinkterm-plugin-server/src/process.rs b/thinkterm-plugin-server/src/process.rs
index 563714e6..015ffb0b 100644
--- a/thinkterm-plugin-server/src/process.rs
+++ b/thinkterm-plugin-server/src/process.rs
@@ -154,6 +154,12 @@ impl Process {
// server with `--prefer-mux`.
.env_remove("WEZTERM_PANE")
.env_remove("WEZTERM_UNIX_SOCKET");
+ // The command line shipped beside the host, which reaches the
+ // terminal beside a panel (`Env::terminal`): a plugin need not
+ // find it on a PATH ThinkTerm was started with.
+ if let Some(cli) = cli_program() {
+ command.env("THINKTERM_CLI", cli);
+ }
#[cfg(windows)]
{
// The host has no console; a console program would open one.
@@ -533,6 +539,18 @@ fn create_private_dir(dir: &Path) -> std::io::Result<()> {
builder.create(dir)
}
+/// The `thinkterm` program beside this one, whose `cli` a plugin runs.
+fn cli_program() -> Option<PathBuf> {
+ let name = if cfg!(windows) {
+ "thinkterm.exe"
+ } else {
+ "thinkterm"
+ };
+ let exe = std::env::current_exe().ok()?;
+ let exe = exe.canonicalize().unwrap_or(exe);
+ Some(exe.with_file_name(name)).filter(|cli| cli.is_file())
+}
+
#[cfg(test)]
mod tests {
use super::*;
diff --git a/thinkterm-web/src/app.rs b/thinkterm-web/src/app.rs
index 99c4cced..284ee28f 100644
--- a/thinkterm-web/src/app.rs
+++ b/thinkterm-web/src/app.rs
@@ -4925,6 +4925,7 @@ impl<P: Platform, L: Link> App<P, L> {
let inner = &mut *self.inner.borrow_mut();
env.locale = thinkterm_i18n::current_locale().to_string();
env.cwd = Self::focused_cwd(inner);
+ env.terminal = Self::focused_terminal(inner);
// Its fields are the page's own; the keyboard comes to a panel
// through them, and no key of the page's gives it.
env.features = vec![thinkterm_plugin_panel::feature::FIELDS.to_string()];
@@ -4951,6 +4952,7 @@ impl<P: Platform, L: Link> App<P, L> {
let moved = {
let inner = &mut *self.inner.borrow_mut();
let cwd = Self::focused_cwd(inner);
+ let terminal = Self::focused_terminal(inner);
let locale = thinkterm_i18n::current_locale();
let mut moved = false;
let views = [
@@ -4958,9 +4960,13 @@ impl<P: Platform, L: Link> App<P, L> {
(&mut inner.plugin_extended_env, &mut inner.plugin_extended),
];
for (env, model) in views {
+ // The pane in focus not known for the moment, the one told
+ // stays.
+ let terminal = terminal.clone().or_else(|| env.as_ref().and_then(|env| env.terminal.clone()));
match env.as_mut() {
- Some(env) if env.cwd != cwd || env.locale != locale => {
+ Some(env) if env.cwd != cwd || env.terminal != terminal || env.locale != locale => {
env.cwd = cwd.clone();
+ env.terminal = terminal;
env.locale = locale.to_string();
if let Some(model) = model.as_mut() {
model.set_env(env.clone());
@@ -4977,6 +4983,16 @@ impl<P: Platform, L: Link> App<P, L> {
}
}
+ /// The pane in focus as `thinkterm cli` on the server's machine reaches
+ /// it, where the plugins the page reaches run: by the number the server
+ /// gave it, through the server, which the page knows no path for.
+ fn focused_terminal(inner: &Inner<P, L>) -> Option<thinkterm_plugin_panel::Terminal> {
+ inner.panes.contains_key(&inner.focused_pane).then(|| thinkterm_plugin_panel::Terminal {
+ pane: inner.focused_pane as u64,
+ socket: None,
+ })
+ }
+
/// The directory of the pane in focus, as a path on the server's
/// machine: where the plugins the page reaches run, and the terminal.
fn focused_cwd(inner: &Inner<P, L>) -> Option<String> {
diff --git a/thinkterm-web/src/plugin_panel.rs b/thinkterm-web/src/plugin_panel.rs
index d12aded8..9ecfa845 100644
--- a/thinkterm-web/src/plugin_panel.rs
+++ b/thinkterm-web/src/plugin_panel.rs
@@ -478,6 +478,7 @@ mod tests {
locale: String::new(),
cwd: None,
remote: None,
+ terminal: None,
can_extend: false,
close: None,
features: Vec::new(),
diff --git a/wezterm-gui/src/main.rs b/wezterm-gui/src/main.rs
index 22097bf7..192f8502 100644
--- a/wezterm-gui/src/main.rs
+++ b/wezterm-gui/src/main.rs
@@ -1379,12 +1379,22 @@ impl Publish {
}
}
+/// The socket this process serves `thinkterm cli` on, once it listens.
+static CLI_SOCKET: std::sync::OnceLock<PathBuf> = std::sync::OnceLock::new();
+
+/// Where `thinkterm cli` reaches this process: what the terminals it runs
+/// itself are given as `WEZTERM_UNIX_SOCKET`. None when it could not listen.
+pub(crate) fn cli_socket() -> Option<&'static std::path::Path> {
+ CLI_SOCKET.get().map(PathBuf::as_path)
+}
+
fn spawn_mux_server(unix_socket_path: PathBuf, should_publish: bool) -> anyhow::Result<()> {
let mut listener =
wezterm_mux_server_impl::local::LocalListener::with_domain(&config::UnixDomain {
socket_path: Some(unix_socket_path.clone()),
..Default::default()
})?;
+ let _ = CLI_SOCKET.set(unix_socket_path.clone());
std::thread::spawn(move || {
let name_holder;
if should_publish {
diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rs
index e9b006f7..1e4fad73 100644
--- a/wezterm-gui/src/termwindow/mod.rs
+++ b/wezterm-gui/src/termwindow/mod.rs
@@ -3319,6 +3319,10 @@ pub struct TermWindow {
/// The answer is the domain's, so another pane of one looked at already
/// has it at once. One entry a domain, dropped with the panel.
pub(crate) plugin_panel_domains: Vec<(DomainId, Option<bool>)>,
+ /// The pane in focus the plugin panel was last beside, and how
+ /// `thinkterm cli` reaches it: worked out once a pane, dropped with the
+ /// panel.
+ pub(crate) plugin_panel_terminal: Option<(PaneId, Option<thinkterm_plugin_panel::Terminal>)>,
/// How the machine the pane in focus runs on is reached when that is
/// another, for the plugin panel, and when that was found: for one
/// pane, found again every few seconds.
@@ -5164,6 +5168,7 @@ impl TermWindow {
plugin_panel_keys_held: false,
plugin_field_snapshot: None,
plugin_panel_domains: Vec::new(),
+ plugin_panel_terminal: None,
plugin_panel_reach: None,
right_sidebar_snippet_saving: false,
right_sidebar_note: crate::markdown_editor::NoteHostState::default(),
diff --git a/wezterm-gui/src/termwindow/ui/plugin_panel.rs b/wezterm-gui/src/termwindow/ui/plugin_panel.rs
index bf837e8e..b7f75847 100644
--- a/wezterm-gui/src/termwindow/ui/plugin_panel.rs
+++ b/wezterm-gui/src/termwindow/ui/plugin_panel.rs
@@ -65,7 +65,7 @@ use thinkterm_plugin_panel::player::{
use thinkterm_plugin_panel::{
feature, Align, Answer, Area, Ask, Bounds, Button, Bytes, CloseButton, Color, Cursor, Draw,
Drawn, Entry, EntryKind, Env, FieldPart, Font, Input, Line, Mods, MonoMetrics, Player, Rect,
- Remote, Size, Text, TextMetrics, Token,
+ Remote, Size, Terminal, Text, TextMetrics, Token,
};
use url::Url;
use wezterm_font::LoadedFont;
@@ -269,12 +269,14 @@ enum Status {
/// What a panel and its extended view are painted with in one frame: the
/// fonts, pixels to a unit, and where the terminal beside them is -- its
-/// directory here, or the other machine it runs on.
+/// directory here, or the other machine it runs on -- and how `thinkterm
+/// cli` reaches it.
pub(crate) struct PanelPaint {
fonts: PanelFonts,
scale: f32,
cwd: Option<String>,
remote: Option<Remote>,
+ terminal: Option<Terminal>,
}
/// The fonts a panel's text is set in, for one paint.
@@ -388,6 +390,7 @@ impl TermWindow {
scale: panel_scale(self.dimensions.dpi),
remote,
cwd,
+ terminal: self.plugin_panel_terminal(),
})
}
@@ -416,11 +419,13 @@ impl TermWindow {
scale,
cwd,
remote,
+ terminal,
} = paint;
let scale = *scale;
let mut env = panel_env(fonts, &chrome, content_width as f32, height as f32, scale);
env.cwd = cwd.clone();
env.remote = remote.clone();
+ env.terminal = terminal.clone();
env.can_extend = self.right_sidebar_plugin_can_extend();
self.follow_plugin_panel(plugin, env);
// The extended view goes once nothing asks for it, or there is no
@@ -483,11 +488,13 @@ impl TermWindow {
scale,
cwd,
remote,
+ terminal,
} = paint;
let scale = *scale;
let mut env = panel_env(fonts, &chrome, content_width as f32, height as f32, scale);
env.cwd = cwd.clone();
env.remote = remote.clone();
+ env.terminal = terminal.clone();
let (x, y, size) = close;
env.close = Some(CloseButton {
x: (x as f32 - content_x as f32) / scale,
@@ -794,6 +801,7 @@ impl TermWindow {
plugins::close_panel(panel.shown.view);
}
self.plugin_panel_domains.clear();
+ self.plugin_panel_terminal = None;
self.plugin_panel_reach = None;
}
@@ -856,6 +864,27 @@ impl TermWindow {
}
}
+ /// The terminal beside the panel as `thinkterm cli` reaches it, worked
+ /// out once for each pane in focus. While the window has none -- on
+ /// the way to a new tab's -- the one the panel was told of stays.
+ fn plugin_panel_terminal(&mut self) -> Option<Terminal> {
+ let Some(pane) = self.get_active_pane_no_overlay() else {
+ return self
+ .right_sidebar_plugin
+ .as_ref()
+ .and_then(|panel| panel.shown.player.env().terminal.clone());
+ };
+ let pane_id = pane.pane_id();
+ if let Some((beside, terminal)) = &self.plugin_panel_terminal {
+ if *beside == pane_id {
+ return terminal.clone();
+ }
+ }
+ let terminal = cli_terminal(&pane);
+ self.plugin_panel_terminal = Some((pane_id, terminal.clone()));
+ terminal
+ }
+
/// Whether the panes of domain `domain_id` run on this machine: `None`
/// until a look off this thread says, once for the domain. Another tab
/// of a domain the panel was beside already is known at once, so the
@@ -1946,6 +1975,28 @@ fn local_path(url: &Url) -> Option<String> {
(!path.is_empty()).then(|| path.to_string())
}
+/// Pane `pane` as `thinkterm cli` reaches it. One the session server keeps
+/// for this machine, by its number there and the server's socket: as the
+/// programs in it reach it. Any other by its number here and the socket
+/// this process serves the command line on -- which its programs are given
+/// too, and through which one on another machine is reached.
+fn cli_terminal(pane: &Arc<dyn Pane>) -> Option<Terminal> {
+ if crate::local_sessions::is_host_domain_id(pane.domain_id()) {
+ let client = pane.downcast_ref::<wezterm_client::pane::ClientPane>();
+ let host = crate::local_sessions::candidate(&config::configuration());
+ if let (Some(client), Some(host)) = (client, host) {
+ return Some(Terminal {
+ pane: client.remote_pane_id as u64,
+ socket: Some(host.socket_path().to_string_lossy().into_owned()),
+ });
+ }
+ }
+ Some(Terminal {
+ pane: pane.pane_id() as u64,
+ socket: Some(crate::cli_socket()?.to_string_lossy().into_owned()),
+ })
+}
+
/// What the plugin is told of a panel this big, set in `fonts`.
fn panel_env(fonts: &PanelFonts, chrome: &UiPalette, width: f32, height: f32, scale: f32) -> Env {
let text = |(_, metrics): &(Rc<LoadedFont>, RenderMetrics), size: f64| TextMetrics {
@@ -1969,6 +2020,7 @@ fn panel_env(fonts: &PanelFonts, chrome: &UiPalette, width: f32, height: f32, sc
locale: crate::i18n::current_locale().to_string(),
cwd: None,
remote: None,
+ terminal: None,
can_extend: false,
close: None,
features: vec![feature::FIELDS.to_string(), feature::KEYS.to_string()],