feat(tui): relocated terminal restore registration to tui init
- Moved emergency terminal restore registration to the TUI terminal initialization logic. - Ensured terminal restoration triggers correctly on fatal exits by moving registration out of a side-effect-heavy barrel module. - Added a registration guard to prevent redundant postmortem handler attachments.
This commit is contained in:
@@ -1,6 +1,3 @@
|
||||
import { emergencyTerminalRestore } from "@oh-my-pi/pi-tui";
|
||||
import { postmortem } from "@oh-my-pi/pi-utils";
|
||||
|
||||
/**
|
||||
* Interactive mode and embeddable RPC client exports for the coding agent.
|
||||
*
|
||||
@@ -11,7 +8,3 @@ import { postmortem } from "@oh-my-pi/pi-utils";
|
||||
export * from "./interactive-mode";
|
||||
export * from "./rpc/rpc-client";
|
||||
export * from "./rpc/rpc-types";
|
||||
|
||||
postmortem.register("terminal-restore", () => {
|
||||
emergencyTerminalRestore();
|
||||
});
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Fixed
|
||||
|
||||
- Registered emergency terminal restore with the postmortem fatal path whenever a real terminal starts, so fatal exits restore raw mode/alternate screen on the normal CLI graph (previously the registration was a side effect of a barrel module the CLI never imported).
|
||||
|
||||
## [16.3.9] - 2026-07-06
|
||||
|
||||
### Fixed
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { dlopen, FFIType, ptr } from "bun:ffi";
|
||||
import * as fs from "node:fs";
|
||||
import { $env, isBunTestRuntime, isTerminalHeadless, logger } from "@oh-my-pi/pi-utils";
|
||||
import { $env, isBunTestRuntime, isTerminalHeadless, logger, postmortem } from "@oh-my-pi/pi-utils";
|
||||
import { setKittyProtocolActive } from "./keys";
|
||||
import { StdinBuffer } from "./stdin-buffer";
|
||||
import {
|
||||
@@ -161,6 +161,15 @@ let terminalEverStarted = false;
|
||||
// jumps to the viewport home, dropping the parent shell prompt on top of the
|
||||
// dead frame after exit.
|
||||
let altScreenActive = false;
|
||||
let terminalRestoreRegistered = false;
|
||||
|
||||
function registerPostmortemTerminalRestore(): void {
|
||||
if (terminalRestoreRegistered) return;
|
||||
terminalRestoreRegistered = true;
|
||||
postmortem.register("terminal-restore", () => {
|
||||
emergencyTerminalRestore();
|
||||
});
|
||||
}
|
||||
|
||||
/** Record alternate-screen state (called by the TUI on `?1049h`/`?1049l` writes). */
|
||||
export function setAltScreenActive(active: boolean): void {
|
||||
@@ -523,6 +532,7 @@ export class ProcessTerminal implements Terminal {
|
||||
// escapes never reach the developer's terminal during `bun test`.
|
||||
this.#headless = isTerminalHeadless();
|
||||
if (this.#headless) return;
|
||||
registerPostmortemTerminalRestore();
|
||||
|
||||
// Register for emergency cleanup
|
||||
activeTerminal = this;
|
||||
|
||||
Reference in New Issue
Block a user