From ed91a6364bf391d0c6523904264175bb25539455 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 29 Nov 2026 02:28:14 +0100 Subject: [PATCH] thing-tui: a restore that finds the writer held still gives back raw mode Per the steward's decision on thing2:finding:cut-tui-host.s2.restore-skipped-under-lock-leaves-raw; the double-panic case is run in a pty (red before this commit, green after). Co-Authored-By: Claude Opus 5.5 --- crates/thing-tui/src/terminal.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/crates/thing-tui/src/terminal.rs b/crates/thing-tui/src/terminal.rs index 1750d02..16bce9e 100644 --- a/crates/thing-tui/src/terminal.rs +++ b/crates/thing-tui/src/terminal.rs @@ -36,11 +36,18 @@ trait Restore: Send + Sync { impl Restore for Shared { fn restore(&self) { // The lock is held across a write: a panic inside one (on this thread) reaches the hook with - // it taken. Leave that restore to `Drop`, which runs once the unwinding has released it. + // it taken. The escape bytes are left to `Drop`, which runs once the unwinding has released + // the writer; raw mode needs no writer, so it is given back now, because `Drop` may never run + // (a second panic during the unwind, or an abort). let mut out = match self.out.try_lock() { Ok(out) => out, Err(TryLockError::Poisoned(poisoned)) => poisoned.into_inner(), - Err(TryLockError::WouldBlock) => return, + Err(TryLockError::WouldBlock) => { + if self.raw { + let _ = disable_raw_mode(); + } + return; + } }; if !self.entered.swap(false, Ordering::SeqCst) { return;