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 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-11-29 02:28:14 +01:00
commit ed91a6364b

View file

@ -36,11 +36,18 @@ trait Restore: Send + Sync {
impl<W: Write + Send> Restore for Shared<W> {
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;