Skip to content

Claude's answers, rendered: Markdown, math, charts and diagrams drawn in the Claude Code terminal. Independent project, not affiliated with Anthropic.

TypeScript claude-code-mod

Command: a simpler theme listing, the subcommands on /iui, one in-use mark for every list

razorback16ebc893c2bc46
diff --git a/hooks/lib/command.ts b/hooks/lib/command.ts
index ed0ba4f..438de90 100644
--- a/hooks/lib/command.ts
+++ b/hooks/lib/command.ts
@@ -86,14 +86,21 @@ const UPDATES = ['on', 'off'] as const
// Typeahead rows for `/iui` arguments: the word at the cursor (`token`,
// starting at `start` in `text`) completed as a subcommand, a theme name, a
-// size, a width, a height, a grid or an updates value. Right after `theme`,
-// `size`, `width`, `height`, `grid` or `updates`, rows hold the word and its
-// argument, since the typeahead asks only while a word is at the cursor.
+// size, a width, a height, a grid or an updates value. The typeahead asks
+// only while a word is at the cursor (never after a space), and again after
+// a row is taken. So each word offers its next step while it is at the
+// cursor: `/iui` its subcommands, and `theme`, `size`, `width`, `height`,
+// `grid` or `updates` their values, as rows that hold the word too. A Tab
+// then takes a row and the next rows show at once. The value in use is
+// marked `in use` in each list, as in `/iui theme`.
export type Suggestion = { text: string; label?: string; description?: string }
export function commandSuggestions(
text: string, token: string, start: number,
o: { themes: readonly ThemeInfo[]; active: string; size: number; width?: Width; height?: Height; grid?: boolean; updates?: boolean },
): Suggestion[] {
+ if (token === '/iui' && /^\s*$/.test(text.slice(0, start))) {
+ return SUBCOMMANDS.map(c => ({ text: `/iui ${c.name}`, label: c.name, description: c.description }))
+ }
const head = /^\s*\/iui\s+/.exec(text)
if (!head || start < head[0].length) return []
const before = text.slice(head[0].length, start).trim().split(/\s+/).filter(Boolean).map(w => w.toLowerCase())
@@ -104,18 +111,18 @@ export function commandSuggestions(
.map(t => ({
text: `${lead}${t.name}`,
label: t.name,
- description: `${t.isUser ? 'user' : 'built-in'}${t.name === o.active ? ', active' : ''}${t.description ? `: ${t.description}` : ''}`,
+ description: [[t.isUser ? 'yours' : '', t.name === o.active ? 'in use' : ''].filter(Boolean).join(', '), t.description].filter(Boolean).join(': ') || undefined,
}))
const sizeRows = (prefix: string, lead: string) => SIZES
.filter(n => String(n).startsWith(prefix))
- .map(n => ({ text: `${lead}${n}`, label: `${n}%`, description: n === o.size ? 'current' : n === DEFAULT_SIZE ? 'the terminal text size' : undefined }))
+ .map(n => ({ text: `${lead}${n}`, label: `${n}%`, description: n === o.size ? 'in use' : n === DEFAULT_SIZE ? 'the terminal text size' : undefined }))
const width = o.width ?? DEFAULT_WIDTH
const widthRows = (prefix: string, lead: string) => WIDTHS
.filter(w => String(w).startsWith(prefix))
.map(w => ({
text: `${lead}${w}`,
label: w === 'full' ? 'full' : `${w} columns`,
- description: w === width ? 'current' : w === DEFAULT_WIDTH ? 'the default' : w === 'full' ? `the terminal width (${IMAGE_MAX_COLUMNS} at most)` : undefined,
+ description: w === width ? 'in use' : w === DEFAULT_WIDTH ? 'the default' : w === 'full' ? `the terminal width (${IMAGE_MAX_COLUMNS} at most)` : undefined,
}))
const height = o.height ?? DEFAULT_HEIGHT
const heightRows = (prefix: string, lead: string) => HEIGHTS
@@ -123,17 +130,17 @@ export function commandSuggestions(
.map(h => ({
text: `${lead}${h}`,
label: typeof h === 'number' ? `${h} rows` : h,
- description: h === height ? 'current' : h === DEFAULT_HEIGHT ? 'the default: half the terminal'
+ description: h === height ? 'in use' : h === DEFAULT_HEIGHT ? 'the default: half the terminal'
: h === 'full' ? `the terminal height less ${PICTURE_ROOM_ROWS} rows` : undefined,
}))
const grid = o.grid === false ? 'off' : 'on'
const gridRows = (prefix: string, lead: string) => GRIDS
.filter(g => g.startsWith(prefix))
- .map(g => ({ text: `${lead}${g}`, label: g, description: g === grid ? 'current' : g === 'on' ? 'the default' : undefined }))
+ .map(g => ({ text: `${lead}${g}`, label: g, description: g === grid ? 'in use' : g === 'on' ? 'the default' : undefined }))
const updates = o.updates === false ? 'off' : 'on'
const updateRows = (prefix: string, lead: string) => UPDATES
.filter(u => u.startsWith(prefix))
- .map(u => ({ text: `${lead}${u}`, label: u, description: u === updates ? 'current' : u === 'on' ? 'the default' : undefined }))
+ .map(u => ({ text: `${lead}${u}`, label: u, description: u === updates ? 'in use' : u === 'on' ? 'the default' : undefined }))
if (before.length === 0) {
if (word === 'theme') return themeRows('', 'theme ')
if (word === 'height') return heightRows('', 'height ')
diff --git a/hooks/lib/themes.ts b/hooks/lib/themes.ts
index 79160c6..e48333c 100644
--- a/hooks/lib/themes.ts
+++ b/hooks/lib/themes.ts
@@ -87,17 +87,21 @@ export function chooseTheme(themes: ReadonlyMap<string, ThemeInfo>, wanted: stri
return { name: BASE_THEME, dir: base?.dir ?? `${root}/render/themes/${BASE_THEME}`, isFallback: wanted !== BASE_THEME }
}
-// What `/iui theme` lists.
-export function themeListing(themes: ReadonlyMap<string, ThemeInfo>, problems: readonly ThemeProblem[], active: string, userDir: string): string {
- const lines = [...themes.values()]
- .sort((a, b) => a.name.localeCompare(b.name))
- .map(t => `${t.name === active ? '*' : '-'} ${t.name} (${t.isUser ? 'user' : 'built-in'})${t.description ? `: ${t.description}` : ''}`)
- const skipped = problems.map(p => ` skipped ${p.name} (${p.isUser ? 'user' : 'built-in'}): ${p.reason}`)
+// What `/iui theme` lists. The output shows as Markdown, so the theme in use
+// is marked in words (a `*` would turn into a list bullet), and the home
+// folder shows as `~`.
+export function themeListing(themes: ReadonlyMap<string, ThemeInfo>, problems: readonly ThemeProblem[], active: string, userDir: string, home = ''): string {
+ const marks = (t: { name: string; isUser: boolean }) => [t.isUser ? 'yours' : '', t.name === active ? 'in use' : ''].filter(Boolean).join(', ')
+ const item = (t: ThemeInfo) => `- ${t.name}${marks(t) ? ` (${marks(t)})` : ''}${t.description ? `: ${t.description}` : ''}`
+ const lines = [...themes.values()].sort((a, b) => a.name.localeCompare(b.name)).map(item)
+ const skipped = problems.map(p => `- ${p.name}${p.isUser ? ' (yours)' : ''}: not usable, ${p.reason}`)
+ const dir = home && userDir.startsWith(`${home}/`) ? `~${userDir.slice(home.length)}` : userDir
return [
- `Themes (* = active):`,
+ 'Themes:',
...(lines.length ? lines : ['- none found']),
...skipped,
- `User themes go in ${userDir}/<name>/theme.json. Switch with /iui theme <name>.`,
+ '',
+ `Change it with /iui theme <name>. Your own themes go in ${dir}/<name>/theme.json.`,
].join('\n')
}
diff --git a/hooks/register.tsx b/hooks/register.tsx
index 7b3f882..ef3c155 100644
--- a/hooks/register.tsx
+++ b/hooks/register.tsx
@@ -451,7 +451,7 @@ export const register: Register = on => {
// Typeahead for /iui arguments; the theme list is the last scan's.
on('prompt.autocomplete', async ($, e, next) => {
const got = await next(e)
- if (!/^\s*\/iui\s/.test(e.text)) return got
+ if (!/^\s*\/iui(\s|$)/.test(e.text)) return got
if (!S.themeChoices.length) await setUp($).catch(() => null)
await loadUpdates($)
const mine = commandSuggestions(e.text, e.token, e.start, {
@@ -544,8 +544,7 @@ export const register: Register = on => {
const { themes, problems, chosen } = await applyTheme($, ready.root, ready.home, wanted)
if (asked.name && chosen.isFallback) {
if (was) S.look = was
- const names = [...themes.keys()].sort().join(', ') || 'none'
- return { text: `No usable theme named ${asked.name}. Themes: ${names}.\n${themeListing(themes, problems, was?.name ?? DEFAULT_THEME, userThemesOf(ready.home))}` }
+ return { text: `No usable theme named ${asked.name}.\n\n${themeListing(themes, problems, was?.name ?? DEFAULT_THEME, userThemesOf(ready.home), ready.home)}` }
}
if (S.look?.name !== was?.name || S.look?.dir !== was?.dir || S.look?.stamp !== was?.stamp) {
// The theme's fonts set the column width and the code size.
@@ -553,8 +552,8 @@ export const register: Register = on => {
beginEpoch($)
}
if (asked.name) await storeSet($, 'theme-name', chosen.name)
- const head = asked.name ? `Intelligent UI uses the theme ${chosen.name}.\n` : ''
- return { text: `${head}${themeListing(themes, problems, chosen.name, userThemesOf(ready.home))}` }
+ const head = asked.name ? `Theme set to ${chosen.name}.\n\n` : ''
+ return { text: `${head}${themeListing(themes, problems, chosen.name, userThemesOf(ready.home), ready.home)}` }
}
const state = (await read($, isOn)) ? 'on' : 'off'
const ready = await setUp($)
diff --git a/render/themes/claude-code/theme.json b/render/themes/claude-code/theme.json
index ff55200..8795383 100644
--- a/render/themes/claude-code/theme.json
+++ b/render/themes/claude-code/theme.json
@@ -1,6 +1,6 @@
{
"name": "Claude Code",
- "description": "The colours of Claude Code's own Markdown in the terminal, with its dark and light themes",
+ "description": "Claude Code's own colours",
"source": "Claude Code 2.1.302: its dark and light theme palettes (text, inactive, subtle, promptBorder, permission for inline code and code blocks with no language, claude for the accent, its border colour for the code block frame, the subagent colours for drawings) and its Markdown renderer (dim quote bar, no code background, underlined h1, '-' bullets, 1. a. i. 1. numbers, highlight.js classes as ANSI colours). ANSI colours (links, code) are VS Code's terminal colours, MIT, see LICENSE: src/vs/workbench/contrib/terminal/common/terminalColorRegistry.ts",
"syntax": { "dark": "dark.tmTheme", "light": "light.tmTheme" },
"dark": {
diff --git a/render/themes/vscode-modern/theme.json b/render/themes/vscode-modern/theme.json
index 4027e9c..83c977e 100644
--- a/render/themes/vscode-modern/theme.json
+++ b/render/themes/vscode-modern/theme.json
@@ -1,6 +1,6 @@
{
"name": "VS Code Modern",
- "description": "VS Code's Markdown preview with Dark Modern and Light Modern",
+ "description": "VS Code, Dark Modern and Light Modern",
"source": "microsoft/vscode (MIT, see LICENSE): extensions/theme-defaults/themes/dark_modern.json and light_modern.json (colours); every other value comes from the vscode theme (markdown.css, highlight.css)",
"dark": {
"fg": "#cccccc",
diff --git a/render/themes/vscode/theme.json b/render/themes/vscode/theme.json
index 6e74835..b4537cb 100644
--- a/render/themes/vscode/theme.json
+++ b/render/themes/vscode/theme.json
@@ -1,6 +1,6 @@
{
"name": "VS Code",
- "description": "VS Code's Markdown preview with the default themes, Dark+ and Light+",
+ "description": "VS Code, Dark+ and Light+",
"source": "microsoft/vscode (MIT, see LICENSE): extensions/markdown-language-features/media/markdown.css (sizes, spacing), media/highlight.css (code colours, in dark.tmTheme and light.tmTheme), src/vs/platform/theme/common/colors/baseColors.ts (textPreformat, textCodeBlock, textBlockQuote, textLink defaults), extensions/theme-defaults/themes/dark_vs.json and light_vs.json (editor and widget colours)",
"syntax": { "dark": "dark.tmTheme", "light": "light.tmTheme" },
"fonts": {
diff --git a/tests/command.test.ts b/tests/command.test.ts
index 2155e94..0925723 100644
--- a/tests/command.test.ts
+++ b/tests/command.test.ts
@@ -26,50 +26,57 @@ test('right after theme or size, rows hold the word and its argument', () => {
const rows = at('/iui theme')
expect(rows.map(r => r.text)).toEqual(['theme github-light', 'theme nord', 'theme vscode', 'theme vscode-modern'])
expect(rows.map(r => r.label)).toEqual(['github-light', 'nord', 'vscode', 'vscode-modern'])
- expect(rows[3]!.description).toBe('built-in, active: default look')
- expect(rows[1]!.description).toBe('user: my nord')
+ expect(rows[3]!.description).toBe('in use: default look')
+ expect(rows[1]!.description).toBe('yours: my nord')
expect(at('/iui size').map(r => r.text)).toContain('size 150')
const widths = at('/iui width')
expect(widths.map(r => r.text)).toEqual(['width 80', 'width 100', 'width 120', 'width 160', 'width 200', 'width full'])
- // full is the default; with no width given, it is current.
- expect(widths.at(-1)!.description).toBe('current')
+ // full is the default; with no width given, it is in use.
+ expect(widths.at(-1)!.description).toBe('in use')
const heights = at('/iui height')
expect(heights.map(r => r.text)).toEqual(['height half', 'height full', 'height 12', 'height 24', 'height 36'])
expect(heights.map(r => r.label)).toEqual(['half', 'full', '12 rows', '24 rows', '36 rows'])
- // half is the default; with no height given, it is current.
- expect(heights[0]!.description).toBe('current')
+ // half is the default; with no height given, it is in use.
+ expect(heights[0]!.description).toBe('in use')
expect(heights[1]!.description).toBe('the terminal height less 16 rows')
const grids = at('/iui grid')
expect(grids.map(r => r.text)).toEqual(['grid on', 'grid off'])
- // on is the default; with no grid given, it is current.
- expect(grids.map(r => r.description)).toEqual(['current', undefined])
+ // on is the default; with no grid given, it is in use.
+ expect(grids.map(r => r.description)).toEqual(['in use', undefined])
})
test('a theme name or size completes after its word', () => {
expect(at('/iui theme vs').map(r => r.text)).toEqual(['vscode', 'vscode-modern'])
expect(at('/iui theme N').map(r => r.text)).toEqual(['nord'])
expect(at('/iui size 1').map(r => r.text)).toEqual(['100', '110', '120', '125', '150', '175'])
- expect(at('/iui size 10')[0]!.description).toBe('current')
+ expect(at('/iui size 10')[0]!.description).toBe('in use')
expect(at('/iui theme nord extra')).toEqual([])
expect(at('/iui width 1').map(r => r.text)).toEqual(['100', '120', '160'])
expect(at('/iui width f').map(r => r.label)).toEqual(['full'])
const set = (text: string) => commandSuggestions(text, /\S+$/.exec(text)![0], text.lastIndexOf(' ') + 1, { ...o, width: 160 })
- expect(set('/iui width 16')[0]!.description).toBe('current')
+ expect(set('/iui width 16')[0]!.description).toBe('in use')
expect(set('/iui width f')[0]!.description).toBe('the default')
expect(at('/iui height f').map(r => r.text)).toEqual(['full'])
expect(at('/iui height 2').map(r => r.text)).toEqual(['24'])
const tall = (text: string) => commandSuggestions(text, /\S+$/.exec(text)![0], text.lastIndexOf(' ') + 1, { ...o, height: 24 })
- expect(tall('/iui height 2')[0]!.description).toBe('current')
+ expect(tall('/iui height 2')[0]!.description).toBe('in use')
expect(tall('/iui height h')[0]!.description).toBe('the default: half the terminal')
expect(at('/iui grid o').map(r => r.text)).toEqual(['on', 'off'])
expect(at('/iui grid of').map(r => r.label)).toEqual(['off'])
const gridded = (text: string) => commandSuggestions(text, /\S+$/.exec(text)![0], text.lastIndexOf(' ') + 1, { ...o, grid: false })
- expect(gridded('/iui grid o').map(r => r.description)).toEqual(['the default', 'current'])
+ expect(gridded('/iui grid o').map(r => r.description)).toEqual(['the default', 'in use'])
expect(at('/iui grid on extra')).toEqual([])
})
-test('other prompts and the command name itself get no rows', () => {
- expect(at('/iui')).toEqual([])
+test('the command name itself offers the subcommands, as rows that hold it', () => {
+ const rows = at('/iui')
+ expect(rows.map(r => r.label)).toEqual(['on', 'off', 'size', 'width', 'height', 'grid', 'updates', 'theme', 'setup', 'details', 'grab', 'dump'])
+ expect(rows.find(r => r.label === 'theme')!.text).toBe('/iui theme')
+ expect(at(' /iui').map(r => r.text)).toContain('/iui grid')
+ expect(at('tell me /iui')).toEqual([])
+})
+
+test('other prompts get no rows', () => {
expect(at('/iuix t')).toEqual([])
expect(at('tell me about /iui t')).toEqual([])
expect(at('/other theme')).toEqual([])
diff --git a/tests/pure.test.ts b/tests/pure.test.ts
index 993b0f4..311555d 100644
--- a/tests/pure.test.ts
+++ b/tests/pure.test.ts
@@ -582,11 +582,13 @@ test('a user theme replaces the built-in one of its name; a broken one is only r
expect(themes.get('nord')).toMatchObject({ isUser: true, description: 'mine' })
expect(themes.get('vscode')).toMatchObject({ isUser: false, dir: '/mod/render/themes/vscode' })
expect(problems.map(p => p.name).sort()).toEqual(['solar', 'vscode'])
- const listing = themeListing(themes, problems, 'nord', '/home/.claude/cc-intelligent-ui/themes')
- expect(listing).toContain('* nord (user): mine')
- expect(listing).toContain('- vscode (built-in)')
- expect(listing).toContain('skipped solar (user)')
- expect(listing).toContain('/home/.claude/cc-intelligent-ui/themes/<name>/theme.json')
+ const listing = themeListing(themes, problems, 'nord', '/home/.claude/cc-intelligent-ui/themes', '/home')
+ expect(listing).toContain('- nord (yours, in use): mine')
+ expect(listing).toContain('- vscode\n')
+ expect(listing).toContain('- solar (yours): not usable')
+ expect(listing).toContain('~/.claude/cc-intelligent-ui/themes/<name>/theme.json')
+ // Shown as Markdown: a line that starts with `* ` would turn into a bullet.
+ expect(listing.split('\n').some(l => l.startsWith('* '))).toBe(false)
})
test('a missing theme falls back to the base theme, even before it is on disk', () => {
diff --git a/tests/themes.test.ts b/tests/themes.test.ts
index 4bb8f0c..579ed4c 100644
--- a/tests/themes.test.ts
+++ b/tests/themes.test.ts
@@ -48,22 +48,22 @@ const withThemes = (on: any, stored: Record<string, unknown> = {}) => {
test('/iui theme lists built-in and user themes; a user theme wins and a broken one is reported', async ($, on) => {
withThemes(on)
const ran = await $.command.run({ command: 'iui', args: 'theme' } as any)
- expect(ran.text).toContain('* claude-code (built-in): default look')
- expect(ran.text).toContain('- vscode-modern (built-in): modern look')
- expect(ran.text).toContain('- vscode (built-in): built-in look')
- expect(ran.text).toContain('- nord (user): my nord')
- expect(ran.text).toContain('- Sun.Light (user): bright')
- expect(ran.text).toContain('skipped Broken (user): theme.json is not valid JSON')
- expect(ran.text).toContain(`${USER}/<name>/theme.json`)
- expect(ran.text).toContain('skipped Lost (user): theme.json names syntax files that do not exist: gone.tmTheme')
- expect(ran.text).toContain('- Own (user): own colours')
+ expect(ran.text).toContain('- claude-code (in use): default look')
+ expect(ran.text).toContain('- vscode-modern: modern look')
+ expect(ran.text).toContain('- vscode: built-in look')
+ expect(ran.text).toContain('- nord (yours): my nord')
+ expect(ran.text).toContain('- Sun.Light (yours): bright')
+ expect(ran.text).toContain('- Broken (yours): not usable, theme.json is not valid JSON')
+ expect(ran.text).toContain('Your own themes go in ~/.claude/cc-intelligent-ui/themes/<name>/theme.json.')
+ expect(ran.text).toContain('- Lost (yours): not usable, theme.json names syntax files that do not exist: gone.tmTheme')
+ expect(ran.text).toContain('- Own (yours): own colours')
})
test('/iui theme <name> switches and stores the name as typed; an unknown one is refused', async ($, on) => {
const store = withThemes(on)
const set = await $.command.run({ command: 'iui', args: 'theme Sun.Light' } as any)
- expect(set.text).toContain('Intelligent UI uses the theme Sun.Light.')
- expect(set.text).toContain('* Sun.Light (user)')
+ expect(set.text).toContain('Theme set to Sun.Light.')
+ expect(set.text).toContain('- Sun.Light (yours, in use)')
expect(store['theme-name']).toBe('Sun.Light')
const shown = await $.command.run({ command: 'iui', args: '' } as any)
expect(shown.text).toContain('theme Sun.Light')
@@ -82,6 +82,6 @@ test('a stored theme that is gone falls back to claude-code, with one toast', as
return { value: undefined }
})
const ran = await $.command.run({ command: 'iui', args: 'theme' } as any)
- expect(ran.text).toContain('* claude-code (built-in)')
+ expect(ran.text).toContain('- claude-code (in use)')
expect(toasts.filter(t => t.includes('Intelligent UI: theme gone not found, using claude-code')).length).toBe(1)
})
diff --git a/tests/updates.test.ts b/tests/updates.test.ts
index 4dc7a1a..ce59a8b 100644
--- a/tests/updates.test.ts
+++ b/tests/updates.test.ts
@@ -89,10 +89,10 @@ test('/iui updates [on|off] is a command, with typeahead rows', () => {
expect(at('/iui u')[0]!.description).toBe('look for a new version once a day, on or off')
const rows = at('/iui updates')
expect(rows.map(r => r.text)).toEqual(['updates on', 'updates off'])
- // on is the default; with no value given, it is current.
- expect(rows.map(r => r.description)).toEqual(['current', undefined])
- expect(at('/iui updates of', { updates: false }).map(r => [r.text, r.description])).toEqual([['off', 'current']])
- expect(at('/iui updates o', { updates: false }).map(r => r.description)).toEqual(['the default', 'current'])
+ // on is the default; with no value given, it is in use.
+ expect(rows.map(r => r.description)).toEqual(['in use', undefined])
+ expect(at('/iui updates of', { updates: false }).map(r => [r.text, r.description])).toEqual([['off', 'in use']])
+ expect(at('/iui updates o', { updates: false }).map(r => r.description)).toEqual(['the default', 'in use'])
expect(at('/iui updates on extra')).toEqual([])
})