From 6f024ccc429d462ee96863e150bc3559e1719f8d Mon Sep 17 00:00:00 2001 From: Eric Engberg Date: Fri, 16 Oct 2026 00:07:38 -0500 Subject: [PATCH 1/8] fix(tui): keep Merge highlighted after cancelling the shell-command confirmation When an import adds a Custom Command, choosing Replace All or Merge first asks "Apply this import? It adds a shell command...". Cancel says "Go back to the preview without importing", but coming back from Merge put the highlight on Replace All and switched the preview to the Replace diff. The confirmation doesn't name the mode, so pressing Enter again and confirming applied Replace All, which resets every setting the file leaves out to its default. The confirmation replaces the preview's List, and the List mounted again at its first row, then reported that row as the new selection. Mount it on the mode the preview was showing instead. --- src/tui/components/ImportPreviewDialog.tsx | 5 ++ .../__tests__/ImportPreviewDialog.test.ts | 83 +++++++++++++++++++ 2 files changed, 88 insertions(+) diff --git a/src/tui/components/ImportPreviewDialog.tsx b/src/tui/components/ImportPreviewDialog.tsx index 33f8f8a0c..fd11fd529 100644 --- a/src/tui/components/ImportPreviewDialog.tsx +++ b/src/tui/components/ImportPreviewDialog.tsx @@ -228,6 +228,10 @@ export function ImportPreviewDialog({ } } + // The confirmation above unmounts the List, so it comes back on the mode + // the preview was showing rather than on the first row + const previewModeIndex = previewMode === 'merge' ? 1 : 0; + const diffRows: React.JSX.Element[] = []; for (const key of topLevelKeys) { @@ -315,6 +319,7 @@ export function ImportPreviewDialog({ items={items} onSelect={handleSelect} onSelectionChange={handleSelectionChange} + initialSelection={previewModeIndex} /> ); diff --git a/src/tui/components/__tests__/ImportPreviewDialog.test.ts b/src/tui/components/__tests__/ImportPreviewDialog.test.ts index 2184c3099..aaad3b108 100644 --- a/src/tui/components/__tests__/ImportPreviewDialog.test.ts +++ b/src/tui/components/__tests__/ImportPreviewDialog.test.ts @@ -67,6 +67,25 @@ function createMockStdout(): CapturedWriteStream { }); } +// An import that adds a shell command and leaves globalBold out, so Replace All +// resets globalBold and Merge keeps it +const COMMAND_IMPORT_CURRENT: Settings = { ...DEFAULT_SETTINGS, globalBold: true }; +const COMMAND_IMPORT_DATA: Settings = { + ...DEFAULT_SETTINGS, + flexMode: 'full-minus-40', + lines: [[{ id: 'c', type: 'custom-command', commandPath: 'echo hi' }], [], []] +}; +const COMMAND_IMPORT_VALIDATION = { + status: 'valid' as const, + data: COMMAND_IMPORT_DATA, + presentKeys: ['version', 'flexMode', 'lines'] as (keyof Settings)[] +}; + +// The globalBold row of the last frame drawn +function lastGlobalBoldRow(output: string): string | undefined { + return output.slice(output.lastIndexOf('globalBold:')).split('\n')[0]; +} + describe('ImportPreviewDialog helpers', () => { it('includes optional settings that exist only in the imported config', () => { const current: Settings = { ...DEFAULT_SETTINGS }; @@ -276,4 +295,68 @@ describe('ImportPreviewDialog helpers', () => { stderr.destroy(); } }); + + it('keeps Merge highlighted after Cancel on the shell-command confirmation', async () => { + const stdin = createMockStdin(); + const stdout = createMockStdout(); + const stderr = createMockStdout(); + const onApply = vi.fn(); + const instance = render(React.createElement(ImportPreviewDialog, { + validation: COMMAND_IMPORT_VALIDATION, + currentSettings: COMMAND_IMPORT_CURRENT, + onApply, + onCancel: () => undefined + }), { + stdin, + stdout, + stderr, + debug: true, + exitOnCtrlC: false, + patchConsole: false + }); + + try { + await waitFor(() => { + expect(stdout.getOutput()).toContain('▶ Replace All'); + }); + stdin.write('\u001B[B'); + await waitFor(() => { + expect(stdout.getOutput()).toContain('▶ Merge'); + }); + stdin.write('\r'); + await waitFor(() => { + expect(stdout.getOutput()).toContain('▶ Cancel'); + expect(stdout.getOutput()).toContain('Apply and run these commands'); + }); + + stdout.clearOutput(); + stdin.write('\r'); + await waitFor(() => { + expect(stdout.getOutput()).toContain('▶ Merge'); + expect(lastGlobalBoldRow(stdout.getOutput())).toBe('globalBold: true'); + }); + expect(stdout.getOutput()).not.toContain('▶ Replace All'); + + stdin.write('\r'); + await waitFor(() => { + expect(stdout.getOutput()).toContain('▶ Cancel'); + expect(stdout.getOutput()).toContain('Apply and run these commands'); + }); + stdin.write('\u001B[B'); + await waitFor(() => { + expect(stdout.getOutput()).toContain('▶ Apply and run these commands'); + }); + stdin.write('\r'); + await waitFor(() => { + expect(onApply).toHaveBeenCalledWith('merge'); + }); + expect(onApply).toHaveBeenCalledTimes(1); + } finally { + instance.unmount(); + instance.cleanup(); + stdin.destroy(); + stdout.destroy(); + stderr.destroy(); + } + }); }); From 91de0bb7a677b505b61cd782438945a56db7bd2b Mon Sep 17 00:00:00 2001 From: Eric Engberg Date: Fri, 16 Oct 2026 00:07:46 -0500 Subject: [PATCH 2/8] fix(tui): let Escape leave Import Preview and its shell-command confirmation Escape did nothing on Import Preview, on both the diff and the "Apply this import? It adds a shell command..." confirmation. The only way out was to arrow down to Cancel and press Enter. The Import Config path dialog one step earlier, and the other menus, go back on Escape, and docs/USAGE.md already says Escape returns from the confirmation to the preview. The dialog had no input handler of its own, and its List only handles the arrows and Enter. Escape now steps back one screen: from the confirmation to the preview, where the mode stays highlighted, and from the preview out of the import, as Cancel does. --- src/tui/components/ImportPreviewDialog.tsx | 15 ++- .../__tests__/ImportPreviewDialog.test.ts | 101 ++++++++++++++++++ 2 files changed, 115 insertions(+), 1 deletion(-) diff --git a/src/tui/components/ImportPreviewDialog.tsx b/src/tui/components/ImportPreviewDialog.tsx index fd11fd529..a1fdc70aa 100644 --- a/src/tui/components/ImportPreviewDialog.tsx +++ b/src/tui/components/ImportPreviewDialog.tsx @@ -1,6 +1,7 @@ import { Box, - Text + Text, + useInput } from 'ink'; import React, { useState } from 'react'; @@ -176,6 +177,18 @@ export function ImportPreviewDialog({ { label: 'Cancel', value: 'cancel' } ]; + // Escape steps back one screen: from the confirmation to the preview, then out + useInput((_, key) => { + if (!key.escape) { + return; + } + if (pendingMode) { + setPendingMode(null); + return; + } + onCancel(); + }); + function handleSelect(value: ImportMode | 'back'): void { if (value === 'cancel' || value === 'back') { onCancel(); diff --git a/src/tui/components/__tests__/ImportPreviewDialog.test.ts b/src/tui/components/__tests__/ImportPreviewDialog.test.ts index aaad3b108..e6f963c42 100644 --- a/src/tui/components/__tests__/ImportPreviewDialog.test.ts +++ b/src/tui/components/__tests__/ImportPreviewDialog.test.ts @@ -296,6 +296,107 @@ describe('ImportPreviewDialog helpers', () => { } }); + it('cancels the import when Escape is pressed on the preview', async () => { + const stdin = createMockStdin(); + const stdout = createMockStdout(); + const stderr = createMockStdout(); + const onApply = vi.fn(); + const onCancel = vi.fn(); + const instance = render(React.createElement(ImportPreviewDialog, { + validation: { + status: 'valid', + data: { ...DEFAULT_SETTINGS, globalBold: true }, + presentKeys: ['version', 'globalBold'] + }, + currentSettings: DEFAULT_SETTINGS, + onApply, + onCancel + }), { + stdin, + stdout, + stderr, + debug: true, + exitOnCtrlC: false, + patchConsole: false + }); + + try { + await waitFor(() => { + expect(stdout.getOutput()).toContain('▶ Replace All'); + }); + stdin.write('\u001B'); + await waitFor(() => { + expect(onCancel).toHaveBeenCalledTimes(1); + }); + expect(onApply).not.toHaveBeenCalled(); + } finally { + instance.unmount(); + instance.cleanup(); + stdin.destroy(); + stdout.destroy(); + stderr.destroy(); + } + }); + + it('goes back from the shell-command confirmation to the preview on Escape, still on Merge', async () => { + const stdin = createMockStdin(); + const stdout = createMockStdout(); + const stderr = createMockStdout(); + const onApply = vi.fn(); + const onCancel = vi.fn(); + const instance = render(React.createElement(ImportPreviewDialog, { + validation: COMMAND_IMPORT_VALIDATION, + currentSettings: COMMAND_IMPORT_CURRENT, + onApply, + onCancel + }), { + stdin, + stdout, + stderr, + debug: true, + exitOnCtrlC: false, + patchConsole: false + }); + + try { + await waitFor(() => { + expect(lastGlobalBoldRow(stdout.getOutput())).toBe('globalBold: true → false'); + }); + stdin.write('\u001B[B'); + await waitFor(() => { + expect(stdout.getOutput()).toContain('▶ Merge'); + expect(lastGlobalBoldRow(stdout.getOutput())).toBe('globalBold: true'); + }); + stdin.write('\r'); + await waitFor(() => { + expect(stdout.getOutput()).toContain('▶ Cancel'); + expect(stdout.getOutput()).toContain('Apply and run these commands'); + }); + + stdout.clearOutput(); + stdin.write('\u001B'); + await waitFor(() => { + expect(stdout.getOutput()).toContain('Changes that will be applied:'); + expect(stdout.getOutput()).toContain('▶ Merge'); + expect(lastGlobalBoldRow(stdout.getOutput())).toBe('globalBold: true'); + }); + expect(stdout.getOutput()).not.toContain('▶ Replace All'); + expect(onCancel).not.toHaveBeenCalled(); + + stdin.write('\u001B'); + await waitFor(() => { + expect(onCancel).toHaveBeenCalledTimes(1); + }); + expect(onApply).not.toHaveBeenCalled(); + } finally { + instance.unmount(); + instance.cleanup(); + stdin.destroy(); + stdout.destroy(); + stderr.destroy(); + } + }); + it('keeps Merge highlighted after Cancel on the shell-command confirmation', async () => { const stdin = createMockStdin(); const stdout = createMockStdout(); From 7eb19437648a5a0b8a19b558cd753c7b5ab8327a Mon Sep 17 00:00:00 2001 From: Eric Engberg Date: Fri, 16 Oct 2026 00:07:56 -0500 Subject: [PATCH 3/8] fix(tui): keep Color Level highlighted after the custom-colors warning In Terminal Options you press Enter on Color Level to cycle through the levels. With an ansi256 or hex widget color, leaving 256 Color or Truecolor first warns "Custom colors detected!". After Yes, No or Escape the highlight was back on Terminal Width, so the next Enter opened the Terminal Width screen instead of cycling on. The warning replaces the List, and the List mounted again at its first row. Remember the highlighted row, as Powerline Setup does around its confirmations, and mount the List on it. --- src/tui/components/TerminalOptionsMenu.tsx | 6 + .../__tests__/TerminalOptionsMenu.test.ts | 189 +++++++++++++++++- 2 files changed, 194 insertions(+), 1 deletion(-) diff --git a/src/tui/components/TerminalOptionsMenu.tsx b/src/tui/components/TerminalOptionsMenu.tsx index 6db5525d6..f846d69e1 100644 --- a/src/tui/components/TerminalOptionsMenu.tsx +++ b/src/tui/components/TerminalOptionsMenu.tsx @@ -71,6 +71,8 @@ export const TerminalOptionsMenu: React.FC = ({ }) => { const [showColorWarning, setShowColorWarning] = useState(false); const [pendingColorLevel, setPendingColorLevel] = useState<0 | 1 | 2 | 3 | null>(null); + // The warning unmounts the List, so it comes back on the row it was on + const [selectedItem, setSelectedItem] = useState(0); const handleSelect = (value: TerminalOptionsValue | 'back') => { if (value === 'back') { @@ -154,6 +156,10 @@ export const TerminalOptionsMenu: React.FC = ({ marginTop={1} items={buildTerminalOptionsItems(settings.colorLevel)} onSelect={handleSelect} + onSelectionChange={(_, index) => { + setSelectedItem(index); + }} + initialSelection={selectedItem} showBackButton={true} /> diff --git a/src/tui/components/__tests__/TerminalOptionsMenu.test.ts b/src/tui/components/__tests__/TerminalOptionsMenu.test.ts index 0b6d22ecd..17af036c8 100644 --- a/src/tui/components/__tests__/TerminalOptionsMenu.test.ts +++ b/src/tui/components/__tests__/TerminalOptionsMenu.test.ts @@ -1,15 +1,89 @@ +import chalk from 'chalk'; +import { render } from 'ink'; +import { PassThrough } from 'node:stream'; +import React, { useState } from 'react'; +import stripAnsi from 'strip-ansi'; import { describe, expect, - it + it, + vi } from 'vitest'; import { + DEFAULT_SETTINGS, + type Settings +} from '../../../types/Settings'; +import { waitFor } from '../../__tests__/helpers/wait-for-ink'; +import { + TerminalOptionsMenu, buildTerminalOptionsItems, getNextColorLevel, shouldWarnOnColorLevelChange } from '../TerminalOptionsMenu'; +class MockTtyStream extends PassThrough { + isTTY = true; + columns = 120; + rows = 40; + + setRawMode() { + return this; + } + + ref() { + return this; + } + + unref() { + return this; + } +} + +interface CapturedWriteStream extends NodeJS.WriteStream { + clearOutput: () => void; + getOutput: () => string; +} + +function createMockStdin(): NodeJS.ReadStream { + return new MockTtyStream() as unknown as NodeJS.ReadStream; +} + +function createMockStdout(): CapturedWriteStream { + const stream = new MockTtyStream(); + const chunks: string[] = []; + + stream.on('data', (chunk: Buffer | string) => { + chunks.push(chunk.toString()); + }); + + return Object.assign(stream as unknown as NodeJS.WriteStream, { + clearOutput() { + chunks.length = 0; + }, + getOutput() { + return stripAnsi(chunks.join('')); + } + }); +} + +// Truecolor with a hex widget color, so leaving Truecolor shows the custom-colors warning +const CUSTOM_COLOR_SETTINGS: Settings = { + ...DEFAULT_SETTINGS, + colorLevel: 3, + lines: [[{ id: '1', type: 'model', color: 'hex:FF8800' }], [], []] +}; + +function StatefulTerminalOptionsMenu({ onBack }: { onBack: (target?: string) => void }) { + const [settings, setSettings] = useState(CUSTOM_COLOR_SETTINGS); + + return React.createElement(TerminalOptionsMenu, { + settings, + onUpdate: setSettings, + onBack + }); +} + describe('TerminalOptionsMenu helpers', () => { it('cycles color levels in order', () => { expect(getNextColorLevel(0)).toBe(1); @@ -42,3 +116,116 @@ describe('TerminalOptionsMenu helpers', () => { expect(items[1]?.description).toContain('Truecolor'); }); }); + +describe('TerminalOptionsMenu', () => { + it('keeps Color Level highlighted after the custom-colors warning, so Enter cycles on', async () => { + const stdin = createMockStdin(); + const stdout = createMockStdout(); + const stderr = createMockStdout(); + const onBack = vi.fn(); + const chalkLevel = chalk.level; + const instance = render( + React.createElement(StatefulTerminalOptionsMenu, { onBack }), + { + stdin, + stdout, + stderr, + debug: true, + exitOnCtrlC: false, + patchConsole: false + } + ); + + try { + await waitFor(() => { + expect(stdout.getOutput()).toContain('▶ ◱ Terminal Width'); + }); + stdin.write('\u001B[B'); + await waitFor(() => { + expect(stdout.getOutput()).toContain('▶ ▓ Color Level (Truecolor)'); + }); + stdin.write('\r'); + await waitFor(() => { + expect(stdout.getOutput()).toContain('Custom colors detected'); + }); + + stdout.clearOutput(); + stdin.write('\r'); + await waitFor(() => { + expect(stdout.getOutput()).toContain('▶ ▓ Color Level (No Color)'); + }); + expect(stdout.getOutput()).not.toContain('▶ ◱ Terminal Width'); + + stdin.write('\r'); + await waitFor(() => { + expect(stdout.getOutput()).toContain('▶ ▓ Color Level (Basic)'); + }); + expect(onBack).not.toHaveBeenCalled(); + } finally { + chalk.level = chalkLevel; + instance.unmount(); + instance.cleanup(); + stdin.destroy(); + stdout.destroy(); + stderr.destroy(); + } + }); + + it('keeps Color Level highlighted after Escape on the custom-colors warning', async () => { + const stdin = createMockStdin(); + const stdout = createMockStdout(); + const stderr = createMockStdout(); + const onUpdate = vi.fn(); + const onBack = vi.fn(); + const instance = render( + React.createElement(TerminalOptionsMenu, { + settings: CUSTOM_COLOR_SETTINGS, + onUpdate, + onBack + }), + { + stdin, + stdout, + stderr, + debug: true, + exitOnCtrlC: false, + patchConsole: false + } + ); + + try { + await waitFor(() => { + expect(stdout.getOutput()).toContain('▶ ◱ Terminal Width'); + }); + stdin.write('\u001B[B'); + await waitFor(() => { + expect(stdout.getOutput()).toContain('▶ ▓ Color Level (Truecolor)'); + }); + stdin.write('\r'); + await waitFor(() => { + expect(stdout.getOutput()).toContain('Custom colors detected'); + }); + + stdout.clearOutput(); + stdin.write('\u001B'); + await waitFor(() => { + expect(stdout.getOutput()).toContain('▶ ▓ Color Level (Truecolor)'); + }); + expect(stdout.getOutput()).not.toContain('▶ ◱ Terminal Width'); + + stdout.clearOutput(); + stdin.write('\r'); + await waitFor(() => { + expect(stdout.getOutput()).toContain('Custom colors detected'); + }); + expect(onUpdate).not.toHaveBeenCalled(); + expect(onBack).not.toHaveBeenCalled(); + } finally { + instance.unmount(); + instance.cleanup(); + stdin.destroy(); + stdout.destroy(); + stderr.destroy(); + } + }); +}); From 76d104d99d0cc2e6d398acc74bedc3ff1d6676ea Mon Sep 17 00:00:00 2001 From: Eric Engberg Date: Fri, 16 Oct 2026 00:07:56 -0500 Subject: [PATCH 4/8] fix(tui): keep the cancelled setting highlighted in Configure Status Line Pressing Escape on a Refresh Interval or cache TTL prompt brought the list back with the highlight on the first row, Refresh Interval (or Git Cache TTL when Refresh Interval needs a newer Claude Code). Pressing Enter again opened a different setting from the one just left. Saving returns to the Main Menu, so only cancelling showed it. Each prompt replaces the List, and the List mounted again at its first row. Remember the highlighted row and mount the List on it. --- src/tui/components/RefreshIntervalMenu.tsx | 6 +++ .../__tests__/RefreshIntervalMenu.test.ts | 54 +++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/src/tui/components/RefreshIntervalMenu.tsx b/src/tui/components/RefreshIntervalMenu.tsx index 48d221093..f1e497f27 100644 --- a/src/tui/components/RefreshIntervalMenu.tsx +++ b/src/tui/components/RefreshIntervalMenu.tsx @@ -173,6 +173,8 @@ export const RefreshIntervalMenu: React.FC = ({ const [refreshInput, setRefreshInput] = useState(() => getRefreshInputValue(currentInterval)); const [ttlInput, setTtlInput] = useState(() => String(gitCacheTtlSeconds)); const [validationError, setValidationError] = useState(null); + // A prompt unmounts the List, so it comes back on the row that opened it + const [selectedItem, setSelectedItem] = useState(0); const ttlFields: Record = { gitCacheTtl: { @@ -346,6 +348,10 @@ export const RefreshIntervalMenu: React.FC = ({ setTtlInput(String(ttlFields[value].currentValue)); setEditingTtlField(value); }} + onSelectionChange={(_, index) => { + setSelectedItem(index); + }} + initialSelection={selectedItem} showBackButton={true} /> )} diff --git a/src/tui/components/__tests__/RefreshIntervalMenu.test.ts b/src/tui/components/__tests__/RefreshIntervalMenu.test.ts index ce24c708c..a3f8e4303 100644 --- a/src/tui/components/__tests__/RefreshIntervalMenu.test.ts +++ b/src/tui/components/__tests__/RefreshIntervalMenu.test.ts @@ -434,4 +434,58 @@ describe('RefreshIntervalMenu', () => { stderr.destroy(); } }); + + it('keeps the cancelled setting highlighted after Escape closes its prompt', async () => { + const stdin = createMockStdin(); + const stdout = createMockStdout(); + const stderr = createMockStdout(); + const onUpdate = vi.fn(); + const onCustomCommandCacheTtlUpdate = vi.fn(); + const onBack = vi.fn(); + const instance = render( + React.createElement(RefreshIntervalMenu, { + currentInterval: 10, + supportsRefreshInterval: true, + gitCacheTtlSeconds: 5, + customCommandCacheTtlSeconds: 7, + terminalWidthCacheTtlSeconds: 9, + onUpdate, + onGitCacheTtlUpdate: vi.fn(), + onCustomCommandCacheTtlUpdate, + onTerminalWidthCacheTtlUpdate: vi.fn(), + onBack + }), + { + stdin, + stdout, + stderr, + debug: true, + exitOnCtrlC: false, + patchConsole: false + } + ); + + try { + await waitFor(() => { + expect(stdout.getOutput()).toMatch(selected('Refresh Interval')); + }); + await press(stdin, stdout, '\u001B[B', selected('Git Cache TTL')); + await press(stdin, stdout, '\u001B[B', selected('Custom Command Cache TTL')); + await press(stdin, stdout, '\r', 'Enter custom command cache TTL in seconds (0-60):'); + + await press(stdin, stdout, '\u001B', selected('Custom Command Cache TTL')); + expect(stdout.getOutput()).not.toMatch(selected('Refresh Interval')); + + await press(stdin, stdout, '\r', 'Enter custom command cache TTL in seconds (0-60):'); + expect(onUpdate).not.toHaveBeenCalled(); + expect(onCustomCommandCacheTtlUpdate).not.toHaveBeenCalled(); + expect(onBack).not.toHaveBeenCalled(); + } finally { + instance.unmount(); + instance.cleanup(); + stdin.destroy(); + stdout.destroy(); + stderr.destroy(); + } + }); }); From ab05de19dffefc594efce08659626802a7f7020e Mon Sep 17 00:00:00 2001 From: Eric Engberg Date: Fri, 16 Oct 2026 00:07:56 -0500 Subject: [PATCH 5/8] fix(tui): keep the chosen update style highlighted when going back in Install MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In Install to Claude Code, going back from the package manager step (Escape or "← Back") highlighted Pinned global install again, with its description, even after choosing Auto-update. Pressing Enter then led into the pinned global install commands instead of the npx/bunx ones. The style List mounts again on the way back, and it always started on its first row. Start it on the style still held from the first pick. --- src/tui/components/InstallMenu.tsx | 3 +- .../components/__tests__/InstallMenu.test.tsx | 71 +++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/src/tui/components/InstallMenu.tsx b/src/tui/components/InstallMenu.tsx index 419bf5e52..75c63cce0 100644 --- a/src/tui/components/InstallMenu.tsx +++ b/src/tui/components/InstallMenu.tsx @@ -193,7 +193,8 @@ export const InstallMenu: React.FC = ({ setUpdateStyle(value); setStep('manager'); }} - initialSelection={0} + // Going back from the package manager step mounts this List again + initialSelection={updateStyle === 'auto-update' ? 1 : 0} showBackButton={true} /> diff --git a/src/tui/components/__tests__/InstallMenu.test.tsx b/src/tui/components/__tests__/InstallMenu.test.tsx index 339e76f71..272e6253b 100644 --- a/src/tui/components/__tests__/InstallMenu.test.tsx +++ b/src/tui/components/__tests__/InstallMenu.test.tsx @@ -280,4 +280,75 @@ describe('InstallMenu', () => { stderr.destroy(); } }); + + it('keeps Auto-update highlighted when going back from package manager selection', async () => { + const stdin = createMockStdin(); + const stdout = createMockStdout(); + const stderr = createMockStdout(); + const onCancel = vi.fn(); + const instance = render( + React.createElement(InstallMenu, { + commandAvailability: ALL_AVAILABLE, + currentVersion: '2.2.13', + existingStatusLine: null, + onSelect: vi.fn(), + onCancel + }), + { + stdin, + stdout, + stderr, + debug: true, + exitOnCtrlC: false, + patchConsole: false + } + ); + + try { + await waitFor(() => { + expect(stdout.getOutput()).toContain('▶ Pinned global install'); + }); + stdin.write('\u001B[B'); + await waitFor(() => { + expect(stdout.getOutput()).toContain('▶ Auto-update'); + }); + stdin.write('\r'); + await waitFor(() => { + expect(stdout.getOutput()).toContain('▶ npx -y ccstatusline@latest'); + }); + + // Escape + stdout.clearOutput(); + stdin.write('\u001B'); + await waitFor(() => { + expect(stdout.getOutput()).toContain('Select update style'); + expect(stdout.getOutput()).toContain('▶ Auto-update'); + }); + expect(stdout.getOutput()).not.toContain('▶ Pinned global install'); + + // The '← Back' row + stdin.write('\r'); + await waitFor(() => { + expect(stdout.getOutput()).toContain('▶ npx -y ccstatusline@latest'); + }); + stdin.write('\u001B[A'); + await waitFor(() => { + expect(stdout.getOutput()).toContain('▶ ← Back'); + }); + stdout.clearOutput(); + stdin.write('\r'); + await waitFor(() => { + expect(stdout.getOutput()).toContain('Select update style'); + expect(stdout.getOutput()).toContain('▶ Auto-update'); + }); + expect(stdout.getOutput()).not.toContain('▶ Pinned global install'); + expect(onCancel).not.toHaveBeenCalled(); + } finally { + instance.unmount(); + instance.cleanup(); + stdin.destroy(); + stdout.destroy(); + stderr.destroy(); + } + }); }); From 3e1c965c000d17f3fc517e4756638b49d77e492e Mon Sep 17 00:00:00 2001 From: Eric Engberg Date: Fri, 30 Oct 2026 11:55:46 -0500 Subject: [PATCH 6/8] test(import-preview): mark the command import with colorLevel instead of flexMode flexMode is going away with the Terminal Width options; any non-default key the import carries serves this fixture. --- src/tui/components/__tests__/ImportPreviewDialog.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tui/components/__tests__/ImportPreviewDialog.test.ts b/src/tui/components/__tests__/ImportPreviewDialog.test.ts index e6f963c42..aec659099 100644 --- a/src/tui/components/__tests__/ImportPreviewDialog.test.ts +++ b/src/tui/components/__tests__/ImportPreviewDialog.test.ts @@ -72,13 +72,13 @@ function createMockStdout(): CapturedWriteStream { const COMMAND_IMPORT_CURRENT: Settings = { ...DEFAULT_SETTINGS, globalBold: true }; const COMMAND_IMPORT_DATA: Settings = { ...DEFAULT_SETTINGS, - flexMode: 'full-minus-40', + colorLevel: 3, lines: [[{ id: 'c', type: 'custom-command', commandPath: 'echo hi' }], [], []] }; const COMMAND_IMPORT_VALIDATION = { status: 'valid' as const, data: COMMAND_IMPORT_DATA, - presentKeys: ['version', 'flexMode', 'lines'] as (keyof Settings)[] + presentKeys: ['version', 'colorLevel', 'lines'] as (keyof Settings)[] }; // The globalBold row of the last frame drawn From 0c1870b57343f1d7137913635649ab5a8d719335 Mon Sep 17 00:00:00 2001 From: Eric Engberg Date: Fri, 30 Oct 2026 18:33:16 -0500 Subject: [PATCH 7/8] test(terminal-options): start the warning tests on Color Level, now the first row With #765 Terminal Options lists only Color Level, so the two tests start there instead of stepping down from Terminal Width. --- .../components/__tests__/TerminalOptionsMenu.test.ts | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/tui/components/__tests__/TerminalOptionsMenu.test.ts b/src/tui/components/__tests__/TerminalOptionsMenu.test.ts index 52ff0a0bf..7c015fa09 100644 --- a/src/tui/components/__tests__/TerminalOptionsMenu.test.ts +++ b/src/tui/components/__tests__/TerminalOptionsMenu.test.ts @@ -133,10 +133,6 @@ describe('TerminalOptionsMenu', () => { ); try { - await waitFor(() => { - expect(stdout.getOutput()).toContain('▶ ◱ Terminal Width'); - }); - stdin.write('\u001B[B'); await waitFor(() => { expect(stdout.getOutput()).toContain('▶ ▓ Color Level (Truecolor)'); }); @@ -150,7 +146,6 @@ describe('TerminalOptionsMenu', () => { await waitFor(() => { expect(stdout.getOutput()).toContain('▶ ▓ Color Level (No Color)'); }); - expect(stdout.getOutput()).not.toContain('▶ ◱ Terminal Width'); stdin.write('\r'); await waitFor(() => { @@ -190,10 +185,6 @@ describe('TerminalOptionsMenu', () => { ); try { - await waitFor(() => { - expect(stdout.getOutput()).toContain('▶ ◱ Terminal Width'); - }); - stdin.write('\u001B[B'); await waitFor(() => { expect(stdout.getOutput()).toContain('▶ ▓ Color Level (Truecolor)'); }); @@ -207,7 +198,6 @@ describe('TerminalOptionsMenu', () => { await waitFor(() => { expect(stdout.getOutput()).toContain('▶ ▓ Color Level (Truecolor)'); }); - expect(stdout.getOutput()).not.toContain('▶ ◱ Terminal Width'); stdout.clearOutput(); stdin.write('\r'); From 57d551199af1039e20d8c06056df1d3c15cd8c63 Mon Sep 17 00:00:00 2001 From: Eric Engberg Date: Fri, 30 Oct 2026 18:53:02 -0500 Subject: [PATCH 8/8] fix(tui): drop the Terminal Options row change, which #765 made moot With #765, Color Level is Terminal Options' only setting and the custom-colors warning opens only from it, so the menu comes back on that row without help. --- src/tui/components/TerminalOptionsMenu.tsx | 6 - .../__tests__/TerminalOptionsMenu.test.ts | 179 +----------------- 2 files changed, 1 insertion(+), 184 deletions(-) diff --git a/src/tui/components/TerminalOptionsMenu.tsx b/src/tui/components/TerminalOptionsMenu.tsx index d716143d9..7be8cc903 100644 --- a/src/tui/components/TerminalOptionsMenu.tsx +++ b/src/tui/components/TerminalOptionsMenu.tsx @@ -66,8 +66,6 @@ export const TerminalOptionsMenu: React.FC = ({ }) => { const [showColorWarning, setShowColorWarning] = useState(false); const [pendingColorLevel, setPendingColorLevel] = useState<0 | 1 | 2 | 3 | null>(null); - // The warning unmounts the List, so it comes back on the row it was on - const [selectedItem, setSelectedItem] = useState(0); const handleSelect = (value: TerminalOptionsValue | 'back') => { if (value === 'back') { @@ -146,10 +144,6 @@ export const TerminalOptionsMenu: React.FC = ({ marginTop={1} items={buildTerminalOptionsItems(settings.colorLevel)} onSelect={handleSelect} - onSelectionChange={(_, index) => { - setSelectedItem(index); - }} - initialSelection={selectedItem} showBackButton={true} /> diff --git a/src/tui/components/__tests__/TerminalOptionsMenu.test.ts b/src/tui/components/__tests__/TerminalOptionsMenu.test.ts index 7c015fa09..5323bb558 100644 --- a/src/tui/components/__tests__/TerminalOptionsMenu.test.ts +++ b/src/tui/components/__tests__/TerminalOptionsMenu.test.ts @@ -1,89 +1,15 @@ -import chalk from 'chalk'; -import { render } from 'ink'; -import { PassThrough } from 'node:stream'; -import React, { useState } from 'react'; -import stripAnsi from 'strip-ansi'; import { describe, expect, - it, - vi + it } from 'vitest'; import { - DEFAULT_SETTINGS, - type Settings -} from '../../../types/Settings'; -import { waitFor } from '../../__tests__/helpers/wait-for-ink'; -import { - TerminalOptionsMenu, buildTerminalOptionsItems, getNextColorLevel, shouldWarnOnColorLevelChange } from '../TerminalOptionsMenu'; -class MockTtyStream extends PassThrough { - isTTY = true; - columns = 120; - rows = 40; - - setRawMode() { - return this; - } - - ref() { - return this; - } - - unref() { - return this; - } -} - -interface CapturedWriteStream extends NodeJS.WriteStream { - clearOutput: () => void; - getOutput: () => string; -} - -function createMockStdin(): NodeJS.ReadStream { - return new MockTtyStream() as unknown as NodeJS.ReadStream; -} - -function createMockStdout(): CapturedWriteStream { - const stream = new MockTtyStream(); - const chunks: string[] = []; - - stream.on('data', (chunk: Buffer | string) => { - chunks.push(chunk.toString()); - }); - - return Object.assign(stream as unknown as NodeJS.WriteStream, { - clearOutput() { - chunks.length = 0; - }, - getOutput() { - return stripAnsi(chunks.join('')); - } - }); -} - -// Truecolor with a hex widget color, so leaving Truecolor shows the custom-colors warning -const CUSTOM_COLOR_SETTINGS: Settings = { - ...DEFAULT_SETTINGS, - colorLevel: 3, - lines: [[{ id: '1', type: 'model', color: 'hex:FF8800' }], [], []] -}; - -function StatefulTerminalOptionsMenu({ onBack }: { onBack: (target?: string) => void }) { - const [settings, setSettings] = useState(CUSTOM_COLOR_SETTINGS); - - return React.createElement(TerminalOptionsMenu, { - settings, - onUpdate: setSettings, - onBack - }); -} - describe('TerminalOptionsMenu helpers', () => { it('cycles color levels in order', () => { expect(getNextColorLevel(0)).toBe(1); @@ -112,106 +38,3 @@ describe('TerminalOptionsMenu helpers', () => { expect(items[0]?.description).toContain('Truecolor'); }); }); - -describe('TerminalOptionsMenu', () => { - it('keeps Color Level highlighted after the custom-colors warning, so Enter cycles on', async () => { - const stdin = createMockStdin(); - const stdout = createMockStdout(); - const stderr = createMockStdout(); - const onBack = vi.fn(); - const chalkLevel = chalk.level; - const instance = render( - React.createElement(StatefulTerminalOptionsMenu, { onBack }), - { - stdin, - stdout, - stderr, - debug: true, - exitOnCtrlC: false, - patchConsole: false - } - ); - - try { - await waitFor(() => { - expect(stdout.getOutput()).toContain('▶ ▓ Color Level (Truecolor)'); - }); - stdin.write('\r'); - await waitFor(() => { - expect(stdout.getOutput()).toContain('Custom colors detected'); - }); - - stdout.clearOutput(); - stdin.write('\r'); - await waitFor(() => { - expect(stdout.getOutput()).toContain('▶ ▓ Color Level (No Color)'); - }); - - stdin.write('\r'); - await waitFor(() => { - expect(stdout.getOutput()).toContain('▶ ▓ Color Level (Basic)'); - }); - expect(onBack).not.toHaveBeenCalled(); - } finally { - chalk.level = chalkLevel; - instance.unmount(); - instance.cleanup(); - stdin.destroy(); - stdout.destroy(); - stderr.destroy(); - } - }); - - it('keeps Color Level highlighted after Escape on the custom-colors warning', async () => { - const stdin = createMockStdin(); - const stdout = createMockStdout(); - const stderr = createMockStdout(); - const onUpdate = vi.fn(); - const onBack = vi.fn(); - const instance = render( - React.createElement(TerminalOptionsMenu, { - settings: CUSTOM_COLOR_SETTINGS, - onUpdate, - onBack - }), - { - stdin, - stdout, - stderr, - debug: true, - exitOnCtrlC: false, - patchConsole: false - } - ); - - try { - await waitFor(() => { - expect(stdout.getOutput()).toContain('▶ ▓ Color Level (Truecolor)'); - }); - stdin.write('\r'); - await waitFor(() => { - expect(stdout.getOutput()).toContain('Custom colors detected'); - }); - - stdout.clearOutput(); - stdin.write('\u001B'); - await waitFor(() => { - expect(stdout.getOutput()).toContain('▶ ▓ Color Level (Truecolor)'); - }); - - stdout.clearOutput(); - stdin.write('\r'); - await waitFor(() => { - expect(stdout.getOutput()).toContain('Custom colors detected'); - }); - expect(onUpdate).not.toHaveBeenCalled(); - expect(onBack).not.toHaveBeenCalled(); - } finally { - instance.unmount(); - instance.cleanup(); - stdin.destroy(); - stdout.destroy(); - stderr.destroy(); - } - }); -});