An enter racing a drop is refused until the terminal is given back. The race is forced with a
barrier inside the old guard's restore write, not a timing assumption.
Per thing2:ruling:tui-panic-restore-rule and thing2:finding:cut-tui-host.s3.drop-unregisters-before-restoring.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The hook, in every build, claims the restore once, writes it to a fresh io::stdout() handle and
turns raw mode off; Drop then has nothing left to write. Proven by pty probes (unwind with and
without a destructor panic, and an abort build): red before, green after.
Per thing2:ruling:tui-panic-restore-rule and thing2:finding:cut-tui-host.s3.abort-lock-held-leaves-screen-modes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A main-thread panic ends the process without running a guard held by a render thread, so the
owner-only rule left the terminal raw. restores_here takes is_main as well as abort, owner and here.
Per thing2:ruling:tui-panic-restore-rule and thing2:finding:cut-tui-host.s3.main-panic-with-guard-on-worker-leaves-raw.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A second enter or stdout() while one is alive fails with AlreadyExists, so nested and cross-thread
guards are impossible and no guard can take the terminal from another. The registry becomes one
slot; the several-guards unregistering and its test go. The refusal is pinned in their place, and
every test that builds a guard takes a lock so the suite's threads do not collide.
Per the steward's decision on thing2:finding:cut-tui-host.s2.guards-share-global-modes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A guard moved to a render thread follows its user: that thread's panic restores before its
message, and a panic on the thread that gave it away leaves it to the owner.
Per the steward's decision on thing2:finding:cut-tui-host.s2.guard-owner-is-the-constructing-thread.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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>
Nothing unwinds to Drop there, so the owner-only rule left a worker's panic to abort the process
with the terminal still raw. Unwind builds keep the owner-thread rule.
Per the steward's decision on thing2:finding:cut-tui-host.s2.abort-profile-worker-panic-leaves-raw.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Per the steward's decision on thing2:finding:cut-tui-host.s1.report-overclaims-and-misses-estimate;
the estimate is explained in the report.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
write_enter, write_restore and enter_without_raw_mode leave the public API; their tests are
unit tests in the crate. Every constructor that enters (enter, stdout) installs the hook. The
seams are pinned out of the API by compile_fail doctests.
Per the steward's decision on thing2:finding:cut-tui-host.s1.public-api-test-seams.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A guard registers when entered and unregisters on drop; the hook restores through the
registered guard's own writer, claims the restore once so unwinding does not repeat it, and
leaves a panic on any other thread, or after the drop, to the previous hook. Every
constructor that enters installs the hook.
Per the steward's decision on thing2:finding:cut-tui-host.s1.panic-hook-owner-blind.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>