fix(tui): make color-scheme detection fully covered and race-free
The color-scheme detection block left packages/ui/tui/src/index.ts below the 100% per-file coverage gate on three counts: the .then callback's `scheme === undefined` branch was reachable only via the 2s query timeout, the .catch only via a query-write failure, and the `editor.borderColor` assignment inside applyColorScheme was dead code — the next line's setStatus() immediately reassigns editor.borderColor. Register the scheme listener before firing the startup query so the query's own reply is delivered through the listener (the same path as later theme switches), which removes the redundant .then re-application and its uncoverable undefined branch, and closes the theoretical window where a synchronous reply lands before the listener exists. Drop the dead editor.borderColor line. Cover the rest: a same-scheme report (early return) and a terminal that throws on the query write (the swallowed .catch).
This commit is contained in:
@@ -1134,25 +1134,24 @@ export function createTuiChat(
|
||||
currentScheme = scheme
|
||||
Object.assign(palette, createPalette(resolved.color, scheme))
|
||||
Object.assign(mdTheme, markdownTheme(palette))
|
||||
editor.borderColor = text => palette.dim(text)
|
||||
rebuildTranscript(false)
|
||||
setStatus(agent.status)
|
||||
requestRender()
|
||||
}
|
||||
let currentScheme: TerminalColorScheme = 'dark'
|
||||
|
||||
// Detect the terminal's color scheme via device-status report. Most terminals
|
||||
// do not respond, so the promise settles with `undefined` and we keep the
|
||||
// dark-optimised palette.
|
||||
ui.queryTerminalColorScheme({ timeoutMs: 2000 }).then((scheme) => {
|
||||
if (scheme !== undefined) applyColorScheme(scheme)
|
||||
}).catch(() => {
|
||||
// Timeout or query failure — keep dark default.
|
||||
})
|
||||
|
||||
// Live-update when the user switches their terminal theme behind us.
|
||||
// Apply any color scheme the terminal reports. Registering before the query
|
||||
// below means even a synchronous reply reaches `applyColorScheme`; in practice
|
||||
// the startup query's reply is the only report, since dsh-tui leaves
|
||||
// unsolicited color-scheme notifications disabled.
|
||||
const disposeSchemeListener = ui.onTerminalColorSchemeChange(applyColorScheme)
|
||||
|
||||
// Ask the terminal for its color scheme via device-status report; the reply,
|
||||
// if any, arrives through the listener above. Most terminals do not respond,
|
||||
// so we keep the dark-optimised palette. Swallow a query-write failure for the
|
||||
// same reason.
|
||||
ui.queryTerminalColorScheme({ timeoutMs: 2000 }).catch(() => {})
|
||||
|
||||
const toggleTools = (): void => {
|
||||
toolsExpanded = !toolsExpanded
|
||||
for (const card of allToolCards) card.setExpanded(toolsExpanded)
|
||||
|
||||
Reference in New Issue
Block a user