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.

fix(tui): ignore a canonical tab size no screen could have

RoversX5fa55ff1a5e0
diff --git a/Cargo.lock b/Cargo.lock
index 53aaed62..7e0b5a38 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -7932,6 +7932,7 @@ dependencies = [
"smol",
"termwiz 0.24.0",
"thinkterm-core",
+ "thinkterm-proto",
"toml 0.8.23",
"uuid",
"wezterm-client",
diff --git a/thinkterm-tui/Cargo.toml b/thinkterm-tui/Cargo.toml
index 9ebddfdb..9f2b52a6 100644
--- a/thinkterm-tui/Cargo.toml
+++ b/thinkterm-tui/Cargo.toml
@@ -21,6 +21,7 @@ serde_json.workspace = true
smol.workspace = true
termwiz.workspace = true
thinkterm-core.workspace = true
+thinkterm-proto.workspace = true
toml.workspace = true
uuid = { workspace = true, features = ["v4"] }
wezterm-client.workspace = true
diff --git a/thinkterm-tui/src/lib.rs b/thinkterm-tui/src/lib.rs
index 0354defd..2cfd3736 100644
--- a/thinkterm-tui/src/lib.rs
+++ b/thinkterm-tui/src/lib.rs
@@ -3298,7 +3298,7 @@ fn local_tab_size(
/// last measured — full-width output arrives and is then clipped to the width
/// the terminal had before it was resized.
fn adopt_local_tab_size(local_tab_id: TabId, size: TerminalSize) {
- if size.rows == 0 || size.cols == 0 {
+ if !adoptable_tab_size(&size) {
return;
}
if let Some(tab) = Mux::get().get_tab(local_tab_id) {
@@ -3306,6 +3306,13 @@ fn adopt_local_tab_size(local_tab_id: TabId, size: TerminalSize) {
}
}
+/// Whether a tab size may lay the tab out here. The canonical size comes off
+/// the wire, and one past what any screen holds would size every pane grid in
+/// the tab from it.
+fn adoptable_tab_size(size: &TerminalSize) -> bool {
+ size.rows > 0 && size.cols > 0 && thinkterm_proto::layout::terminal_size_is_plausible(size)
+}
+
async fn dispatch_actions(state: &mut TuiState) {
while let Some(action) = state.actions.pop_front() {
if let Err(err) = dispatch_action(state, action).await {
@@ -7183,6 +7190,22 @@ mod tests {
);
}
+ #[test]
+ fn a_tab_size_no_screen_could_have_is_not_adopted() {
+ use thinkterm_proto::layout::MAX_PANE_CELLS;
+ let size = |cols, rows| TerminalSize {
+ rows,
+ cols,
+ ..TerminalSize::default()
+ };
+ assert!(adoptable_tab_size(&size(100, 30)));
+ assert!(adoptable_tab_size(&size(MAX_PANE_CELLS, MAX_PANE_CELLS)));
+ assert!(!adoptable_tab_size(&size(0, 30)), "nothing to lay out");
+ // What a broken or hostile server could answer as the canonical size.
+ assert!(!adoptable_tab_size(&size(MAX_PANE_CELLS + 1, 30)));
+ assert!(!adoptable_tab_size(&size(100, usize::MAX)));
+ }
+
/// The loop that used to eat a row per layout, run five times.
///
/// Lay out at the tab size, spend a row on each pane's own bar, tell the