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
herdr: pictures setup, the outer terminal's font and theme, smaller pages
razorback169824bea9d2af
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex b0c41f4..d2616f7 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -2,6 +2,24 @@All releases of Intelligent UI for Claude Code (`cc-intelligent-ui`). Claude Code finds a new version by the `version` in `.claude-plugin/plugin.json`. To get it, refer to [Update](docs/install.md#update).+## Unreleased++### New++- **herdr support** (the terminal multiplexer). In a herdr pane, Claude Code needs `CLAUDE_CODE_FORCE_TERMINAL_IMAGES=1` to show pictures. The mod asks one time to add the shell line, as in iTerm2. `/iui setup` also adds it. Then close the pane and open a new herdr pane. herdr must run in a terminal that shows kitty pictures (kitty or Ghostty). Refer to [Terminals](docs/install.md#terminals).+- `/iui setup` works in herdr on Linux too.+- `/iui details` names herdr, its version and the terminal that it runs in, for example `herdr 0.9.5 (in Ghostty)`.++### Changed++- The shell line of `/iui setup` sets the variable in iTerm2 and in herdr. `/iui setup` replaces the line of an older version. In herdr, the mod asks to update an older line. In iTerm2, the older line still works, and the mod does not ask.+- In herdr, pages are shorter, so that each page is at most 16 MiB as pixels.++### Fixed++- In herdr, the mod now uses the font and the background of the terminal that herdr runs in (Ghostty, kitty or iTerm2). Before, it used Menlo and the OS appearance, so the text could be dark on a dark background.+- In herdr, a tall page of a long answer did not show (herdr does not send an image that is too large to the terminal). Refer to [Limitations](docs/limitations.md).+## 0.3.2 (2026-10-21)### Newdiff --git a/README.md b/README.mdindex 1b98833..35d9956 100644--- a/README.md+++ b/README.md@@ -38,6 +38,7 @@ You need Claude Code 2.1.298 or later, [Typst](https://typst.app) 0.15, and macO|---|---|---|| kitty 0.28+, Ghostty, cmux (macOS) | Yes | Nothing || iTerm2 3.6+ (macOS) | Yes | Run `/iui setup` one time |+| herdr, in kitty or Ghostty | Yes | Run `/iui setup` one time || Rio 0.5.27+ | Yes (not tested) | Set `CLAUDE_CODE_FORCE_TERMINAL_IMAGES=1` || ssh | Yes, from kitty or Ghostty | Refer to [Install](docs/install.md#terminals) || tmux, screen | No | — |@@ -95,7 +96,7 @@ More in the [gallery](docs/gallery.md): plots, fractals and a tour of all the Ma| `/iui select on` / `off` | Claude Code 2.1.298+, fullscreen: the mod selects and copies picture text with the mouse (on by default) || `/iui updates on` / `off` | Turns the daily check for a new version on or off (on by default) || `/iui details` | Shows the terminal, font, mode and Typst that the mod found |-| `/iui setup` | iTerm2 (macOS): adds the shell line that turns pictures on |+| `/iui setup` | iTerm2 (macOS) and herdr: adds the shell line that turns pictures on || `/iui grab` | Copies the text under your last mouse selection of pictures || `/iui dump` | Shows how the mod read the last clipboard with picture cells (for a bug report) |diff --git a/docs/how-it-works.md b/docs/how-it-works.mdindex 617ffda..a99a7d3 100644--- a/docs/how-it-works.md+++ b/docs/how-it-works.md@@ -88,4 +88,6 @@ Claude Code finds the light or dark mode for `auto` by asking the terminal for iThe terminal comes before the OS: a dark terminal on a light Mac is dark.+In **herdr**, `TERM_PROGRAM` is `herdr`, so it does not name the terminal that herdr runs in. Intelligent UI finds that terminal from the variables that herdr keeps of the terminal that started the herdr server: `GHOSTTY_RESOURCES_DIR` or `GHOSTTY_BIN_DIR` for Ghostty, `KITTY_PID` or `KITTY_INSTALLATION_DIR` for kitty, `ITERM_PROFILE` for iTerm2. It then uses that terminal's sources above (and its font for the text size). If it finds none, it uses `COLORFGBG`, then the OS appearance.+Intelligent UI checks every 3 s. After a change, each mode's pictures compile once. `/iui probe` asks the terminal for its background with OSC 11 (5 times) and shows the raw answers. This is a test of whether the answer can reach the mod. The 3 s check does not use OSC 11 yet.diff --git a/docs/install.md b/docs/install.mdindex 0c69c4c..98cdf67 100644--- a/docs/install.md+++ b/docs/install.md@@ -12,7 +12,10 @@## Terminals- **kitty (0.28 or later), Ghostty and cmux (Ghostty inside, macOS only):** pictures work with no setting. kitty and Ghostty work on macOS and on Linux.-- **iTerm2 3.6 or later (3.7.5 tested, macOS only):** Claude Code needs `CLAUDE_CODE_FORCE_TERMINAL_IMAGES=1` when it starts. A mod cannot set it early enough. The first time the mod runs in iTerm2, it asks to add one line to your shell's start file (`~/.zshrc`, `~/.bash_profile` or a fish `conf.d` file). The line sets the variable in iTerm2 only, not in tmux or screen. Then close the tab, open a new iTerm2 tab, and start Claude Code there. You can also run `/iui setup` (undo: `/iui setup remove`).+- **iTerm2 3.6 or later (3.7.5 tested, macOS only):** Claude Code needs `CLAUDE_CODE_FORCE_TERMINAL_IMAGES=1` when it starts. A mod cannot set it early enough. The first time the mod runs in iTerm2, it asks to add one line to your shell's start file (`~/.zshrc`, `~/.bash_profile` or a fish `conf.d` file). The line sets the variable in iTerm2 and herdr only, not in tmux or screen. Then close the tab, open a new iTerm2 tab, and start Claude Code there. You can also run `/iui setup` (undo: `/iui setup remove`).+- **herdr (0.9.5 tested, in Ghostty):** herdr is a terminal multiplexer. It draws the pictures of its panes in the terminal that it runs in, so that terminal must show kitty pictures (kitty or Ghostty). Claude Code needs `CLAUDE_CODE_FORCE_TERMINAL_IMAGES=1` in herdr too. The first time the mod runs in a herdr pane, it asks to add the same line to your shell's start file. If the file has the line of an older version (iTerm2 only), the mod asks to update it. Then close the pane, open a new herdr pane, and start Claude Code there. You can also run `/iui setup` (undo: `/iui setup remove`). herdr works on macOS and on Linux.+ - herdr hides the name of the terminal that it runs in. The mod finds that terminal from the variables that herdr keeps of the terminal that started the herdr server (`GHOSTTY_RESOURCES_DIR` for Ghostty, `KITTY_PID` for kitty, `ITERM_PROFILE` for iTerm2). The mod then reads the font and the background of that terminal. If you attach to the herdr server from a different terminal, the font and the `auto` mode can be wrong. `/iui details` shows the terminal that the mod found, for example `herdr 0.9.5 (in Ghostty)`.+ - Pages are shorter in herdr, so that herdr can send each one to the terminal. Refer to [Limitations](limitations.md).- **Rio 0.5.27 or later (not tested):** set `CLAUDE_CODE_FORCE_TERMINAL_IMAGES=1` before you start Claude Code. Rio works on macOS and on Linux.- Do not put the variable in the `env` of `~/.claude/settings.json`. It then applies in every terminal, also where pictures cannot show.- **Warp (not yet):** Warp does not draw kitty pictures with Unicode placeholders yet. The pull request [warpdotdev/warp#16312](https://github.com/warpdotdev/warp/pull/16312) adds them. The mod will support Warp when that pull request is merged.@@ -67,7 +70,7 @@ The mod works on Linux with X11 and with Wayland. It uses these tools. Most Linu- **"Edit the plan"** (refer to [Plan approval](usage.md#plan-approval)): VS Code (`code --wait`), else the first of VSCodium, Zed, Sublime Text, Kate, gedit and gvim that is on the `PATH`. These editors can wait until you close the file. If none is installed, the option does not show.- **The cache folder** is in `$TMPDIR`, else in `/tmp`.-`/iui setup` is for iTerm2 only. On Linux it changes no file.+`/iui setup` is for iTerm2 and herdr. On Linux it changes no file, but in a herdr pane it adds the line (to `~/.bashrc` for bash, because herdr does not start a login shell on Linux).To install the clipboard tools, for example:diff --git a/docs/limitations.md b/docs/limitations.mdindex bc117bc..fe822aa 100644--- a/docs/limitations.md+++ b/docs/limitations.md@@ -58,4 +58,5 @@- **The look is close to VS Code, not exact:** Typst does not use CSS. Raw HTML in Markdown is shown in a simple form or dropped. Loose lists have tight spacing (with `/iui grid on`, the items of a loose list have a gap of one row).- **A picture that the terminal dropped from its image memory** (after many large pictures) is not sent again when you scroll back to it.- **Over ssh**, the mod cannot read the terminal's config on your computer. So it uses the metrics of the theme's code font (Menlo on macOS) for the text size, and `auto` uses `COLORFGBG` if ssh sends it. Else `auto` is dark. The mod does not use the OS appearance of the remote computer. Pages are shorter, so that each one is at most 4096 pixels tall. In tmux or screen on the remote computer, no pictures show.-- **`auto` theme** reads the iTerm2 profile, the Ghostty, kitty and Rio configs, and the cmux settings directly. It does not read kitty's `globinclude`, `envinclude` and `geninclude` lines, or colours that you set while kitty runs. In other terminals, it uses `COLORFGBG` (set only when the terminal starts), then the OS appearance (on Linux, the desktop portal or GNOME's setting). If you change the theme of such a terminal and the OS appearance does not change, Intelligent UI does not see it. A change shows after up to 3 s.+- **In herdr**, herdr does not send an image to the terminal if the image is too large for its transfer limit (30 MiB as base64, approximately 22 MiB as pixels: width × height × 4 bytes). It shows no image and no message. Thus the mod makes pages shorter in herdr, so that each page is at most 16 MiB as pixels. A pasted image, an image that Claude sends, a PDF page or a live Typst drawing larger than approximately 22 MiB as pixels (for example, 2900 × 2000 pixels) does not show in herdr. The mod finds the terminal that herdr runs in from the variables of the terminal that started the herdr server. If you attach from a different terminal, the font and the `auto` mode can be wrong.+- **`auto` theme** reads the iTerm2 profile, the Ghostty, kitty and Rio configs, and the cmux settings directly (in herdr, those of the terminal that herdr runs in). It does not read kitty's `globinclude`, `envinclude` and `geninclude` lines, or colours that you set while kitty runs. In other terminals, it uses `COLORFGBG` (set only when the terminal starts), then the OS appearance (on Linux, the desktop portal or GNOME's setting). If you change the theme of such a terminal and the OS appearance does not change, Intelligent UI does not see it. A change shows after up to 3 s.diff --git a/docs/usage.md b/docs/usage.mdindex 3932041..0f4f57e 100644--- a/docs/usage.md+++ b/docs/usage.md@@ -49,7 +49,7 @@ You can also start the skill yourself: type `/cc-intelligent-ui:intelligent-ui`| `/iui` | Shows the state, the theme, the text size, the width, the image height and the row grid, a problem that keeps pictures away, and a new version when there is one || `/iui details` | Shows all that the mod found: where the mode comes from, the terminal font, the Typst path, why the terminal can or cannot show pictures, if picture select is on (`Picture select:`), if the `/iui grab` toast is on (`/iui grab hint:`), and the state of the update check (`Update checks:`) || `/iui on` / `off` | Turns the pictures on or off (kept for later sessions) |-| `/iui setup` / `setup remove` | iTerm2 (macOS only): adds or removes the shell line that turns pictures on (then close the tab and open a new one). On Linux, it changes no file. |+| `/iui setup` / `setup remove` | iTerm2 (macOS only) and herdr (macOS and Linux): adds or removes the shell line that turns pictures on (then close the tab or pane and open a new one). An older line (iTerm2 only) is updated. On Linux outside herdr, it changes no file. || `/iui size <80–200>` | Text size in percent. 100 is the same visual size as your terminal text. || `/iui width` | Shows the width: the most columns that a picture can use || `/iui width <40–400>` | Sets the most columns that a picture can use (kept for later sessions) |diff --git a/hooks/lib/answer.ts b/hooks/lib/answer.tsindex 96593f5..55f1c20 100644--- a/hooks/lib/answer.ts+++ b/hooks/lib/answer.ts@@ -107,7 +107,7 @@ export async function pagesOf($: EngineInterface, o: PagesInput): Promise<Drawinconst room = await roomOf($, { hasRoom, textHash, base, env, rows, widthPt, rowPt, isLive: liveNow() })const key = renderKey({textHash, columns, cell, size: S.size, mode: S.theme, termFont: env.termFont,- columnPt, templateStamp: env.stamp, look: active, inline: env.inline, base, room, grid: S.grid, fauxBold: fauxBoldOf(env.metrics),+ columnPt, templateStamp: env.stamp, look: active, inline: env.inline, herdr: env.herdr, base, room, grid: S.grid, fauxBold: fauxBoldOf(env.metrics),})const seen = lastText.get(id)const changed = seen !== textdiff --git a/hooks/lib/api.ts b/hooks/lib/api.tsindex b878bd8..e3b20db 100644--- a/hooks/lib/api.ts+++ b/hooks/lib/api.ts@@ -13,10 +13,10 @@ import type {export type EnvName =| 'CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC' | 'CLAUDE_CODE_FORCE_TERMINAL_IMAGES' | 'CLAUDE_CODE_SESSION_KIND' | 'CLAUDE_CODE_TMPDIR'| 'CMUX_SOCKET_PATH' | 'CMUX_SURFACE_ID' | 'CMUX_WORKSPACE_ID' | 'COLORFGBG' | 'DISABLE_AUTOUPDATER' | 'DISABLE_UPDATES' | 'DISPLAY'- | 'GHOSTTY_RESOURCES_DIR' | 'HOME'- | 'ITERM_PROFILE' | 'ITERM_SESSION_ID' | 'IUI_DEBUG' | 'IUI_FORCE' | 'KITTY_CONFIG_DIRECTORY' | 'KITTY_PID'+ | 'GHOSTTY_BIN_DIR' | 'GHOSTTY_RESOURCES_DIR' | 'HERDR_ENV' | 'HOME'+ | 'ITERM_PROFILE' | 'ITERM_SESSION_ID' | 'IUI_DEBUG' | 'IUI_FORCE' | 'KITTY_CONFIG_DIRECTORY' | 'KITTY_INSTALLATION_DIR' | 'KITTY_PID'| 'KITTY_WINDOW_ID' | 'LC_TERMINAL' | 'RIO_CONFIG_HOME' | 'SHELL' | 'SSH_CONNECTION' | 'SSH_TTY' | 'STY'- | 'TERM' | 'TERM_PROGRAM' | 'TMUX' | 'TYPST_FONT_PATHS' | 'WAYLAND_DISPLAY' | 'XDG_CONFIG_HOME' | 'XDG_CURRENT_DESKTOP' | 'ZDOTDIR'+ | 'TERM' | 'TERM_PROGRAM' | 'TERM_PROGRAM_VERSION' | 'TMUX' | 'TYPST_FONT_PATHS' | 'WAYLAND_DISPLAY' | 'XDG_CONFIG_HOME' | 'XDG_CURRENT_DESKTOP' | 'ZDOTDIR'export function clockAfter($: EngineInterface, ms: number, fn: () => void) {return $.clock.after(ms, fn)@@ -55,13 +55,16 @@ export function envGet($: EngineInterface, name: EnvName): Promise<string | undecase 'DISABLE_AUTOUPDATER': return $.env.get('DISABLE_AUTOUPDATER')case 'DISABLE_UPDATES': return $.env.get('DISABLE_UPDATES')case 'DISPLAY': return $.env.get('DISPLAY')+ case 'GHOSTTY_BIN_DIR': return $.env.get('GHOSTTY_BIN_DIR')case 'GHOSTTY_RESOURCES_DIR': return $.env.get('GHOSTTY_RESOURCES_DIR')+ case 'HERDR_ENV': return $.env.get('HERDR_ENV')case 'HOME': return $.env.get('HOME')case 'ITERM_PROFILE': return $.env.get('ITERM_PROFILE')case 'ITERM_SESSION_ID': return $.env.get('ITERM_SESSION_ID')case 'IUI_DEBUG': return $.env.get('IUI_DEBUG')case 'IUI_FORCE': return $.env.get('IUI_FORCE')case 'KITTY_CONFIG_DIRECTORY': return $.env.get('KITTY_CONFIG_DIRECTORY')+ case 'KITTY_INSTALLATION_DIR': return $.env.get('KITTY_INSTALLATION_DIR')case 'KITTY_PID': return $.env.get('KITTY_PID')case 'KITTY_WINDOW_ID': return $.env.get('KITTY_WINDOW_ID')case 'LC_TERMINAL': return $.env.get('LC_TERMINAL')@@ -72,6 +75,7 @@ export function envGet($: EngineInterface, name: EnvName): Promise<string | undecase 'STY': return $.env.get('STY')case 'TERM': return $.env.get('TERM')case 'TERM_PROGRAM': return $.env.get('TERM_PROGRAM')+ case 'TERM_PROGRAM_VERSION': return $.env.get('TERM_PROGRAM_VERSION')case 'TMUX': return $.env.get('TMUX')case 'TYPST_FONT_PATHS': return $.env.get('TYPST_FONT_PATHS')case 'WAYLAND_DISPLAY': return $.env.get('WAYLAND_DISPLAY')diff --git a/hooks/lib/command.ts b/hooks/lib/command.tsindex 98639ec..24a5072 100644--- a/hooks/lib/command.ts+++ b/hooks/lib/command.ts@@ -77,7 +77,7 @@ const SUBCOMMANDS = [{ name: 'select', description: 'select and copy picture text with the mouse, on or off' },{ name: 'updates', description: 'look for a new version once a day, on or off' },{ name: 'theme', description: 'list the themes, or switch to one' },- { name: 'setup', description: 'iTerm2: add the shell line that turns pictures on' },+ { name: 'setup', description: 'iTerm2 and herdr: add the shell line that turns pictures on' },{ name: 'details', description: 'the mode source, the terminal font, Typst and the terminal' },{ name: 'grab', description: 'copy the text of the pictures you last selected (or copied, on the main screen)' },{ name: 'dump', description: 'show what the clipboard held and how it was read' },diff --git a/hooks/lib/draw.tsx b/hooks/lib/draw.tsxindex 85bc655..135a7de 100644--- a/hooks/lib/draw.tsx+++ b/hooks/lib/draw.tsx@@ -69,6 +69,8 @@ export function renderKey(o: {look: Look// Over ssh: pages are cut shorter (inlineBudget), so they are other PNGs.inline?: boolean+ // Under herdr: pages are cut shorter too (herdrBudget).+ herdr?: boolean// The folder relative images start from, when it is not the session's (a// Markdown file's): the same text there shows other images.base?: string@@ -85,7 +87,7 @@ export function renderKey(o: {const { room } = oreturn hashOf([o.textHash, o.columns, o.cell.width, o.cell.height, o.size, o.mode, o.termFont, o.columnPt,- o.templateStamp, o.look.name, o.look.dir, o.look.stamp, TEMPLATE_VERSION, ...(o.inline ? ['inline'] : []),+ o.templateStamp, o.look.name, o.look.dir, o.look.stamp, TEMPLATE_VERSION, ...(o.inline ? ['inline'] : []), ...(o.herdr ? ['herdr'] : []),...(o.base ? ['base', o.base] : []),...(room ? ['room', room.heightPt, room.design.widthPt, room.design.heightPt] : []),...(o.grid ? ['grid', GRID_VERSION] : []),diff --git a/hooks/lib/env.ts b/hooks/lib/env.tsindex e26e1b7..a25b55c 100644--- a/hooks/lib/env.ts+++ b/hooks/lib/env.ts@@ -9,7 +9,7 @@ import {import { DEFAULT_METRICS, refresh, S, type Env } from './state'import { resolveMode, settingOf } from './mode'import { isItermIn } from './terminals'-import { canDrawIn, isSet } from './terminal'+import { canDrawIn, herdrHostOf, isHerdrIn, isSet, needsSetup } from './terminal'import { claudeTmpOf } from './images'import { applyTheme } from './themes'import { registerCommand } from './command'@@ -70,7 +70,18 @@ export function setUp($: EngineInterface): Promise<Env> {S.termProgram = programS.termName = termS.itermProfile = (await envGet($, 'ITERM_PROFILE')) || undefined- S.isKitty = /kitty/i.test(term) || !!(await envGet($, 'KITTY_WINDOW_ID')) || !!(await envGet($, 'KITTY_PID'))+ S.isHerdr = isHerdrIn({ program, herdrEnv: await envGet($, 'HERDR_ENV') })+ S.herdrVersion = S.isHerdr ? ((await envGet($, 'TERM_PROGRAM_VERSION')) ?? '').trim() : ''+ S.herdrHost = S.isHerdr+ ? herdrHostOf({+ ghosttyResources: await envGet($, 'GHOSTTY_RESOURCES_DIR'),+ ghosttyBin: await envGet($, 'GHOSTTY_BIN_DIR'),+ kittyPid: await envGet($, 'KITTY_PID'),+ kittyDir: await envGet($, 'KITTY_INSTALLATION_DIR'),+ itermProfile: S.itermProfile,+ })+ : ''+ S.isKitty = /kitty/i.test(term) || !!(await envGet($, 'KITTY_WINDOW_ID')) || !!(await envGet($, 'KITTY_PID')) || S.herdrHost === 'kitty'S.isRemote = sshS.debug = isSet(await envGet($, 'IUI_DEBUG'))S.isIterm = isItermIn({@@ -79,8 +90,15 @@ export function setUp($: EngineInterface): Promise<Env> {session: (await envGet($, 'ITERM_SESSION_ID')) || undefined,lcTerminal: (await envGet($, 'LC_TERMINAL')) || undefined,})- S.setupNeeded = S.isIterm && !terminalDraws && !ssh && S.hostOs === 'Darwin' &&- !(await envGet($, 'TMUX')) && !(await envGet($, 'STY')) && (await envGet($, 'CLAUDE_CODE_SESSION_KIND')) !== 'bg'+ S.setupNeeded = needsSetup({+ iterm: S.isIterm,+ herdr: S.isHerdr,+ draws: terminalDraws,+ ssh,+ os: S.hostOs,+ tmux: !!(await envGet($, 'TMUX')) || !!(await envGet($, 'STY')),+ background: (await envGet($, 'CLAUDE_CODE_SESSION_KIND')) === 'bg',+ })if (S.setupNeeded) void offerSetup($).catch(() => undefined)S.isCmux = !!(await envGet($, 'CMUX_SURFACE_ID')) || !!(await envGet($, 'CMUX_WORKSPACE_ID')) || !!(await envGet($, 'CMUX_SOCKET_PATH'))S.colorFgBg = (await envGet($, 'COLORFGBG')) ?? ''@@ -131,6 +149,7 @@ export function setUp($: EngineInterface): Promise<Env> {typst,canDraw,inline: ssh && canDraw,+ herdr: S.isHerdr,cache,cwd: await sessionCwd($).catch(() => '/'),root,diff --git a/hooks/lib/host.ts b/hooks/lib/host.tsindex 0185748..b5ab1d9 100644--- a/hooks/lib/host.ts+++ b/hooks/lib/host.ts@@ -309,9 +309,13 @@ async function rioFont($: EngineInterface, isMac: boolean): Promise<string> {return (await installedFamily($, isMac, RIO_OLD_FONT)) ? RIO_OLD_FONT : RIO_DEFAULT_FONT}+// iTerm2, or herdr in iTerm2 (its profile and font; S.isIterm stays false+// there, so the setup question for iTerm2 is not asked).+const isItermHere = () => S.isIterm || S.herdrHost === 'iterm'+// The font that the terminal's own config or profile names.async function configFontOf($: EngineInterface, isMac: boolean): Promise<string> {- if (S.isIterm && isMac) {+ if (isItermHere() && isMac) {const profile = await envGet($, 'ITERM_PROFILE')const [marks, guid] = await Promise.all([processRun($, ['sh', '-c', ITERM_BOOKMARKS_SH], { timeoutMs: 5000 }).catch(() => null),@@ -384,7 +388,7 @@ export async function readHostMode($: EngineInterface): Promise<HostMode | null>// The background of the iTerm2 profile in use, on a Mac.async function readItermMode($: EngineInterface): Promise<HostMode | null> {- if (!S.isIterm || S.hostOs !== 'Darwin') return null+ if (!isItermHere() || S.hostOs !== 'Darwin') return nullconst got = await processRun($, ['sh', '-c', ITERM_MODE_SH], { timeoutMs: HOST_CHECK_MS }).catch(() => null)if (!got || got.exitCode !== 0) return nullconst [style = '', guid = '', marks = ''] = got.stdout.split(/^@\n/m)@@ -401,9 +405,10 @@ export async function probeOsc11($: EngineInterface): Promise<{ reply: string }}// The background of Ghostty's config. A `light:A,dark:B` theme follows the OS-// (in cmux, cmux's appearance). In cmux, cmux's own config is read as well.+// (in cmux, cmux's appearance). In cmux, cmux's own config is read as well;+// herdr in Ghostty reads Ghostty's.async function readGhosttyMode($: EngineInterface): Promise<HostMode | null> {- if (!/ghostty/i.test(S.termProgram + S.termName)) return null+ if (!/ghostty/i.test(S.termProgram + S.termName) && S.herdrHost !== 'ghostty') return nullconst got = await processRun($, ['sh', '-c', GHOSTTY_SH], { timeoutMs: HOST_CHECK_MS }).catch(() => null)if (!got || got.exitCode !== 0) return nullconst home = (await envGet($, 'HOME')) ?? ''diff --git a/hooks/lib/setup.ts b/hooks/lib/setup.tsindex b15e1d1..f13ca43 100644--- a/hooks/lib/setup.ts+++ b/hooks/lib/setup.ts@@ -1,5 +1,5 @@-// iTerm2 setup: the marked block /iui setup adds to (or removes from)-// the shell's start file, and the question asked once per load.+// iTerm2 and herdr setup: the marked block /iui setup adds to (or removes+// from) the shell's start file, and the question asked once per load.import type { EngineInterface } from 'claude-code'import { S } from './state'@@ -7,16 +7,17 @@ import { readText } from './host'import { envGet, fsWrite, processRun, storeGet, storeSet, uiAsk, uiLog, uiToast } from './api'// Claude Code turns pictures on by itself in kitty and Ghostty only; iTerm2-// needs CLAUDE_CODE_FORCE_TERMINAL_IMAGES=1 when Claude Code starts (a mod's-// $.env.set comes after its terminal check, too late). So the setup adds a-// marked block to the shell's start file that sets it in iTerm2 alone, not in-// tmux or screen (Claude Code cannot draw there).+// and herdr need CLAUDE_CODE_FORCE_TERMINAL_IMAGES=1 when Claude Code starts+// (a mod's $.env.set comes after its terminal check, too late). So the setup+// adds a marked block to the shell's start file that sets it in iTerm2 and+// herdr alone, not in tmux or screen (Claude Code cannot draw there). The+// markers stay as they were (an old block set it in iTerm2 only).export const SETUP_START = '# >>> cc-intelligent-ui: Claude Code pictures in iTerm2 >>>'export const SETUP_END = '# <<< cc-intelligent-ui <<<'export type ShellRc = { path: string; kind: 'sh' | 'fish' }// The start file the setup writes for the login shell (`SHELL`); null for a-// shell it does not know. iTerm2 starts login shells: bash reads-// .bash_profile on macOS. fish gets a file of its own in conf.d.+// shell it does not know. iTerm2 (and herdr on macOS) starts login shells:+// bash reads .bash_profile on macOS. fish gets a file of its own in conf.d.export function shellRcOf(o: { shell: string; home: string; zdotdir?: string; xdgConfig?: string; isMac: boolean }): ShellRc | null {const name = o.shell.split('/').pop() ?? ''if (name === 'zsh') return { path: `${o.zdotdir || o.home}/.zshrc`, kind: 'sh' }@@ -26,11 +27,13 @@ export function shellRcOf(o: { shell: string; home: string; zdotdir?: string; xd}export function setupBlock(kind: ShellRc['kind']): string {const line = kind === 'fish'- ? 'if test "$TERM_PROGRAM" = "iTerm.app"; and not set -q TMUX; and not set -q STY; set -gx CLAUDE_CODE_FORCE_TERMINAL_IMAGES 1; end'- : 'if [ "$TERM_PROGRAM" = "iTerm.app" ] && [ -z "$TMUX" ] && [ -z "$STY" ]; then export CLAUDE_CODE_FORCE_TERMINAL_IMAGES=1; fi'+ ? 'if test "$TERM_PROGRAM" = "iTerm.app" -o "$TERM_PROGRAM" = "herdr"; and not set -q TMUX; and not set -q STY; set -gx CLAUDE_CODE_FORCE_TERMINAL_IMAGES 1; end'+ : 'if { [ "$TERM_PROGRAM" = "iTerm.app" ] || [ "$TERM_PROGRAM" = "herdr" ]; } && [ -z "$TMUX" ] && [ -z "$STY" ]; then export CLAUDE_CODE_FORCE_TERMINAL_IMAGES=1; fi'return `${SETUP_START}\n${line}\n${SETUP_END}\n`}export const hasSetup = (text: string) => text.includes(SETUP_START)+// The text has this version's block (an old one has no herdr).+export const hasNewSetup = (text: string, kind: ShellRc['kind']) => text.includes(setupBlock(kind))// The text with no setup block (and no blank line left where it was).export function withoutSetup(text: string): string {const lines = text.split('\n')@@ -67,28 +70,34 @@ async function shellRc($: EngineInterface): Promise<ShellRc | null> {})}-// What /iui setup says where iTerm2 does not run (not macOS): it changes no file.-export const SETUP_NOT_MAC = '/iui setup is for iTerm2, which runs on macOS only, so Intelligent UI changed no file. ' +- 'On Linux, kitty and Ghostty show pictures with no setup. ' ++// What /iui setup says where neither iTerm2 (macOS only) nor herdr runs: it changes no file.+export const SETUP_NOT_MAC = '/iui setup is for iTerm2 and herdr. iTerm2 runs on macOS only, and this terminal is not herdr, so Intelligent UI changed no file. ' ++ 'On Linux, kitty and Ghostty show pictures with no setup. In herdr, run /iui setup in a herdr pane. ' +'For Rio, set CLAUDE_CODE_FORCE_TERMINAL_IMAGES=1 before you start Claude Code. Run /iui details to see if this terminal shows pictures.'-// Adds (or removes) the setup block. Returns what to tell the person.+// The words for the terminal in use: herdr opens panes, iTerm2 tabs.+export const setupWordsOf = (isHerdr: boolean) => (isHerdr ? { app: 'herdr', tab: 'pane' } : { app: 'iTerm2', tab: 'tab' })++// Adds (or removes) the setup block. Returns what to tell the person. A+// block of an older version (no herdr) is replaced.export async function runSetup($: EngineInterface, remove: boolean): Promise<string> {- if (S.hostOs && S.hostOs !== 'Darwin') return SETUP_NOT_MAC+ if (S.hostOs && S.hostOs !== 'Darwin' && !S.isHerdr) return SETUP_NOT_MACconst rc = await shellRc($)- const manual = `export CLAUDE_CODE_FORCE_TERMINAL_IMAGES=1 (only in iTerm2, not in tmux or screen)`+ const { app, tab } = setupWordsOf(S.isHerdr)+ const manual = `export CLAUDE_CODE_FORCE_TERMINAL_IMAGES=1 (only in iTerm2 and herdr, not in tmux or screen)`if (!rc) return `Intelligent UI does not know your shell, so it changed no file. Add this to your shell's start file: ${manual}`const text = (await readText($, rc.path)) ?? ''- const restart = 'Close this tab, open a new iTerm2 tab, and start Claude Code there to see pictures.'+ const restart = `Close this ${tab}, open a new ${app} ${tab}, and start Claude Code there to see pictures.`if (remove) {if (!hasSetup(text)) return `${rc.path} has no Intelligent UI block.`await fsWrite($, rc.path, withoutSetup(text))- return `Removed the Intelligent UI block from ${rc.path}. New iTerm2 tabs show answers as text.`+ return `Removed the Intelligent UI block from ${rc.path}. New ${app} ${tab}s show answers as text.`}- if (hasSetup(text)) return `${rc.path} already has the Intelligent UI block. ${restart}`+ if (hasNewSetup(text, rc.kind)) return `${rc.path} already has the Intelligent UI block. ${restart}`if (rc.kind === 'fish') await processRun($, ['mkdir', '-p', rc.path.replace(/\/[^/]*$/, '')]).catch(() => null)await fsWrite($, rc.path, withSetup(text, rc.kind))- return `Added the Intelligent UI block to ${rc.path}. ${restart} Undo with /iui setup remove.`+ const done = hasSetup(text) ? `Updated the Intelligent UI block in ${rc.path}` : `Added the Intelligent UI block to ${rc.path}`+ return `${done}. ${restart} Undo with /iui setup remove.`}// Asks once per load whether to add the setup block; "Never ask" is kept.@@ -97,20 +106,28 @@ export async function offerSetup($: EngineInterface) {S.setupAsked = trueif ((await storeGet($, 'setup').catch(() => undefined)) === 'never') returnconst rc = await shellRc($)- if (rc && hasSetup((await readText($, rc.path)) ?? '')) return+ const text = rc ? ((await readText($, rc.path)) ?? '') : ''+ // A block is enough for iTerm2; herdr needs this version's (an old one sets the variable in iTerm2 only).+ const isOld = !!rc && hasSetup(text) && !hasNewSetup(text, rc.kind)+ if (rc && hasSetup(text) && !(S.isHerdr && isOld)) returnconst file = rc ? rc.path.replace((await envGet($, 'HOME')) ?? '\u0000', '~') : "your shell's start file"- const answer = await uiAsk($,- `Intelligent UI draws answers as pictures, but in iTerm2 Claude Code needs CLAUDE_CODE_FORCE_TERMINAL_IMAGES=1 when it starts. Add one line to ${file} that sets it in iTerm2 only (not in tmux or screen)?`,- { header: 'iui', options: ['Add the line', 'Not now', 'Never ask'] },+ const { app, tab } = setupWordsOf(S.isHerdr)+ const yes = isOld ? 'Update the line' : 'Add the line'+ const ask = isOld+ ? `Update the Intelligent UI line in ${file} so that it sets it in herdr too (not in tmux or screen)?`+ : `Add one line to ${file} that sets it in iTerm2 and herdr only (not in tmux or screen)?`+ const answer = await uiAsk($,+ `Intelligent UI draws answers as pictures, but in ${app} Claude Code needs CLAUDE_CODE_FORCE_TERMINAL_IMAGES=1 when it starts. ${ask}`,+ { header: 'iui', options: [yes, 'Not now', 'Never ask'] },)if (answer === 'Never ask') await storeSet($, 'setup', 'never')- if (answer !== 'Add the line') return+ if (answer !== yes) returnconst said = await runSetup($, false)// The toast box is small: a short line there, the whole text in the transcript.try {uiLog($, said)} catch {}try {- uiToast($, said.startsWith('Added') ? 'Close this tab and open a new iTerm2 tab to see pictures.' : 'See the transcript for the setup.', { timeoutMs: 10000 })+ uiToast($, /^(Added|Updated)/.test(said) ? `Close this ${tab} and open a new ${app} ${tab} to see pictures.` : 'See the transcript for the setup.', { timeoutMs: 10000 })} catch {}}diff --git a/hooks/lib/state.ts b/hooks/lib/state.tsindex 5c3e414..0a6cf05 100644--- a/hooks/lib/state.ts+++ b/hooks/lib/state.ts@@ -12,6 +12,7 @@ import type { GridMetrics } from './grid'import type { Checked } from './updates'import type { ClipWay } from './clipboard'import type { PdfFacts, PixelBox } from './images'+import type { HerdrHost } from './terminal'import { DEFAULT_HEIGHT, DEFAULT_SIZE, DEFAULT_WIDTH, type Height, type Width } from './settings'import { invalidate } from './api'@@ -57,6 +58,8 @@ export type Env = {canDraw: boolean// Over ssh: pictures go as `{ png }` bytes, not as a file name.inline: boolean+ // Under herdr: pages are cut smaller (herdrBudget), so herdr sends them.+ herdr?: booleancache: stringcwd: stringroot: string@@ -176,6 +179,11 @@ export const S = {// iTerm2 (isItermIn) and cmux (Ghostty inside, with its CMUX_* variables), set in setUp.isIterm: false,isCmux: false,+ // herdr (isHerdrIn), its version ('' not known) and the terminal it runs in+ // (herdrHostOf; '' outside herdr or not known), set in setUp.+ isHerdr: false,+ herdrVersion: '',+ herdrHost: '' as HerdrHost,// A font folder for Typst (TYPST_FONT_PATHS): the font a terminal carries// in its program (Ghostty's, Rio's), when it draws it. '' for none.fontPaths: '',@@ -186,7 +194,7 @@ export const S = {isRemote: false,// IUI_DEBUG is set (setUp): trace lines go to the debug log.debug: false,- // iTerm2 with the engine's pictures off at start: /iui setup can help+ // iTerm2 or herdr with the engine's pictures off at start: /iui setup can help// (`setupNeeded`); the question is asked once per load (`setupAsked`).setupNeeded: false,setupAsked: false,diff --git a/hooks/lib/terminal.ts b/hooks/lib/terminal.tsindex 8b564bc..8f52162 100644--- a/hooks/lib/terminal.ts+++ b/hooks/lib/terminal.ts@@ -46,12 +46,45 @@ export function sizeOf(stdout: string, padded = false): { rows: number; columns:// Ghostty, or cmux (Ghostty's engine): its tty pixels include the window// padding (iTerm2, kitty and WezTerm do not), and it draws its own font when-// its config names none.-export const isGhosttyHere = () => /ghostty/i.test(S.termProgram + S.termName) || S.isCmux+// its config names none. herdr in Ghostty uses Ghostty's font and config (its+// tty pixels are whole cells, so the round down changes nothing).+export const isGhosttyHere = () => /ghostty/i.test(S.termProgram + S.termName) || S.isCmux || S.herdrHost === 'ghostty'// A set flag: anything but empty, 0, false, no or off.export const isSet = (value: string | undefined) => !!value && !/^(0|false|no|off)$/i.test(value.trim())+// herdr (a multiplexer with a terminal of its own per pane): TERM_PROGRAM, or+// HERDR_ENV with no TERM_PROGRAM. Another TERM_PROGRAM (tmux in a pane, a+// terminal started from one) wins.+export function isHerdrIn(env: { program: string; herdrEnv?: string }): boolean {+ if (env.program) return /^herdr$/i.test(env.program)+ return isSet(env.herdrEnv)+}++// The terminal herdr runs in, from the variables it keeps of the terminal+// that started its server (most often the one attached now): Ghostty's+// GHOSTTY_*_DIR, kitty's KITTY_PID or KITTY_INSTALLATION_DIR, iTerm2's+// ITERM_PROFILE; '' when none.+export type HerdrHost = 'ghostty' | 'kitty' | 'iterm' | ''+export function herdrHostOf(env: { ghosttyResources?: string; ghosttyBin?: string; kittyPid?: string; kittyDir?: string; itermProfile?: string }): HerdrHost {+ if (env.ghosttyResources || env.ghosttyBin) return 'ghostty'+ if (env.kittyPid || env.kittyDir) return 'kitty'+ if (env.itermProfile) return 'iterm'+ return ''+}+const HERDR_HOSTS = { ghostty: 'Ghostty', kitty: 'kitty', iterm: 'iTerm2' } as const+// herdr in /iui details: `herdr 0.9.5 (in Ghostty)`.+export const herdrText = (version: string, host: HerdrHost) =>+ `herdr${version ? ` ${version}` : ''} (${host ? `in ${HERDR_HOSTS[host]}` : 'outer terminal not known'})`++// Whether /iui setup can turn pictures on: they are off, and this is iTerm2+// on a Mac or herdr (macOS or Linux), not over ssh, tmux, screen or a+// background session.+export function needsSetup(o: { iterm: boolean; herdr: boolean; draws: boolean; ssh: boolean; os: string; tmux: boolean; background: boolean }): boolean {+ if (o.draws || o.ssh || o.tmux || o.background) return false+ return (o.iterm && o.os === 'Darwin') || o.herdr+}+// Whether the engine draws pictures here; elsewhere an Image shows only its// alt, so the text is better. Claude Code turns kitty graphics on by itself// only for kitty and Ghostty; any other terminal draws only when@@ -81,3 +114,14 @@ export const fitsInline = (page: { width: number; height: number }, base64?: str// Over ssh, a segment's budget in rows so that its page stays under// INLINE_MAX_SIDE pixels tall (with room for the rough row count).export const inlineBudget = (px: Cell) => Math.max(20, Math.min(SEGMENT_ROWS, Math.floor((INLINE_MAX_SIDE / px.height) * 0.75)))+// herdr skips an image whose RGBA (4 bytes a pixel), sent as base64, is over+// its 30 MiB transfer budget: a page stays under 16 MiB decoded.+export const HERDR_MAX_PAGE_BYTES = 16 * 1024 * 1024+// Under herdr, a segment's budget in rows so that its page (the columns'+// width in device pixels, as sizing makes it) stays under HERDR_MAX_PAGE_BYTES+// (with room for the rough row count).+export const herdrBudget = (columns: number, px: Cell) =>+ Math.max(20, Math.min(SEGMENT_ROWS, Math.floor((HERDR_MAX_PAGE_BYTES / (4 * Math.round(columns * px.width) * px.height)) * 0.75)))+// A segment's budget in rows: the smaller of the ssh and herdr ones that apply.+export const segmentBudget = (env: { inline: boolean; herdr?: boolean }, columns: number, px: Cell) =>+ Math.min(env.inline ? inlineBudget(px) : SEGMENT_ROWS, env.herdr ? herdrBudget(columns, px) : SEGMENT_ROWS)diff --git a/hooks/lib/typst.ts b/hooks/lib/typst.tsindex db1fd7a..968d4cd 100644--- a/hooks/lib/typst.ts+++ b/hooks/lib/typst.ts@@ -2,10 +2,10 @@// answer's segments to PNG pages (with a retry in safe mode).import type { EngineInterface } from 'claude-code'-import { COMPILE_TIMEOUT_MS, MAX_IMAGE_ROWS, NO_NETWORK, SEGMENT_ROWS, TOUCH_FLUSH_MS, TYPST_FALLBACKS } from './settings'+import { COMPILE_TIMEOUT_MS, MAX_IMAGE_ROWS, NO_NETWORK, TOUCH_FLUSH_MS, TYPST_FALLBACKS } from './settings'import { DEFAULT_METRICS, fauxBoldOf, S, type Cell, type FontMetrics, type Job, type LeanFonts, type Metrics, type Page, type Result } from './state'import { firstLine, imagePathOf, localImages, plainOf, splitInTwo, splitSegments } from './markdown'-import { inlineBudget } from './terminal'+import { segmentBudget } from './terminal'import { fontFit, placeFirstLine, sizing } from './draw'import { DEFAULT_GRID, gridOf } from './grid'import { HEADERS_SH } from './host'@@ -467,7 +467,7 @@ export async function compile($: EngineInterface, job: Job, signal?: AbortSignal// The room height of a drawing in rows (less the pt rounding); unknown// without a room (the default applies).const roomRows = job.room ? Math.ceil(job.room.heightPt / rowPt - 0.01) : undefined- let segments = splitSegments(job.text, job.columns, job.env.inline ? inlineBudget(job.cell) : SEGMENT_ROWS, job.size, roomRows)+ let segments = splitSegments(job.text, job.columns, segmentBudget(job.env, job.columns, job.cell), job.size, roomRows)const base = job.base ?? job.env.cwdconst images = await existingImages($, segments, base)await fsWrite($, `${dir}/doc.json`, JSON.stringify({ base, segments, images }))diff --git a/hooks/register.tsx b/hooks/register.tsxindex 5db9794..ac9431f 100644--- a/hooks/register.tsx+++ b/hooks/register.tsx@@ -48,7 +48,7 @@ import { pagesOf, type Drawing } from './lib/answer'import { clipboardNow, clipWatchArgs, clipWayReady, hintText } from './lib/clipboard'import { setUp } from './lib/env'import { frameFor, noteView, stopWatch, watchFrame, watchState } from './lib/frame'-import { roomColumns } from './lib/terminal'+import { herdrText, roomColumns } from './lib/terminal'import { onScreenOf, pastedImagePath, pastedNumbers, sentFiles } from './lib/images'import { drawPageField, pasteDir, pdfPagesOf, rowsAfter, sentOf, shownOf, underRow, type Shown, type Under } from './lib/pictures'import { checkUpdates, loadUpdates, updateLine, updateNotice, type UpdateState } from './lib/updates'@@ -81,7 +81,7 @@ export {type ThemeInfo, type ThemeProblem, type ThemeSyntax,} from './lib/themes'export { commandSuggestions, parseCommand, type Command, type Suggestion } from './lib/command'-export { hasSetup, SETUP_END, SETUP_NOT_MAC, SETUP_START, setupBlock, shellRcOf, withoutSetup, withSetup, type ShellRc } from './lib/setup'+export { hasNewSetup, hasSetup, SETUP_END, SETUP_NOT_MAC, SETUP_START, setupBlock, setupWordsOf, shellRcOf, withoutSetup, withSetup, type ShellRc } from './lib/setup'export { fcPatternOf, OSC11_PL, perlFor, PROGRAM_FONTS_PL, PROGRAM_FONTS_SH, WATCH_PL } from './lib/host'export {convertCall, isSafePage, measureCall, noNetworkEnv, pageRowsOf, parseOd, pngSize, probeCall, resultOf, roomInputs, shouldRetrySafe, typstCall, typstInputs,@@ -824,19 +824,25 @@ export const register: Register = on => {? `Intelligent UI draws no pictures: ${S.cacheProblem} (it never uses a shared folder instead)`: ready.canDraw? `this terminal draws pictures${ready.inline ? ' (over ssh, sent as bytes)' : ''}`- : 'Claude Code draws no pictures here (it does in kitty and Ghostty, in iTerm2 3.6+ and Rio 0.5.27+ with CLAUDE_CODE_FORCE_TERMINAL_IMAGES=1, over ssh when TERM names kitty or Ghostty or with that variable; never in tmux, screen or a background session; not in WezTerm, Warp, Konsole or others), so answers stay text'+ : S.isHerdr && S.setupNeeded+ ? 'Claude Code draws no pictures in herdr until CLAUDE_CODE_FORCE_TERMINAL_IMAGES=1 is set when it starts (run /iui setup), so answers stay text'+ : 'Claude Code draws no pictures here (it does in kitty and Ghostty, in iTerm2 3.6+, Rio 0.5.27+ and herdr with CLAUDE_CODE_FORCE_TERMINAL_IMAGES=1, over ssh when TERM names kitty or Ghostty or with that variable; never in tmux, screen or a background session; not in WezTerm, Warp, Konsole or others), so answers stay text'+ // In herdr: its version and the terminal it runs in.+ const herdr = S.isHerdr ? `terminal ${herdrText(S.herdrVersion, S.herdrHost)}: ` : ''await clipWayReady()const auto = `Picture select: ${selectState()}\n/iui grab hint: ${hintOf(state === 'on')}`const updates = `Update checks: ${updateLine(await updateState($))}`- return { text: `Intelligent UI is ${state}, theme ${theme}, ${modeLine(S.theme, S.setting, S.settingRaw, S.host)}, text size ${S.size}%, width ${widthText(S.width)}, image and drawing height ${heightText(S.height)}, row grid ${S.grid ? 'on' : 'off'}, picture select ${S.select ? 'on' : 'off'}, ${font}. ${typst}; ${terminal}.\n${auto}\n${updates}` }+ return { text: `Intelligent UI is ${state}, theme ${theme}, ${modeLine(S.theme, S.setting, S.settingRaw, S.host)}, text size ${S.size}%, width ${widthText(S.width)}, image and drawing height ${heightText(S.height)}, row grid ${S.grid ? 'on' : 'off'}, picture select ${S.select ? 'on' : 'off'}, ${font}. ${typst}; ${herdr}${terminal}.\n${auto}\n${updates}` }}// The short state: what is set, and only the problems that keep pictures away.const sized = (v: number | 'full' | 'half', unit: string) => (typeof v === 'number' ? `${v} ${unit}` : v)const lines = [`Intelligent UI is ${state}: theme ${theme}, ${S.theme}, text ${S.size}%, width ${sized(S.width, 'columns')}, height ${sized(S.height, 'rows')}, grid ${S.grid ? 'on' : 'off'}.`]if (S.cacheProblem) lines.push(`No pictures: ${S.cacheProblem}. See /iui details.`)- else if (S.setupNeeded) lines.push('In iTerm2, run /iui setup once to show pictures.')+ else if (S.setupNeeded) lines.push(`In ${S.isHerdr ? 'herdr' : 'iTerm2'}, run /iui setup once to show pictures.`)else if (!ready.canDraw) {- const where = ready.isMac ? 'kitty, Ghostty and iTerm2 3.6+' : 'kitty and Ghostty, and in Rio with CLAUDE_CODE_FORCE_TERMINAL_IMAGES=1'+ const where = ready.isMac+ ? 'kitty, Ghostty and iTerm2 3.6+, and in herdr with /iui setup'+ : 'kitty and Ghostty, in herdr with /iui setup, and in Rio with CLAUDE_CODE_FORCE_TERMINAL_IMAGES=1'lines.push(`This terminal shows no pictures, so answers stay text. Pictures show in ${where}.`)}if (!ready.typst) lines.push(`Typst is not installed, so answers stay text. Install it: ${typstHintOf(ready.isMac)}`)diff --git a/tests/draw.test.ts b/tests/draw.test.tsindex fc08f25..da6746a 100644--- a/tests/draw.test.ts+++ b/tests/draw.test.ts@@ -1,8 +1,8 @@import { expect, mock, test } from 'claude-code/testing'import {- alignFirstLine, scaledBulletRow, base64Bytes, canDrawIn, COMMIT_MIN_MS, DEFAULT_CELL, fileHref, fitsInline, INLINE_MAX_BYTES, INLINE_MAX_SIDE, inlineBudget, renderKey,- RESIZE_QUIET_MS, resolveLinks, SEGMENT_ROWS, WATCH_PL,+ alignFirstLine, scaledBulletRow, base64Bytes, canDrawIn, COMMIT_MIN_MS, DEFAULT_CELL, fileHref, fitsInline, herdrBudget, HERDR_MAX_PAGE_BYTES, INLINE_MAX_BYTES,+ INLINE_MAX_SIDE, inlineBudget, renderKey, RESIZE_QUIET_MS, resolveLinks, SEGMENT_ROWS, segmentBudget, sizing, WATCH_PL,} from '../hooks/register'import { TABLE_GRID } from './table-fixture'// This file's own copy of the drawing code, called with a fake `$`.@@ -57,6 +57,42 @@ test('over ssh a segment is cut so its page stays under 4096 px tall', () => {expect(inlineBudget(DEFAULT_CELL) * DEFAULT_CELL.height).toBeLessThan(INLINE_MAX_SIDE)})+test('under herdr a segment is cut so its page stays under 16 MiB of RGBA', () => {+ // The page is as wide as its columns in device pixels (sizing).+ expect(sizing(187, { width: 16, height: 34 }, 6).widthPx).toBe(2992)+ // A wide page on a Retina screen: 41 rows fit, 30 with the room for the rough count.+ expect(herdrBudget(187, { width: 16, height: 34 })).toBe(30)+ expect(herdrBudget(187, { width: 16, height: 34 }) * 34 * 2992 * 4 / 0.75).toBeLessThanOrEqual(HERDR_MAX_PAGE_BYTES)+ // A small page keeps the normal budget; a huge one at least 20 rows.+ expect(herdrBudget(80, { width: 8, height: 16 })).toBe(SEGMENT_ROWS)+ expect(herdrBudget(255, { width: 40, height: 80 })).toBe(20)+ // The cell width counts as sizing rounds it.+ expect(herdrBudget(100, { width: 15.5, height: 30 })).toBe(Math.floor((HERDR_MAX_PAGE_BYTES / (4 * 1550 * 30)) * 0.75))+})++test('the segment budget: the smaller of the ssh and herdr ones that apply', () => {+ const big = { width: 16, height: 34 }+ expect(segmentBudget({ inline: false }, 187, big)).toBe(SEGMENT_ROWS)+ expect(segmentBudget({ inline: false, herdr: false }, 187, big)).toBe(SEGMENT_ROWS)+ expect(segmentBudget({ inline: false, herdr: true }, 187, big)).toBe(herdrBudget(187, big))+ expect(segmentBudget({ inline: true }, 187, big)).toBe(inlineBudget(big))+ // Over ssh into herdr: the herdr budget (30) is under the ssh one (90).+ expect(inlineBudget(big)).toBe(90)+ expect(segmentBudget({ inline: true, herdr: true }, 187, big)).toBe(30)+ // A narrow page: the ssh budget is the smaller one.+ expect(segmentBudget({ inline: true, herdr: true }, 40, big)).toBe(inlineBudget(big))+})++test('pages cut for herdr have keys of their own; other keys do not change', () => {+ const o = {+ textHash: 'h', columns: 100, cell: DEFAULT_CELL, size: 100, mode: 'dark' as const, termFont: '', columnPt: 6,+ templateStamp: '1', look: { name: 'vscode', dir: '/t', stamp: '0' },+ }+ expect(renderKey({ ...o, herdr: false })).toBe(renderKey(o))+ expect(renderKey({ ...o, herdr: true })).not.toBe(renderKey(o))+ expect(renderKey({ ...o, herdr: true })).not.toBe(renderKey({ ...o, inline: true }))+})+test('pages cut for ssh have keys of their own; local keys do not change', () => {const o = {textHash: 'h', columns: 100, cell: DEFAULT_CELL, size: 100, mode: 'dark' as const, termFont: '', columnPt: 6,diff --git a/tests/frame.test.ts b/tests/frame.test.tsindex 8732cf6..c0547c1 100644--- a/tests/frame.test.ts+++ b/tests/frame.test.ts@@ -539,3 +539,23 @@ test('Ghostty is told by TERM_PROGRAM or TERM, and cmux (its engine) counts too'S.isCmux = was.cmux}})++test('herdr in Ghostty counts as Ghostty (its font and config); herdr elsewhere does not', () => {+ const was = { program: S.termProgram, name: S.termName, cmux: S.isCmux, host: S.herdrHost }+ try {+ S.isCmux = false+ S.termProgram = 'herdr'+ S.termName = 'xterm-256color'+ S.herdrHost = 'ghostty'+ expect(isGhosttyHere()).toBe(true)+ S.herdrHost = 'kitty'+ expect(isGhosttyHere()).toBe(false)+ S.herdrHost = ''+ expect(isGhosttyHere()).toBe(false)+ } finally {+ S.termProgram = was.program+ S.termName = was.name+ S.isCmux = was.cmux+ S.herdrHost = was.host+ }+})diff --git a/tests/mode.test.ts b/tests/mode.test.tsindex 2931cd5..c6048a7 100644--- a/tests/mode.test.ts+++ b/tests/mode.test.ts@@ -127,6 +127,69 @@ test('with the theme on auto, Ghostty draws as its background is', async ($, on)expect((await $.command.run({ command: 'iui', args: 'details' } as any)).text).toContain('mode dark (auto, from Ghostty: theme Night background)')})+// herdr in Ghostty on a light Mac: herdr's TERM_PROGRAM hides Ghostty, but+// its GHOSTTY_RESOURCES_DIR is kept, so Ghostty's dark config counts.+test('with the theme on auto, herdr in Ghostty draws as the Ghostty background is', async ($, on) => {+ mock.store(on)+ mock.clock(on)+ mock.env(on, { HOME: '/h', TERM_PROGRAM: 'herdr', HERDR_ENV: '1', TERM: 'xterm-256color', GHOSTTY_RESOURCES_DIR: '/R', CLAUDE_CODE_FORCE_TERMINAL_IMAGES: '1' })+ on('config.list', async () => ({ value: [{ key: 'theme', value: 'auto' }] as any }))+ const ok = (stdout: string, exitCode = 0) => ({ value: { exitCode, stdout, stderr: '', isStdoutTruncated: false, isStderrTruncated: false } })+ on('process.run', async ($: any, e: any, next: any) => {+ const argv: string[] = e.argv+ const cmd = argv.join(' ')+ if (argv[0] === 'sh' && /cc-intelligent-ui-/.test(cmd)) return ok('/tmp/mdp\nDarwin\n')+ if (argv[0] === 'sh' && cmd.includes('+show-config')) return ok('background = #1d1f21\n')+ if (argv[0] === 'defaults' && argv.includes('AppleInterfaceStyle')) return ok('', 1)+ return next(e)+ })+ const ran = await $.command.run({ command: 'iui', args: 'details' } as any)+ expect(ran.text).toContain('mode dark (auto, from Ghostty: config background)')+})++// herdr in iTerm2 on a light Mac: ITERM_PROFILE is kept, so the profile counts.+test('with the theme on auto, herdr in iTerm2 draws as the iTerm2 profile is', async ($, on) => {+ mock.store(on)+ mock.clock(on)+ mock.env(on, { HOME: '/h', TERM_PROGRAM: 'herdr', HERDR_ENV: '1', TERM: 'xterm-256color', ITERM_PROFILE: 'Default', CLAUDE_CODE_FORCE_TERMINAL_IMAGES: '1' })+ on('config.list', async () => ({ value: [{ key: 'theme', value: 'auto' }] as any }))+ const dark = { 'Red Component': 0.11, 'Green Component': 0.15, 'Blue Component': 0.17 }+ const marks = JSON.stringify([{ Name: 'Default', Guid: 'G1', 'Background Color': dark }])+ const ok = (stdout: string, exitCode = 0) => ({ value: { exitCode, stdout, stderr: '', isStdoutTruncated: false, isStderrTruncated: false } })+ on('process.run', async ($: any, e: any, next: any) => {+ const argv: string[] = e.argv+ const cmd = argv.join(' ')+ if (argv[0] === 'sh' && /cc-intelligent-ui-/.test(cmd)) return ok('/tmp/mdp\nDarwin\n')+ if (argv[0] === 'sh' && cmd.includes('TabStyleWithAutomaticOption')) return ok(`0\n@\nG1\n@\n${marks}\n`)+ if (argv[0] === 'defaults' && argv.includes('AppleInterfaceStyle')) return ok('', 1)+ return next(e)+ })+ const ran = await $.command.run({ command: 'iui', args: 'details' } as any)+ expect(ran.text).toContain('mode dark (auto, from iTerm2: profile Default background)')+ expect(ran.text).toContain('terminal herdr (in iTerm2): ')+})++// herdr with no hint of its terminal: as before, COLORFGBG, then the OS.+test('with the theme on auto, herdr in a terminal it does not know follows the OS', async ($, on) => {+ mock.store(on)+ mock.clock(on)+ mock.env(on, { HOME: '/h', TERM_PROGRAM: 'herdr', HERDR_ENV: '1', TERM: 'xterm-256color', CLAUDE_CODE_FORCE_TERMINAL_IMAGES: '1' })+ on('config.list', async () => ({ value: [{ key: 'theme', value: 'auto' }] as any }))+ const ok = (stdout: string, exitCode = 0) => ({ value: { exitCode, stdout, stderr: '', isStdoutTruncated: false, isStderrTruncated: false } })+ const ran: string[] = []+ on('process.run', async ($: any, e: any, next: any) => {+ const argv: string[] = e.argv+ const cmd = argv.join(' ')+ ran.push(cmd)+ if (argv[0] === 'sh' && /cc-intelligent-ui-/.test(cmd)) return ok('/tmp/mdp\nDarwin\n')+ if (argv[0] === 'defaults' && argv.includes('AppleInterfaceStyle')) return ok('', 1)+ return next(e)+ })+ const got = await $.command.run({ command: 'iui', args: 'details' } as any)+ expect(got.text).toContain('mode light (auto, from macOS)')+ expect(ran.some(c => c.includes('+show-config') || c.includes('TabStyleWithAutomaticOption'))).toBe(false)+})+// kitty on a light Mac: kitty.conf's included theme is dark; once auto theme// files exist, the one for the OS scheme is used.test('with the theme on auto, kitty draws as its config or auto theme is', async ($, on) => {diff --git a/tests/setup.test.ts b/tests/setup.test.tsindex e918669..1c0400f 100644--- a/tests/setup.test.ts+++ b/tests/setup.test.ts@@ -1,6 +1,6 @@import { expect, mock, test } from 'claude-code/testing'-import { hasSetup, SETUP_END, SETUP_START, setupBlock, shellRcOf, withoutSetup, withSetup } from '../hooks/register'+import { hasNewSetup, hasSetup, SETUP_END, SETUP_START, setupBlock, setupWordsOf, shellRcOf, withoutSetup, withSetup } from '../hooks/register'test('the setup writes the start file of the login shell', () => {expect(shellRcOf({ shell: '/bin/zsh', home: '/h', isMac: true })).toEqual({ path: '/h/.zshrc', kind: 'sh' })@@ -19,12 +19,40 @@ test('the start file: an empty ZDOTDIR or XDG_CONFIG_HOME is not used, a shell wexpect(shellRcOf({ shell: '/bin/zsh-5.9', home: '/h', isMac: true })).toBe(null)})-test('the block sets the variable in iTerm2 only, not in tmux or screen', () => {+test('the block sets the variable in iTerm2 and herdr only, not in tmux or screen', () => {const sh = setupBlock('sh')expect(sh.startsWith(`${SETUP_START}\n`)).toBe(true)expect(sh.endsWith(`${SETUP_END}\n`)).toBe(true)- expect(sh).toContain('[ "$TERM_PROGRAM" = "iTerm.app" ] && [ -z "$TMUX" ] && [ -z "$STY" ]; then export CLAUDE_CODE_FORCE_TERMINAL_IMAGES=1; fi')- expect(setupBlock('fish')).toContain('set -gx CLAUDE_CODE_FORCE_TERMINAL_IMAGES 1')+ expect(sh).toContain(+ 'if { [ "$TERM_PROGRAM" = "iTerm.app" ] || [ "$TERM_PROGRAM" = "herdr" ]; } && [ -z "$TMUX" ] && [ -z "$STY" ]; then export CLAUDE_CODE_FORCE_TERMINAL_IMAGES=1; fi',+ )+ const fish = setupBlock('fish')+ expect(fish.startsWith(`${SETUP_START}\n`)).toBe(true)+ expect(fish).toContain(+ 'if test "$TERM_PROGRAM" = "iTerm.app" -o "$TERM_PROGRAM" = "herdr"; and not set -q TMUX; and not set -q STY; set -gx CLAUDE_CODE_FORCE_TERMINAL_IMAGES 1; end',+ )+})++// The block of 0.3.2 and before: iTerm2 only.+const OLD_SH = `${SETUP_START}\nif [ "$TERM_PROGRAM" = "iTerm.app" ] && [ -z "$TMUX" ] && [ -z "$STY" ]; then export CLAUDE_CODE_FORCE_TERMINAL_IMAGES=1; fi\n${SETUP_END}\n`+const OLD_FISH = `${SETUP_START}\nif test "$TERM_PROGRAM" = "iTerm.app"; and not set -q TMUX; and not set -q STY; set -gx CLAUDE_CODE_FORCE_TERMINAL_IMAGES 1; end\n${SETUP_END}\n`++test('an old block (iTerm2 only) is a block, but not the new one; adding the block replaces it', () => {+ const rc = `export A=1\n\n${OLD_SH}`+ expect(hasSetup(rc)).toBe(true)+ expect(hasNewSetup(rc, 'sh')).toBe(false)+ const now = withSetup(rc, 'sh')+ expect(now).toBe(`export A=1\n\n${setupBlock('sh')}`)+ expect(hasNewSetup(now, 'sh')).toBe(true)+ expect(hasNewSetup(withSetup(OLD_FISH, 'fish'), 'fish')).toBe(true)+ expect(hasNewSetup(OLD_FISH, 'fish')).toBe(false)+ // The sh block is not the fish one.+ expect(hasNewSetup(setupBlock('sh'), 'fish')).toBe(false)+})++test('the words for the terminal: herdr panes, iTerm2 tabs', () => {+ expect(setupWordsOf(true)).toEqual({ app: 'herdr', tab: 'pane' })+ expect(setupWordsOf(false)).toEqual({ app: 'iTerm2', tab: 'tab' })})test('adding the block twice keeps one; removing it gives the file back', () => {@@ -57,8 +85,9 @@ test('a block of the other kind is replaced, not added next to the first', () =>expect(sh.startsWith('set -x A 1\n\n')).toBe(true)})-// An iTerm2 session on a Mac with the engine's pictures off and a zsh user.-const iterm = (on: any, files: Record<string, string>, answer: string | null, o: { env?: Record<string, string>; stored?: Record<string, unknown> } = {}) => {+// An iTerm2 session on a Mac with the engine's pictures off and a zsh user+// (`os`: another OS, `answer`: the option chosen, any question).+const iterm = (on: any, files: Record<string, string>, answer: string | null, o: { env?: Record<string, string>; stored?: Record<string, unknown>; os?: string } = {}) => {const store = new Map(Object.entries(o.stored ?? {}))on('store.get', async ($: any, e: any) => ({ value: store.get(e.key) }))on('store.set', async ($: any, e: any) => (store.set(e.key, e.value), { value: undefined }))@@ -80,7 +109,7 @@ const iterm = (on: any, files: Record<string, string>, answer: string | null, o:on('process.run', async ($: any, e: any, next: any) => {if (e.argv[0] === 'mkdir') return mkdirs.push(e.argv.slice(1).join(' ')), { value: { exitCode: 0, stdout: '', stderr: '', isStdoutTruncated: false, isStderrTruncated: false } }return e.argv[0] === 'sh' && /cc-intelligent-ui-/.test(e.argv.join(' '))- ? { value: { exitCode: 0, stdout: '/tmp/mdp\nDarwin\n', stderr: '', isStdoutTruncated: false, isStderrTruncated: false } }+ ? { value: { exitCode: 0, stdout: `/tmp/mdp\n${o.os ?? 'Darwin'}\n`, stderr: '', isStdoutTruncated: false, isStderrTruncated: false } }: next(e)})on('fs.read', async ($: any, e: any, next: any) => (e.path in files ? { value: files[e.path] } : e.path.startsWith('/h/') ? { deny: 'no such file' } : next(e)))@@ -224,3 +253,91 @@ test('a yes with a shell it does not know changes no file; the toast points to texpect(files['/h/.zshrc']).toBe('')expect(toasts.filter(t => /transcript|tab/.test(t))).toEqual(['See the transcript for the setup.'])})++// ---- herdr ------------------------------------------------------------------------++// A herdr pane (in no known terminal) with the engine's pictures off.+const HERDR = { TERM_PROGRAM: 'herdr', TERM_PROGRAM_VERSION: '0.9.5', HERDR_ENV: '1', TERM: 'xterm-256color', ITERM_PROFILE: '' }++test('in herdr with pictures off, the plugin asks once and adds the block on yes; the texts name herdr panes', async ($, on) => {+ const files: Record<string, string> = { '/h/.zshrc': 'export A=1\n' }+ const { asked, clock, toasts, logs } = iterm(on, files, 'Add the line', { env: HERDR })+ const shown = await $.command.run({ command: 'iui', args: '' } as any)+ expect(shown.text).toContain('In herdr, run /iui setup once to show pictures.')+ await clock.settle()+ expect(asked.length).toBe(1)+ expect(asked[0]).toContain('in herdr Claude Code needs CLAUDE_CODE_FORCE_TERMINAL_IMAGES=1')+ expect(asked[0]).toContain('Add one line to ~/.zshrc that sets it in iTerm2 and herdr only')+ expect(files['/h/.zshrc']).toBe(`export A=1\n\n${setupBlock('sh')}`)+ expect(toasts.filter(t => /pane|tab/.test(t))).toEqual(['Close this pane and open a new herdr pane to see pictures.'])+ expect(logs.some(l => l.includes('Added the Intelligent UI block to /h/.zshrc. Close this pane, open a new herdr pane, and start Claude Code there'))).toBe(true)+ const again = await $.command.run({ command: 'iui', args: 'setup' } as any)+ expect(again.text).toBe('/h/.zshrc already has the Intelligent UI block. Close this pane, open a new herdr pane, and start Claude Code there to see pictures.')+ const removed = await $.command.run({ command: 'iui', args: 'setup remove' } as any)+ expect(removed.text).toBe('Removed the Intelligent UI block from /h/.zshrc. New herdr panes show answers as text.')+ expect(files['/h/.zshrc']).toBe('export A=1\n')+})++test('in herdr, an old block (iTerm2 only) is not enough: the question asks to update it, and a yes replaces it', async ($, on) => {+ const files: Record<string, string> = { '/h/.zshrc': `export A=1\n\n${OLD_SH}` }+ const { asked, clock, toasts, logs } = iterm(on, files, 'Update the line', { env: HERDR })+ await $.command.run({ command: 'iui', args: '' } as any)+ await clock.settle()+ expect(asked.length).toBe(1)+ expect(asked[0]).toContain('Update the Intelligent UI line in ~/.zshrc so that it sets it in herdr too')+ expect(files['/h/.zshrc']).toBe(`export A=1\n\n${setupBlock('sh')}`)+ expect(toasts.filter(t => /pane|tab/.test(t))).toEqual(['Close this pane and open a new herdr pane to see pictures.'])+ expect(logs.some(l => l.startsWith('Updated the Intelligent UI block in /h/.zshrc. Close this pane'))).toBe(true)+})++test('in herdr with the new block already there, no question', async ($, on) => {+ const files: Record<string, string> = { '/h/.zshrc': withSetup('export A=1\n', 'sh') }+ const { asked, clock } = iterm(on, files, 'Add the line', { env: HERDR })+ await $.command.run({ command: 'iui', args: '' } as any)+ await clock.settle()+ expect(asked).toEqual([])+})++test('in iTerm2, an old block is enough (no question); /iui setup updates it', async ($, on) => {+ const files: Record<string, string> = { '/h/.zshrc': OLD_SH }+ const { asked, clock } = iterm(on, files, 'Add the line')+ await $.command.run({ command: 'iui', args: '' } as any)+ await clock.settle()+ expect(asked).toEqual([])+ expect(files['/h/.zshrc']).toBe(OLD_SH)+ const ran = await $.command.run({ command: 'iui', args: 'setup' } as any)+ expect(ran.text).toBe('Updated the Intelligent UI block in /h/.zshrc. Close this tab, open a new iTerm2 tab, and start Claude Code there to see pictures. Undo with /iui setup remove.')+ expect(files['/h/.zshrc']).toBe(setupBlock('sh'))+})++test('in herdr on Linux, /iui setup writes the block to .bashrc for bash (herdr starts no login shell there)', async ($, on) => {+ const files: Record<string, string> = { '/h/.bashrc': 'export A=1\n' }+ const { asked, clock } = iterm(on, files, 'Not now', { os: 'Linux', env: { ...HERDR, SHELL: '/bin/bash' } })+ const shown = await $.command.run({ command: 'iui', args: '' } as any)+ expect(shown.text).toContain('In herdr, run /iui setup once to show pictures.')+ await clock.settle()+ expect(asked.length).toBe(1)+ const ran = await $.command.run({ command: 'iui', args: 'setup' } as any)+ expect(ran.text).toBe('Added the Intelligent UI block to /h/.bashrc. Close this pane, open a new herdr pane, and start Claude Code there to see pictures. Undo with /iui setup remove.')+ expect(files['/h/.bashrc']).toBe(`export A=1\n\n${setupBlock('sh')}`)+})++test('herdr with pictures on (the variable set): no question, no setup line', async ($, on) => {+ const files: Record<string, string> = { '/h/.zshrc': '' }+ const { asked, clock } = iterm(on, files, 'Add the line', { env: { ...HERDR, CLAUDE_CODE_FORCE_TERMINAL_IMAGES: '1' } })+ const shown = await $.command.run({ command: 'iui', args: '' } as any)+ expect(shown.text).not.toContain('/iui setup once')+ await clock.settle()+ expect(asked).toEqual([])+})++test('herdr in iTerm2 (ITERM_PROFILE kept) asks the herdr question, never the iTerm2 one', async ($, on) => {+ const files: Record<string, string> = { '/h/.zshrc': '' }+ const { asked, clock } = iterm(on, files, 'Not now', { env: { ...HERDR, ITERM_PROFILE: 'Default' } })+ const shown = await $.command.run({ command: 'iui', args: '' } as any)+ expect(shown.text).toContain('In herdr, run /iui setup once')+ await clock.settle()+ expect(asked.length).toBe(1)+ expect(asked[0]).toContain('in herdr Claude Code needs')+ expect(asked[0]).not.toContain('in iTerm2 Claude Code needs')+})diff --git a/tests/termfont.test.ts b/tests/termfont.test.tsindex e35674b..196d260 100644--- a/tests/termfont.test.ts+++ b/tests/termfont.test.ts@@ -215,6 +215,48 @@ fontTest("cmux: a font-family in cmux's own config counts", async ($, on) => {expect(await details($)).toContain('terminal font Fira Code.')})+// ---- herdr ----------------------------------------------------------------------++fontTest("herdr in Ghostty (GHOSTTY_RESOURCES_DIR kept): Ghostty's font-family; the details name herdr and Ghostty", async ($, on) => {+ world(on, {+ isMac: true,+ env: { TERM_PROGRAM: 'herdr', TERM_PROGRAM_VERSION: '0.9.5', HERDR_ENV: '1', TERM: 'xterm-256color', GHOSTTY_RESOURCES_DIR: '/R', CLAUDE_CODE_FORCE_TERMINAL_IMAGES: '1' },+ families: ['Iosevka'],+ run: shows('font-family = Iosevka\n'),+ })+ const text = await details($)+ expect(text).toContain('terminal font Iosevka.')+ expect(text).toContain('terminal herdr 0.9.5 (in Ghostty): this terminal draws pictures.')+})++fontTest("herdr in kitty (KITTY_INSTALLATION_DIR kept): kitty's font_family", async ($, on) => {+ world(on, {+ isMac: true,+ env: { TERM_PROGRAM: 'herdr', HERDR_ENV: '1', TERM: 'xterm-256color', KITTY_INSTALLATION_DIR: '/K', CLAUDE_CODE_FORCE_TERMINAL_IMAGES: '1' },+ families: ['Iosevka'],+ files: { '/h/.config/kitty/kitty.conf': 'font_family Iosevka\n' },+ })+ const text = await details($)+ expect(text).toContain('terminal font Iosevka.')+ expect(text).toContain('terminal herdr (in kitty): ')+})++fontTest('herdr in a terminal it does not know: no font, as before; the details say so', async ($, on) => {+ const w = world(on, { isMac: true, env: { TERM_PROGRAM: 'herdr', HERDR_ENV: '1', TERM: 'xterm-256color', CLAUDE_CODE_FORCE_TERMINAL_IMAGES: '1' }, run: shows('font-family = Iosevka\n') })+ const text = await details($)+ expect(text).toContain('terminal font not known (Menlo assumed)')+ expect(text).toContain('terminal herdr (outer terminal not known): this terminal draws pictures.')+ expect(w.ran.some(argv => argv.join(' ').includes('+show-config'))).toBe(false)+})++fontTest('herdr with pictures off: the details point to /iui setup', async ($, on) => {+ world(on, { isMac: true, env: { TERM_PROGRAM: 'herdr', HERDR_ENV: '1', TERM: 'xterm-256color', GHOSTTY_BIN_DIR: '/B' }, run: shows('font-family = Iosevka\n') })+ // The setup question (pictures are off in herdr) is dismissed.+ on('tool.call', { tool: 'AskUserQuestion' }, async () => ({ deny: 'dismissed' }))+ const text = await details($)+ expect(text).toContain('terminal herdr (in Ghostty): Claude Code draws no pictures in herdr until CLAUDE_CODE_FORCE_TERMINAL_IMAGES=1 is set when it starts (run /iui setup)')+})+// ---- kitty ----------------------------------------------------------------------const kittyConf = (line: string) => ({ '/h/.config/kitty/kitty.conf': `${line}\n` })diff --git a/tests/terminals.test.ts b/tests/terminals.test.tsindex ff144c7..cb35d89 100644--- a/tests/terminals.test.ts+++ b/tests/terminals.test.ts@@ -1,7 +1,8 @@import { expect, test } from 'claude-code/testing'import {- cmuxAppearanceOf, cmuxConfigOf, cmuxGhosttyConfigPath, cmuxSettingsOf, ghosttyBackgroundOf, ghosttyHasColors, ghosttyThemesOf, ghosttyValueOf, isItermIn, jsoncOf,+ cmuxAppearanceOf, cmuxConfigOf, cmuxGhosttyConfigPath, cmuxSettingsOf, ghosttyBackgroundOf, ghosttyHasColors, ghosttyThemesOf, ghosttyValueOf, herdrHostOf, herdrText,+ isHerdrIn, isItermIn, jsoncOf, needsSetup,KITTY_DEFAULT_BG, kittyAutoFileOf, kittyBackgroundOf, kittyConfigDirsOf, kittyEntriesOf, kittyFontOf, kittyIncludePath, kittyLinesOf,kittySchemeOfGnome, kittyValueOf,RIO_DEFAULT_BG, RIO_DEFAULT_FONT, rioBackgroundOf, rioConfigDirOf, rioFontOf, rioForcedOf, rioThemeNamesOf, rioThemePath, tomlStringsOf,@@ -208,6 +209,52 @@ test('iTerm2: TERM_PROGRAM, else (no TERM_PROGRAM) ITERM_PROFILE, ITERM_SESSION_expect(isItermIn({ program: 'ghostty', profile: 'Default', lcTerminal: 'iTerm2' })).toBe(false)})+// ---- herdr ----------------------------------------------------------------------++test('herdr: TERM_PROGRAM, else (no TERM_PROGRAM) HERDR_ENV; another TERM_PROGRAM wins', () => {+ expect(isHerdrIn({ program: 'herdr' })).toBe(true)+ expect(isHerdrIn({ program: 'Herdr', herdrEnv: '1' })).toBe(true)+ expect(isHerdrIn({ program: '', herdrEnv: '1' })).toBe(true)+ expect(isHerdrIn({ program: '', herdrEnv: '0' })).toBe(false)+ expect(isHerdrIn({ program: '' })).toBe(false)+ expect(isHerdrIn({ program: 'iTerm.app' })).toBe(false)+ // tmux in a herdr pane, or a terminal started from one.+ expect(isHerdrIn({ program: 'tmux', herdrEnv: '1' })).toBe(false)+ expect(isHerdrIn({ program: 'ghostty', herdrEnv: '1' })).toBe(false)+})++test("herdr's terminal: Ghostty, then kitty, then iTerm2, by the variables of the terminal that started it", () => {+ expect(herdrHostOf({})).toBe('')+ expect(herdrHostOf({ ghosttyResources: '/Applications/Ghostty.app/Contents/Resources/ghostty' })).toBe('ghostty')+ expect(herdrHostOf({ ghosttyBin: '/Applications/Ghostty.app/Contents/MacOS' })).toBe('ghostty')+ expect(herdrHostOf({ kittyPid: '123' })).toBe('kitty')+ expect(herdrHostOf({ kittyDir: '/Applications/kitty.app/Contents/Resources/kitty' })).toBe('kitty')+ expect(herdrHostOf({ itermProfile: 'Default' })).toBe('iterm')+ expect(herdrHostOf({ ghosttyResources: '/g', kittyPid: '1', itermProfile: 'Default' })).toBe('ghostty')+ expect(herdrHostOf({ kittyPid: '1', itermProfile: 'Default' })).toBe('kitty')+ expect(herdrHostOf({ ghosttyResources: '', kittyPid: '', itermProfile: '' })).toBe('')+})++test('herdr in /iui details: its version and its terminal', () => {+ expect(herdrText('0.9.5', 'ghostty')).toBe('herdr 0.9.5 (in Ghostty)')+ expect(herdrText('0.9.5', 'kitty')).toBe('herdr 0.9.5 (in kitty)')+ expect(herdrText('', 'iterm')).toBe('herdr (in iTerm2)')+ expect(herdrText('', '')).toBe('herdr (outer terminal not known)')+})++test('/iui setup is offered in iTerm2 on a Mac and in herdr (macOS or Linux), with pictures off, not in ssh, tmux, screen or a background session', () => {+ const off = { iterm: false, herdr: false, draws: false, ssh: false, os: 'Darwin', tmux: false, background: false }+ expect(needsSetup({ ...off, iterm: true })).toBe(true)+ expect(needsSetup({ ...off, iterm: true, os: 'Linux' })).toBe(false)+ expect(needsSetup({ ...off, herdr: true })).toBe(true)+ expect(needsSetup({ ...off, herdr: true, os: 'Linux' })).toBe(true)+ expect(needsSetup(off)).toBe(false)+ for (const no of [{ draws: true }, { ssh: true }, { tmux: true }, { background: true }]) {+ expect(needsSetup({ ...off, herdr: true, ...no })).toBe(false)+ expect(needsSetup({ ...off, iterm: true, ...no })).toBe(false)+ }+})+test('JSONC: comments and trailing commas go, strings stay', () => {const text = '{\n "$schema": "https://x/y.json", // a comment\n /* block\n */ "app": { "appearance": "light", },\n "s": "a // b /* c */",\n}'expect(jsoncOf(text)).toEqual({ $schema: 'https://x/y.json', app: { appearance: 'light' }, s: 'a // b /* c */' })