From c511627e877962014736dab66f17245caea52a05 Mon Sep 17 00:00:00 2001 From: iamtoruk Date: Sat, 2 May 2026 11:54:58 -0700 Subject: [PATCH] Fix dashboard hang and ExperimentalWarning on Windows Strip Ink v7 DEC mode 2026 synchronized output markers (BSU/ESU) on Windows. ConPTY does not implement this protocol and buffers indefinitely, causing the dashboard to hang with no output. The patch intercepts standalone BSU/ESU writes on stdout while preserving full interactivity (keyboard, live refresh, cursor management). Fix ExperimentalWarning timing: the process.emit patch was restored synchronously in the finally block, but Node defers the warning via process.nextTick. Delay restore by one tick so the patch is still active when the warning fires. Closes #195 --- src/compare.tsx | 2 ++ src/dashboard.tsx | 2 ++ src/ink-win.ts | 14 ++++++++++++++ src/sqlite.ts | 2 +- 4 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/ink-win.ts diff --git a/src/compare.tsx b/src/compare.tsx index af1d147a..d8f407d4 100644 --- a/src/compare.tsx +++ b/src/compare.tsx @@ -7,6 +7,7 @@ import { formatCost } from './format.js' import { parseAllSessions } from './parser.js' import { getAllProviders } from './providers/index.js' import type { ProjectSummary, DateRange } from './types.js' +import { patchStdoutForWindows } from './ink-win.js' const ORANGE = '#FF8C42' const GREEN = '#5BF5A0' @@ -448,6 +449,7 @@ export async function renderCompare(range: DateRange, provider: string): Promise return } + patchStdoutForWindows() const projects = await parseAllSessions(range, provider) const { waitUntilExit } = render( process.exit(0)} /> diff --git a/src/dashboard.tsx b/src/dashboard.tsx index f84254d3..9233095d 100644 --- a/src/dashboard.tsx +++ b/src/dashboard.tsx @@ -14,6 +14,7 @@ import { CompareView } from './compare.js' import { getPlanUsageOrNull, type PlanUsage } from './plan-usage.js' import { planDisplayName } from './plans.js' import { join } from 'path' +import { patchStdoutForWindows } from './ink-win.js' type Period = 'today' | 'week' | '30days' | 'month' | 'all' type View = 'dashboard' | 'optimize' | 'compare' @@ -805,6 +806,7 @@ export async function renderDashboard(period: Period = 'week', provider: string const filteredProjects = filterProjectsByName(await parseAllSessions(range, provider), projectFilter, excludeFilter) const planUsage = await getPlanUsageOrNull() const isTTY = process.stdin.isTTY && process.stdout.isTTY + patchStdoutForWindows() if (isTTY) { const { waitUntilExit } = render( diff --git a/src/ink-win.ts b/src/ink-win.ts new file mode 100644 index 00000000..5fd4bade --- /dev/null +++ b/src/ink-win.ts @@ -0,0 +1,14 @@ +const BSU = '\x1b[?2026h' +const ESU = '\x1b[?2026l' +let patched = false + +export function patchStdoutForWindows(): void { + if (process.platform !== 'win32' || patched) return + patched = true + + const origWrite = process.stdout.write.bind(process.stdout) + process.stdout.write = function (chunk: unknown, ...args: unknown[]): boolean { + if (chunk === BSU || chunk === ESU) return true + return (origWrite as Function)(chunk, ...args) + } as typeof process.stdout.write +} diff --git a/src/sqlite.ts b/src/sqlite.ts index a1ca8127..4c8b93a0 100644 --- a/src/sqlite.ts +++ b/src/sqlite.ts @@ -71,7 +71,7 @@ function loadDriver(): boolean { `(underlying error: ${message})` return false } finally { - restore() + process.nextTick(restore) } }