Keep auto WebGL for terminal table output

This commit is contained in:
Neil
2026-06-08 15:16:37 -07:00
parent 2338c42ef9
commit 51fd231a14
12 changed files with 139 additions and 121 deletions
@@ -4027,7 +4027,7 @@ describe('connectPanePty', () => {
disposable.dispose()
})
it('marks panes that receive Arabic output for DOM rendering', async () => {
it('does not switch renderers for Arabic output', async () => {
const { connectPanePty } = await import('./pty-connection')
const transport = createMockTransport()
const capturedDataCallback: { current: ((data: string) => void) | null } = { current: null }
@@ -4046,14 +4046,14 @@ describe('connectPanePty', () => {
capturedDataCallback.current?.('Arabic: السلام عليكم\r\n')
expect(manager.markPaneHasComplexScriptOutput).toHaveBeenCalledWith(1)
expect(manager.markPaneHasComplexScriptOutput).not.toHaveBeenCalled()
expect(pane.terminal.write).toHaveBeenCalledWith(
'Arabic: السلام عليكم\r\n',
expect.any(Function)
)
})
it('marks panes for DOM rendering when background SGR is split across PTY chunks', async () => {
it('does not switch renderers when background SGR is split across PTY chunks', async () => {
const { connectPanePty } = await import('./pty-connection')
const transport = createMockTransport()
const capturedDataCallback: { current: ((data: string) => void) | null } = { current: null }
@@ -4075,10 +4075,10 @@ describe('connectPanePty', () => {
capturedDataCallback.current?.(';2;52;52;52m codex block \x1b[0m\r\n')
expect(manager.markPaneHasComplexScriptOutput).toHaveBeenCalledWith(1)
expect(manager.markPaneHasComplexScriptOutput).not.toHaveBeenCalled()
})
it('keeps renderer-risk scan state across more than two split PTY chunks', async () => {
it('does not switch renderers across split background SGR PTY chunks', async () => {
const { connectPanePty } = await import('./pty-connection')
const transport = createMockTransport()
const capturedDataCallback: { current: ((data: string) => void) | null } = { current: null }
@@ -4101,7 +4101,7 @@ describe('connectPanePty', () => {
capturedDataCallback.current?.(';52;52m codex block \x1b[0m\r\n')
expect(manager.markPaneHasComplexScriptOutput).toHaveBeenCalledWith(1)
expect(manager.markPaneHasComplexScriptOutput).not.toHaveBeenCalled()
})
it('forces a viewport refresh for foreground Codex-style background redraws', async () => {
@@ -4130,7 +4130,7 @@ describe('connectPanePty', () => {
capturedDataCallback.current?.('\x1b[2J\x1b[H\x1b[48;2;52;52;52m codex block text \x1b[0m\r\n')
expect(manager.markPaneHasComplexScriptOutput).toHaveBeenCalledWith(1)
expect(manager.markPaneHasComplexScriptOutput).not.toHaveBeenCalled()
expect(refresh).toHaveBeenCalledWith(0, 39, true)
})
@@ -4163,7 +4163,7 @@ describe('connectPanePty', () => {
capturedDataCallback.current?.(';2;52;52;52m codex block text \x1b[0m\r\n')
expect(manager.markPaneHasComplexScriptOutput).toHaveBeenCalledWith(1)
expect(manager.markPaneHasComplexScriptOutput).not.toHaveBeenCalled()
expect(refresh).toHaveBeenCalledWith(0, 39, true)
})
@@ -4199,7 +4199,7 @@ describe('connectPanePty', () => {
expect(refresh).not.toHaveBeenCalled()
})
it('switches terminal UI drawing glyphs to the DOM renderer for release safety', async () => {
it('keeps terminal UI drawing glyphs on the active renderer', async () => {
const { connectPanePty } = await import('./pty-connection')
const transport = createMockTransport()
const capturedDataCallback: { current: ((data: string) => void) | null } = { current: null }
@@ -4218,7 +4218,7 @@ describe('connectPanePty', () => {
capturedDataCallback.current?.('⠋ Working ├─ file.ts █ progress \uE0B0 prompt\r\n')
expect(manager.markPaneHasComplexScriptOutput).toHaveBeenCalledWith(1)
expect(manager.markPaneHasComplexScriptOutput).not.toHaveBeenCalled()
expect(pane.terminal.write).toHaveBeenCalledWith(
'⠋ Working ├─ file.ts █ progress \uE0B0 prompt\r\n',
expect.any(Function)
@@ -18,7 +18,7 @@ import { safeFit } from '@/lib/pane-manager/pane-tree-ops'
import { getFitOverrideForPty, bindPanePtyId } from '@/lib/pane-manager/mobile-fit-overrides'
import { isPtyLocked } from '@/lib/pane-manager/mobile-driver-state'
import { isPaneReplaying, replayIntoTerminal } from './replay-guard'
import { terminalOutputPrefersDomRenderer } from '@/lib/pane-manager/terminal-complex-script'
import { terminalOutputPrefersRenderRefresh } from '@/lib/pane-manager/terminal-complex-script'
import {
PANE_PTY_RESIZE_HOLD_FLUSH_EVENT,
queuePanePtyResizeIfHeld,
@@ -1797,20 +1797,8 @@ export function connectPanePty(
pendingSpawnByPaneKey.set(pendingSpawnKey, trackedPromise)
}
let rendererRiskScanTail = ''
let foregroundRefreshRiskScanTail = ''
function terminalOutputChunkPrefersDomRenderer(data: string): boolean {
if (!data) {
return false
}
// Why: PTY chunk boundaries can split ASCII SGR sequences; keep a small
// tail so Codex background-color redraws still trigger the DOM fallback.
const scanData = rendererRiskScanTail ? `${rendererRiskScanTail}${data}` : data
rendererRiskScanTail = scanData.slice(-TERMINAL_RENDERER_RISK_SCAN_TAIL_CHARS)
return terminalOutputPrefersDomRenderer(scanData)
}
function trailingIncompleteCsiSequence(data: string): string {
const escapeIndex = data.lastIndexOf('\x1b[')
if (escapeIndex === -1) {
@@ -1834,7 +1822,7 @@ export function connectPanePty(
? `${foregroundRefreshRiskScanTail}${data}`
: data
const prefersRefresh =
scanData.includes('\x1b[') && terminalOutputPrefersDomRenderer(scanData)
scanData.includes('\x1b[') && terminalOutputPrefersRenderRefresh(scanData)
foregroundRefreshRiskScanTail = trailingIncompleteCsiSequence(scanData)
return prefersRefresh
}
@@ -1847,9 +1835,6 @@ export function connectPanePty(
// Why: drain any queued background bytes BEFORE the replay paint, so the
// scheduler's deferred drain cannot land older bytes on top of the replay.
flushTerminalOutput(pane.terminal)
// Why: replay rebuilds terminal pixels from serialized bytes. Keep it off
// WebGL so stale atlas/canvas cells cannot survive restore + scroll.
manager.markPaneHasComplexScriptOutput(pane.id)
replayIntoTerminal(pane, deps.replayingPanesRef, data)
}
@@ -1942,22 +1927,10 @@ export function connectPanePty(
transport.sendInput(mode2031SequenceFor(mode))
recordHiddenMode2031Reply()
}
function beforeTerminalOutputWrite(chunk: string): void {
// Why: hidden tab output is coalesced by the scheduler. Run per-byte
// renderer checks at the xterm write boundary so background PTY bursts
// do not spend foreground event-loop time scanning bytes we will delay.
if (terminalOutputChunkPrefersDomRenderer(chunk) || containsNonAsciiOutput(chunk)) {
manager.markPaneHasComplexScriptOutput(pane.id)
}
function beforeTerminalOutputWrite(): void {
recordTerminalOutput(pane.terminal)
}
function markRendererRiskForSkippedOutput(): void {
// Why: hidden-output recovery skips xterm.write entirely, so WebGL does
// not see the bytes it would later need to repaint during restore/scroll.
manager.markPaneHasComplexScriptOutput(pane.id)
}
function consumeForegroundImmediateBudget(dataLength: number): boolean {
const now = performance.now()
if (now - foregroundImmediateBudgetWindowStart > FOREGROUND_BUDGET_WINDOW_MS) {
@@ -2136,7 +2109,6 @@ export function connectPanePty(
}
function skipHiddenRendererOutput(data: string): void {
markRendererRiskForSkippedOutput()
respondToSkippedMode2031Subscribe(data)
markHiddenOutputRestoreNeeded()
if (hiddenOutputRestoreInFlight) {
@@ -200,7 +200,7 @@ describe('attachWebgl', () => {
expect(pane.terminal.loadAddon).toHaveBeenCalledTimes(1)
})
it('keeps auto-mode panes on DOM after complex-script output', () => {
it('keeps auto-mode panes on WebGL after complex-script output', () => {
const pane = createPane()
attachWebgl(pane)
@@ -210,13 +210,13 @@ describe('attachWebgl', () => {
markComplexScriptOutput(pane)
expect(pane.hasComplexScriptOutput).toBe(true)
expect(pane.webglAddon).toBeNull()
expect(webglMock.dispose).toHaveBeenCalledTimes(1)
expect(pane.webglAddon).not.toBeNull()
expect(webglMock.dispose).not.toHaveBeenCalled()
expect(pane.fitAddon.fit).not.toHaveBeenCalled()
attachWebgl(pane)
expect(pane.terminal.loadAddon).not.toHaveBeenCalled()
expect(pane.terminal.loadAddon).toHaveBeenCalledTimes(1)
})
it('keeps later auto panes on DOM after WebGL attach fails', () => {
@@ -234,7 +234,7 @@ describe('attachWebgl', () => {
expect(secondPane.terminal.loadAddon).not.toHaveBeenCalled()
})
it('allows explicit on mode to override complex-script DOM fallback', () => {
it('keeps forced WebGL on after complex-script output', () => {
const pane = createPane()
markComplexScriptOutput(pane)
@@ -106,8 +106,8 @@ export type ManagedPaneInternal = {
gpuRenderingEnabled: boolean
webglAttachmentDeferred: boolean
webglDisabledAfterContextLoss: boolean
// Why: complex-script shaping/RTL rendering is visibly wrong in xterm WebGL;
// keep auto-mode panes on DOM once their output proves they need browser text shaping.
// Why: expose complex-output diagnostics without changing renderer choice;
// auto renderer fallback is reserved for platform or WebGL failures.
hasComplexScriptOutput: boolean
webglAddon: WebglAddon | null
// Why nullable: ligatures are opt-in per font and toggleable at runtime,
@@ -62,15 +62,15 @@ describe('applyTerminalGpuAcceleration', () => {
expect(pane.fitAddon.fit).toHaveBeenCalledTimes(1)
})
it('returns complex-script panes to DOM when switching from forced WebGL back to auto', () => {
it('keeps complex-script panes on WebGL when switching from forced WebGL back to auto', () => {
const pane = createPane()
pane.hasComplexScriptOutput = true
const options: PaneManagerOptions = { terminalGpuAcceleration: 'on' }
applyTerminalGpuAcceleration([pane], options, 'auto')
expect(pane.webglAddon).toBeNull()
expect(pane.fitAddon.fit).toHaveBeenCalledTimes(1)
expect(pane.webglAddon).not.toBeNull()
expect(pane.fitAddon.fit).not.toHaveBeenCalled()
})
it('returns Linux panes to DOM when switching from forced WebGL back to auto', () => {
@@ -26,11 +26,7 @@ export function shouldUseTerminalWebgl(pane: ManagedPaneInternal): boolean {
// without raising context loss; tab switching only masks it by rebuilding WebGL.
return false
}
return (
pane.terminalGpuAcceleration === 'auto' &&
suggestedRendererType === undefined &&
!pane.hasComplexScriptOutput
)
return pane.terminalGpuAcceleration === 'auto' && suggestedRendererType === undefined
}
function refreshTerminalAfterWebglAttach(pane: ManagedPaneInternal): void {
@@ -82,12 +78,6 @@ export function disposeWebgl(
export function markComplexScriptOutput(pane: ManagedPaneInternal): void {
pane.hasComplexScriptOutput = true
if (pane.terminalGpuAcceleration !== 'auto') {
return
}
// Why: live TUIs often size tables before emitting complex glyphs. Refitting
// during this fallback can reflow the just-written frame under different metrics.
disposeWebgl(pane)
}
export function attachWebgl(pane: ManagedPaneInternal): void {
@@ -1,68 +1,70 @@
import { describe, expect, it } from 'vitest'
import { terminalOutputPrefersDomRenderer } from './terminal-complex-script'
import { terminalOutputPrefersRenderRefresh } from './terminal-complex-script'
describe('terminalOutputPrefersDomRenderer', () => {
describe('terminalOutputPrefersRenderRefresh', () => {
it('detects Arabic terminal output', () => {
expect(terminalOutputPrefersDomRenderer('Arabic: السلام عليكم')).toBe(true)
expect(terminalOutputPrefersRenderRefresh('Arabic: السلام عليكم')).toBe(true)
})
it('detects RTL scripts that need browser text shaping/order', () => {
expect(terminalOutputPrefersDomRenderer('Hebrew: שלום')).toBe(true)
expect(terminalOutputPrefersRenderRefresh('Hebrew: שלום')).toBe(true)
})
it('detects East Asian wide and fullwidth terminal output', () => {
expect(
terminalOutputPrefersDomRenderer('直接接请求本地 /api/mcp,带同一个 Bearer token,成功')
terminalOutputPrefersRenderRefresh('直接接请求本地 /api/mcp,带同一个 Bearer token,成功')
).toBe(true)
expect(terminalOutputPrefersDomRenderer('Japanese: ターミナル')).toBe(true)
expect(terminalOutputPrefersDomRenderer('Korean: 터미널')).toBe(true)
expect(terminalOutputPrefersDomRenderer('Fullwidth: ABC123')).toBe(true)
expect(terminalOutputPrefersRenderRefresh('Japanese: ターミナル')).toBe(true)
expect(terminalOutputPrefersRenderRefresh('Korean: 터미널')).toBe(true)
expect(terminalOutputPrefersRenderRefresh('Fullwidth: ABC123')).toBe(true)
})
it('keeps terminal drawing glyphs on WebGL', () => {
expect(terminalOutputPrefersDomRenderer('⠋ Working')).toBe(false)
expect(terminalOutputPrefersDomRenderer('├─ file.ts')).toBe(false)
expect(terminalOutputPrefersDomRenderer('█ progress')).toBe(false)
expect(terminalOutputPrefersDomRenderer('◆ status')).toBe(false)
expect(terminalOutputPrefersDomRenderer('\uE0B0 prompt')).toBe(false)
expect(terminalOutputPrefersRenderRefresh('⠋ Working')).toBe(false)
expect(terminalOutputPrefersRenderRefresh('├─ file.ts')).toBe(false)
expect(terminalOutputPrefersRenderRefresh('█ progress')).toBe(false)
expect(terminalOutputPrefersRenderRefresh('◆ status')).toBe(false)
expect(terminalOutputPrefersRenderRefresh('\uE0B0 prompt')).toBe(false)
})
it('detects malformed replacement characters', () => {
expect(terminalOutputPrefersDomRenderer('bad replacement �')).toBe(true)
expect(terminalOutputPrefersRenderRefresh('bad replacement �')).toBe(true)
})
it('detects emoji and variation sequences', () => {
expect(terminalOutputPrefersDomRenderer('status 🚀')).toBe(true)
expect(terminalOutputPrefersDomRenderer('developer 👩‍💻')).toBe(true)
expect(terminalOutputPrefersDomRenderer('heart ♥️')).toBe(true)
expect(terminalOutputPrefersRenderRefresh('status 🚀')).toBe(true)
expect(terminalOutputPrefersRenderRefresh('developer 👩‍💻')).toBe(true)
expect(terminalOutputPrefersRenderRefresh('heart ♥️')).toBe(true)
})
it('detects supplementary-plane complex-script ranges', () => {
expect(terminalOutputPrefersDomRenderer('Adlam: 𞤀')).toBe(true)
expect(terminalOutputPrefersDomRenderer('Medefaidrin: 𐻀')).toBe(true)
expect(terminalOutputPrefersRenderRefresh('Adlam: 𞤀')).toBe(true)
expect(terminalOutputPrefersRenderRefresh('Medefaidrin: 𐻀')).toBe(true)
})
it('detects split surrogate chunks so fallback is not lost at chunk boundaries', () => {
it('detects split surrogate chunks so refresh is not lost at chunk boundaries', () => {
const [high, low] = Array.from('🚀')[0].split('')
expect(terminalOutputPrefersDomRenderer(high)).toBe(true)
expect(terminalOutputPrefersDomRenderer(low)).toBe(true)
expect(terminalOutputPrefersRenderRefresh(high)).toBe(true)
expect(terminalOutputPrefersRenderRefresh(low)).toBe(true)
})
it('detects ASCII ANSI background SGR output before the non-ASCII fast path', () => {
expect(terminalOutputPrefersDomRenderer('\x1b[48;2;12;34;56m codex input \x1b[0m')).toBe(true)
expect(terminalOutputPrefersDomRenderer('\x1b[48:2::12:34:56m codex input \x1b[0m')).toBe(true)
expect(terminalOutputPrefersDomRenderer('\x1b[44m selected block \x1b[0m')).toBe(true)
expect(terminalOutputPrefersDomRenderer('\x1b[104m bright selected block \x1b[0m')).toBe(true)
expect(terminalOutputPrefersRenderRefresh('\x1b[48;2;12;34;56m codex input \x1b[0m')).toBe(true)
expect(terminalOutputPrefersRenderRefresh('\x1b[48:2::12:34:56m codex input \x1b[0m')).toBe(
true
)
expect(terminalOutputPrefersRenderRefresh('\x1b[44m selected block \x1b[0m')).toBe(true)
expect(terminalOutputPrefersRenderRefresh('\x1b[104m bright selected block \x1b[0m')).toBe(true)
})
it('does not disable WebGL for ordinary terminal output or ANSI controls alone', () => {
expect(terminalOutputPrefersDomRenderer('abc 123 ✓')).toBe(false)
expect(terminalOutputPrefersDomRenderer('\x1b[32mplain green\x1b[0m')).toBe(false)
expect(terminalOutputPrefersDomRenderer('\x1b[38;2;48;34;56m foreground only\x1b[0m')).toBe(
expect(terminalOutputPrefersRenderRefresh('abc 123 ✓')).toBe(false)
expect(terminalOutputPrefersRenderRefresh('\x1b[32mplain green\x1b[0m')).toBe(false)
expect(terminalOutputPrefersRenderRefresh('\x1b[38;2;48;34;56m foreground only\x1b[0m')).toBe(
false
)
expect(terminalOutputPrefersDomRenderer('\x1b[38:2::48:34:56m foreground only\x1b[0m')).toBe(
expect(terminalOutputPrefersRenderRefresh('\x1b[38:2::48:34:56m foreground only\x1b[0m')).toBe(
false
)
})
@@ -1,7 +1,6 @@
// Why: xterm WebGL renders from a glyph atlas; complex text and background
// repaint-heavy output are safer through the browser renderer path. Terminal
// UI drawing glyphs stay on WebGL because xterm's custom-glyph renderer is
// built for those ranges.
// Why: some foreground ANSI redraws paint background fills before glyphs settle.
// Detect those chunks so the terminal can force a narrow viewport refresh
// without switching renderers based on the text content.
const EMOJI_PRESENTATION_PATTERN = /\p{Emoji_Presentation}/u
const ESCAPE_CHARACTER = String.fromCharCode(0x1b)
const SGR_SEQUENCE_PATTERN = new RegExp(`${ESCAPE_CHARACTER}\\[([0-9:;]*)m`, 'g')
@@ -15,8 +14,8 @@ function isRendererRiskCodePoint(value: number): boolean {
isInRange(value, 0x0590, 0x08ff) ||
value === 0x200d ||
isInRange(value, 0x1100, 0x11ff) ||
// Why: xterm WebGL can leave stale atlas cells for East Asian wide glyphs
// on Windows; force browser text rendering before long CJK output paints.
// Why: keep this list available for targeted refresh decisions without
// turning Unicode output into a renderer-selection signal.
isInRange(value, 0x2e80, 0x9fff) ||
isInRange(value, 0xa960, 0xa97f) ||
isInRange(value, 0xac00, 0xd7ff) ||
@@ -87,7 +86,7 @@ function containsBackgroundSgr(data: string): boolean {
return false
}
export function terminalOutputPrefersDomRenderer(data: string): boolean {
export function terminalOutputPrefersRenderRefresh(data: string): boolean {
if (containsBackgroundSgr(data)) {
return true
}
@@ -419,6 +419,15 @@ async function forceDarkTerminalRendererPath(page: Page): Promise<void> {
theme: 'dark'
}
})
const worktreeId = state.activeWorktreeId
const tabId =
state.activeTabType === 'terminal'
? state.activeTabId
: worktreeId
? (state.activeTabIdByWorktree?.[worktreeId] ?? null)
: null
const manager = tabId ? window.__paneManagers?.get(tabId) : null
manager?.setTerminalGpuAcceleration('auto')
})
await page.waitForTimeout(250)
}
@@ -442,11 +451,21 @@ async function readTerminalRightEdgeOverpaint(page: Page): Promise<{
const pane = manager?.getActivePane?.() ?? manager?.getPanes?.()[0] ?? null
const screen = pane?.container.querySelector<HTMLElement>('.xterm-screen')
const rows = pane?.container.querySelector<HTMLElement>('.xterm-rows')
if (!pane || !screen || !rows) {
if (!pane || !screen) {
throw new Error('Active terminal DOM unavailable')
}
const screenRect = screen.getBoundingClientRect()
if (!rows) {
// Why: WebGL renders rows into a canvas; DOM-span overpaint checks only
// apply to the DOM renderer, while buffer wrap checks still run below.
return {
screenRight: screenRect.right,
offenderCount: 0,
offenders: []
}
}
const cellWidth = pane.terminal._core?._renderService?.dimensions?.css?.cell?.width ?? 0
const maxRight = screenRect.right + Math.max(1, cellWidth * 0.5)
const offenders = Array.from(rows.querySelectorAll<HTMLElement>('span'))
@@ -644,7 +663,6 @@ test.describe('Terminal long table scroll restore repro', () => {
expect(hiddenDebug?.hiddenRendererSkipCount).toBe(0)
const restoredPane = diagnostics.allPaneStates.find((paneState) => paneState.hasMarker)
expect(restoredPane).toBeDefined()
expect(restoredPane?.hasWebgl).toBe(false)
expect(diagnostics.cursorHidden).toBe(false)
await orcaPage.waitForTimeout(100)
const screenshotPath = testInfo.outputPath('long-table-after-switch-scroll.png')
@@ -711,8 +729,9 @@ test.describe('Terminal long table scroll restore repro', () => {
(window as LongTableDebugWindow).__terminalPtyOutputDebug?.snapshot()
)
expect(hiddenDebug?.hiddenRendererSkipCount).toBe(0)
expect(diagnostics.cols).toBeLessThanOrEqual(110)
expect(diagnostics.hasWebgl).toBe(false)
// Why: renderer cell metrics can land one column wider in headless runs;
// the content and screenshot assertions below cover the actual regression.
expect(diagnostics.cols).toBeLessThanOrEqual(112)
expect(diagnostics.cursorHidden).toBe(false)
const content = await getTerminalContent(orcaPage, 30_000)
@@ -794,7 +813,6 @@ test.describe('Terminal long table scroll restore repro', () => {
)
expect(hiddenDebug?.hiddenRendererSkipCount).toBe(0)
expect(diagnostics.cols).toBeLessThan(100)
expect(diagnostics.hasWebgl).toBe(false)
expect(diagnostics.cursorHidden).toBe(false)
testInfo.annotations.push({
type: 'real-emoji-table-overpaint',
@@ -132,7 +132,7 @@ async function readActiveTerminalRenderState(page: Page): Promise<TerminalRender
cursorAnimationDuration: cursorStyle?.animationDuration ?? '',
rowContainerClassName: rowContainer?.className ?? '',
xtermClassName: xterm?.className ?? '',
hasWebglCanvas: pane.container.querySelector('.xterm-webgl canvas') !== null,
hasWebglCanvas: renderingDiagnostics?.hasWebgl ?? false,
hasComplexScriptOutput: renderingDiagnostics?.hasComplexScriptOutput ?? false,
renderer: renderingDiagnostics?.hasWebgl ? 'webgl' : 'dom'
}
@@ -230,6 +230,15 @@ async function enableRiskyTerminalRendererPath(page: Page): Promise<void> {
theme: 'dark'
}
})
const worktreeId = state.activeWorktreeId
const tabId =
state.activeTabType === 'terminal'
? state.activeTabId
: worktreeId
? (state.activeTabIdByWorktree?.[worktreeId] ?? null)
: null
const manager = tabId ? window.__paneManagers?.get(tabId) : null
manager?.setTerminalGpuAcceleration('auto')
})
}
@@ -264,13 +273,14 @@ test.describe('OpenCode emoji table terminal rendering', () => {
description: JSON.stringify({ renderState, blinkSamples })
})
expect(renderState.hasComplexScriptOutput).toBe(true)
expect(renderState.renderer).toBe('dom')
expect(renderState.hasWebglCanvas).toBe(false)
expect(renderState.hasComplexScriptOutput).toBe(false)
expect(renderState.renderer).toBe(renderState.hasWebglCanvas ? 'webgl' : 'dom')
expect(renderState.coreCursorHidden).toBe(false)
expect(renderState.cursorVisibleElementCount).toBeGreaterThan(0)
expect(renderState.cursorBlink).toBe(true)
expect(renderState.cursorAnimationName).not.toBe('none')
if (!renderState.hasWebglCanvas) {
expect(renderState.cursorVisibleElementCount).toBeGreaterThan(0)
expect(renderState.cursorBlink).toBe(true)
expect(renderState.cursorAnimationName).not.toBe('none')
}
expect(blinkSamples.some((sample) => sample.paintedCursorCellCount > 0)).toBe(true)
expect(blinkSamples.some((sample) => sample.paintedCursorCellCount === 0)).toBe(true)
} finally {
@@ -265,11 +265,21 @@ async function readTerminalRightEdgeOverpaint(page: Page): Promise<{
}
const screen = pane.container.querySelector<HTMLElement>('.xterm-screen')
const rows = pane.container.querySelector<HTMLElement>('.xterm-rows')
if (!screen || !rows) {
if (!screen) {
throw new Error('Active terminal DOM unavailable')
}
const screenRect = screen.getBoundingClientRect()
if (!rows) {
// Why: WebGL renders rows into a canvas, so DOM-span overpaint checks only
// apply when the DOM renderer is active. Buffer wrap checks still run below.
return {
screenRight: screenRect.right,
offenderCount: 0,
offenders: []
}
}
const cellWidth = pane.terminal._core?._renderService?.dimensions?.css?.cell?.width ?? 0
const maxRight = screenRect.right + Math.max(1, cellWidth * 0.5)
const offenders = Array.from(rows.querySelectorAll<HTMLElement>('span'))
@@ -305,16 +315,33 @@ async function readVisibleSingerRowGeometry(page: Page): Promise<{
}
const screen = pane.container.querySelector<HTMLElement>('.xterm-screen')
const rows = pane.container.querySelector<HTMLElement>('.xterm-rows')
if (!screen || !rows) {
if (!screen) {
throw new Error('Active terminal DOM unavailable')
}
const screenRect = screen.getBoundingClientRect()
if (!rows) {
const buffer = pane.terminal.buffer.active
const line = Array.from(
{ length: pane.terminal.rows },
(_, row) => buffer.getLine(buffer.viewportY + row)?.translateToString(true) ?? ''
).find((text) => text.includes('Singer'))
if (!line) {
throw new Error('Singer row buffer line unavailable')
}
const cellWidth = pane.terminal._core?._renderService?.dimensions?.css?.cell?.width ?? 0
return {
cols: pane.terminal.cols,
screenRight: screenRect.right,
rowRight: screenRect.left + pane.terminal.cols * cellWidth,
rowText: line
}
}
const row = Array.from(rows.children).find((element) =>
(element.textContent ?? '').includes('Singer')
) as HTMLElement | undefined
if (!row) {
throw new Error('Singer row DOM unavailable')
}
const screenRect = screen.getBoundingClientRect()
const rowRect = row.getBoundingClientRect()
return {
cols: pane.terminal.cols,
@@ -417,7 +444,7 @@ test.describe('Terminal raw emoji table scroll restore repro', () => {
})
// Why: `auto` should start on the fast renderer for ordinary terminal output;
// the emoji table golden below proves complex output can still fall back safely.
// the emoji table golden below proves complex output does not disable it.
test('uses WebGL by default for ordinary terminal output when available @terminal-rendering-golden', async ({
orcaPage
}) => {
@@ -504,8 +531,8 @@ test.describe('Terminal raw emoji table scroll restore repro', () => {
contentType: 'image/png'
})
expect(diagnostics.hasComplexScriptOutput).toBe(true)
expect(diagnostics.hasWebgl).toBe(false)
expect(diagnostics.hasComplexScriptOutput).toBe(false)
expect(diagnostics.hasWebgl).toBe(await expectAutoWebgl(orcaPage))
expect(diagnostics.cursorHidden).toBe(false)
expect(overpaint.offenders).toEqual([])
expect(wrapDiagnostics.wrappedBoxLines).toEqual([])
+4 -4
View File
@@ -520,7 +520,7 @@ test.describe('Terminal Shortcuts', () => {
await orcaPage.keyboard.press('Backspace')
})
test('@headful Codex-like background output falls back to DOM rendering in auto mode', async ({
test('@headful Codex-like background output stays visible without disabling WebGL in auto mode', async ({
orcaPage
}) => {
const hasPane = await orcaPage.evaluate(() => {
@@ -592,13 +592,13 @@ test.describe('Terminal Shortcuts', () => {
}, marker),
{
timeout: 5_000,
message: 'Background SGR output did not switch auto mode to DOM rendering'
message: 'Background SGR output did not stay visible on the auto renderer'
}
)
.toEqual({
markerVisible: true,
hasComplexScriptOutput: true,
hasWebgl: false
hasComplexScriptOutput: false,
hasWebgl: true
})
})