diff --git a/src/cli/tui/panels/embedded-terminal.ts b/src/cli/tui/panels/embedded-terminal.ts index 5ade8bd..7a1d633 100644 --- a/src/cli/tui/panels/embedded-terminal.ts +++ b/src/cli/tui/panels/embedded-terminal.ts @@ -915,7 +915,7 @@ const buildCompactRenderableLines = ( } let statusIndex = -1; - for (let lookahead = 2; lookahead < Math.min(rows.length - index, 8); lookahead += 1) { + for (let lookahead = 2; lookahead < Math.min(rows.length - index, 50); lookahead += 1) { const candidate = rows[index + lookahead]; if (candidate !== undefined && isCommandStatusLine(candidate.plainText)) { commandBlock.push(candidate); @@ -1263,7 +1263,7 @@ export class EmbeddedTerminalPane { } let statusLine: string | null = null; - for (let lookahead = index + 2; lookahead < Math.min(rows.length, index + 10); lookahead += 1) { + for (let lookahead = index + 2; lookahead < Math.min(rows.length, index + 50); lookahead += 1) { const candidate = rows[lookahead]?.plainText ?? ""; if (isCommandStatusLine(candidate)) { statusLine = candidate; @@ -1375,7 +1375,7 @@ export class EmbeddedTerminalPane { } let hasStatusLine = false; - for (let lookahead = index + 2; lookahead < Math.min(rows.length, index + 8); lookahead += 1) { + for (let lookahead = index + 2; lookahead < Math.min(rows.length, index + 50); lookahead += 1) { if (isCommandStatusLine(rows[lookahead]?.plainText ?? "")) { hasStatusLine = true; break; diff --git a/src/cli/tui/terminal-emulator.ts b/src/cli/tui/terminal-emulator.ts index 04c0810..396139a 100644 --- a/src/cli/tui/terminal-emulator.ts +++ b/src/cli/tui/terminal-emulator.ts @@ -710,6 +710,17 @@ export class TerminalEmulatorBuffer { } if (sequence === "\u001b[?1049l") { + // Flush non-blank alternate screen rows to scrollback so codex's TUI + // output survives the screen switch (otherwise the content is discarded). + const altRows = this.alternateScreenBuffer; + let lastNonBlank = altRows.length - 1; + while (lastNonBlank >= 0 && altRows[lastNonBlank]!.every((cell) => cell.char.length === 0)) { + lastNonBlank -= 1; + } + for (let i = 0; i <= lastNonBlank; i += 1) { + this.pushScrollback(altRows[i]!); + } + this.alternateScreen = false; if (this.savedMainState) { this.mainScreen = this.savedMainState.screen.map((row) => cloneRow(row, this.columns));