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;