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

Ghostty: the cell without the window padding; its own JetBrains Mono

razorback166facf15af9c3
diff --git a/docs/how-it-works.md b/docs/how-it-works.md
index 341ec7c..3b622be 100644
--- a/docs/how-it-works.md
+++ b/docs/how-it-works.md
@@ -7,7 +7,7 @@
1. A `ui.render` hook on `AssistantMessage` gets each block of the answer as Markdown.
2. While Claude writes a block, Claude Code shows its own text: Claude Code gives the hook the text of a block only when the block is complete (versions 2.1.299 to 2.1.303 at least). The block is final when the model request starts its next block (a tool call, more text) or ends. If the mod did not see the request, the block is final after its text stops changing for 400 ms. Then the mod writes the block to a JSON file and runs `typst compile` with `render/md.typ`. For plain text, Typst loads only some fonts (refer to [The lean font set](#the-lean-font-set)). Long answers are cut at block boundaries into pages. One page is one PNG.
3. The hook draws one `Image` per PNG, in place of the text.
-4. Text size: the mod finds the terminal font (iTerm2 profile, Ghostty, kitty or Rio config; on Linux, else fontconfig's `monospace` font; else the metrics of the theme's code font, Menlo on macOS) and the cell size in pixels. Typst then measures both fonts so that 100% looks as large as the terminal text.
+4. Text size: the mod finds the terminal font (iTerm2 profile, Ghostty, kitty or Rio config; on Linux, else fontconfig's `monospace` font; else the metrics of the theme's code font, Menlo on macOS) and the cell size in pixels. Typst then measures both fonts so that 100% looks as large as the terminal text. Body text and code use the terminal font, so at 100% they are exactly the terminal's size. Ghostty and cmux draw their own JetBrains Mono when their config names no font. This font is not a file: it is inside the Ghostty program. The first time, the mod copies it to `~/.cache/cc-intelligent-ui/fonts/` (approximately 0.1 s, once for each Ghostty version), so that Typst can draw it. In Ghostty and cmux, the mod also removes the window padding from the cell size, because Ghostty adds the padding to the pixel size that it reports.
5. If a compile fails (a bad Typst block or an unknown LaTeX command), the mod compiles once more in safe mode: Typst blocks and math show as code. A dim line under the picture names the error. If that also fails, the normal text shows.
6. Pictures are kept in `${TMPDIR}/cc-intelligent-ui-<uid>/` (`/tmp` when `TMPDIR` is not set). Folders older than 2 days are deleted at start. The drawing space of each answer at its first compile is kept in `~/.cache/cc-intelligent-ui/designs`, so that its Typst drawings keep the same share of the screen in later sessions.
7. Links: the mod finds the web links, file paths and commands in the Markdown (not in code blocks or math). It draws one dim row for each under the pages, with a `Link` (an OSC 8 link) for a web link or a file, and a `Button` that copies a command (`$.ui.copy`). It keeps a file row only when the file exists (`$.fs.exists`, kept in memory for 512 paths). Each row is one terminal row, cut at its end. The copy (step 9) counts these rows under the pages, so it still finds the page that you select.
diff --git a/docs/install.md b/docs/install.md
index 91b3815..1047615 100644
--- a/docs/install.md
+++ b/docs/install.md
@@ -55,7 +55,7 @@ The mod finds Typst on the `PATH` of your login shell. It also looks in `/usr/lo
The mod works on Linux with X11 and with Wayland. It uses these tools. Most Linux systems have the first three.
- **perl** (perl 5): reads the terminal size and its cell size, and watches for a change of the size.
-- **fontconfig** (`fc-match`, `fc-list`): finds the terminal font when the terminal's config does not name one. kitty and most terminals use fontconfig's `monospace` font. Ghostty uses its own JetBrains Mono when its config names no font. The mod uses JetBrains Mono only when fontconfig has it, because Typst must find the font too.
+- **fontconfig** (`fc-match`, `fc-list`): finds the terminal font when the terminal's config does not name one. kitty and most terminals use fontconfig's `monospace` font. Ghostty uses its own JetBrains Mono when its config names no font. If fontconfig does not have JetBrains Mono, the mod copies the font from the Ghostty program (refer to [How it works](how-it-works.md)).
- **The light or dark mode of the desktop** (for the `auto` theme): the freedesktop portal (`org.freedesktop.appearance color-scheme`, through `gdbus` or `busctl`). GNOME, KDE Plasma and most desktops have the portal. If the portal does not answer, the mod reads GNOME's `color-scheme` (`gsettings`).
- **The clipboard** (for the automatic copy in fullscreen mode and for `/iui grab` on the main screen, refer to [Copy text from a picture](usage.md#copy-text-from-a-picture)). The mod uses the first of these that it finds:
1. **Wayland, not GNOME:** `wl-paste` from `wl-clipboard`. `wl-paste --watch` tells the mod about each clipboard change. It needs the data-control protocol of the compositor (KDE Plasma, Sway, Hyprland and other wlroots compositors have it).
diff --git a/hooks/lib/env.ts b/hooks/lib/env.ts
index 3b0e9d2..c90f444 100644
--- a/hooks/lib/env.ts
+++ b/hooks/lib/env.ts
@@ -102,7 +102,7 @@ export function setUp($: EngineInterface): Promise<Env> {
uiToast($, noTypstOf(isMac), { timeoutMs: 8000 })
} catch {}
}
- const termFont = await termFontOf($, program, isMac).catch(() => '')
+ const termFont = await termFontOf($, isMac).catch(() => '')
const home = (await envGet($, 'HOME')) ?? ''
const designs = made3.trim() || (home ? `${home}/.cache/cc-intelligent-ui/designs` : `${cache}/designs`)
const stored = await storeGet($, 'theme-name').catch(() => undefined)
diff --git a/hooks/lib/fonts.ts b/hooks/lib/fonts.ts
index f7aaf9c..8dee1d7 100644
--- a/hooks/lib/fonts.ts
+++ b/hooks/lib/fonts.ts
@@ -18,7 +18,8 @@ import { fsExists, processRun } from './api'
export const SKIPPED_FONTS = /emoji|cjk|pingfang|hiragino|gothic|han sans|han serif|yahei|jhenghei|meiryo|malgun|simsun|simhei|wenquanyi|droid sans fallback/i
// One font face of `typst fonts --variants`: its file (null: in Typst
-// itself) and its variant (`Normal, Weight: 400, Stretch: 100%`).
+// itself; a variable font's ` (Variable)` mark is cut) and its variant
+// (`Normal, Weight: 400, Stretch: 100%`).
export type Face = { file: string | null; variant: string }
// `typst fonts --variants` as faces by family (lower case, as Typst
@@ -36,7 +37,7 @@ export function fontListOf(stdout: string): Map<string, Face[]> {
}
const at = /^\s+[├└]\S*\s+(.*)$/.exec(line)
if (at) {
- file = at[1] === '(Embedded)' ? null : at[1]!.trim()
+ file = at[1] === '(Embedded)' ? null : at[1]!.replace(/\s+\(Variable\)\s*$/, '').trim()
continue
}
const style = /^\s+\S*\s+Style:\s*(.*)$/.exec(line)
diff --git a/hooks/lib/frame.ts b/hooks/lib/frame.ts
index 0d141ad..24a31f7 100644
--- a/hooks/lib/frame.ts
+++ b/hooks/lib/frame.ts
@@ -12,7 +12,7 @@ import { BASE_THEME, DEFAULT_CELL, RESIZE_QUIET_MS } from './settings'
import { DEFAULT_METRICS, S, type Frame, type Metrics } from './state'
import { beginEpoch, holdJobs, releaseJobs } from './epoch'
import { pump } from './stream'
-import { columnsFor, sizeOf } from './terminal'
+import { columnsFor, isGhosttyHere, sizeOf } from './terminal'
import { CELL_SH, perlFor, termFontOf, WATCH_PL } from './host'
import { clipWatchArgs } from './clipboard'
import { measureFonts } from './typst'
@@ -28,7 +28,7 @@ export type View = { columns: number; rows: number }
// (the rule of sizeOf: no pixels, or a cell under 4 or over 64 px wide).
export function frameOfLine(line: string): Frame | null {
if (!/^\d+ \d+ \d+ \d+$/.test(line.trim())) return null
- const size = sizeOf(line)
+ const size = sizeOf(line, isGhosttyHere())
return size?.cell ? { columns: size.columns, rows: size.rows, cell: size.cell } : null
}
@@ -330,7 +330,7 @@ export function refont($: EngineInterface): Promise<boolean> {
fontAgain = false
const env = S.env
if (!env) return changed
- const termFont = (await termFontOf($, S.termProgram, env.isMac).catch(() => '')) || env.termFont
+ const termFont = (await termFontOf($, env.isMac).catch(() => '')) || env.termFont
const themeDir = S.look?.dir ?? `${env.root}/render/themes/${BASE_THEME}`
const read = env.typst ? await measureFonts($, env.typst, env.root, env.cache, termFont, themeDir).catch(() => DEFAULT_METRICS) : env.metrics
const metrics = read === DEFAULT_METRICS ? env.metrics : read
diff --git a/hooks/lib/host.ts b/hooks/lib/host.ts
index e20f21f..e00ec4e 100644
--- a/hooks/lib/host.ts
+++ b/hooks/lib/host.ts
@@ -16,6 +16,7 @@ import {
rioConfigDirOf, rioFontOf, rioForcedOf, rioThemeNamesOf, rioThemePath, tomlStringsOf, type CmuxAppearance, type KittyEntries,
} from './terminals'
import { firstLine } from './markdown'
+import { isGhosttyHere } from './terminal'
import { clockEvery, envGet, fsExists, fsRead, processRun } from './api'
// One tty size read: `rows cols xpixel ypixel` (TIOCGWINSZ); exit 1 with no tty.
@@ -88,6 +89,57 @@ const FAMILY_JXA = 'function run(argv) { ObjC.import("AppKit"); var f = $.NSFont
// iTerm2's appearance, the default profile's GUID and the profiles, split by "@" lines.
const ITERM_MODE_SH = `defaults read com.googlecode.iterm2 TabStyleWithAutomaticOption 2>/dev/null; echo @; ${ITERM_DEFAULT_SH} 2>/dev/null; echo @; ${ITERM_BOOKMARKS_SH}`
const GHOSTTY_SH = `"\${GHOSTTY_BIN_DIR:+\$GHOSTTY_BIN_DIR/}ghostty" +show-config`
+// Copies the JetBrains Mono that Ghostty carries in its program (no font
+// files: the TrueType data is inside it) to a folder that Typst can read,
+// once per Ghostty build: the variable Regular and Italic (an `fvar` table
+// and the family in the `name` table), each size once (a universal program
+// has a copy per CPU). The folder is in the user cache, by the program's
+// path, size and mtime; it prints the folder, and exit 1 when no font was
+// found. Made in a temporary folder first, so a compile never sees half.
+export const GHOSTTY_FONTS_PL = [
+ 'use strict;',
+ 'my $f = shift or exit 1;',
+ 'my @st = stat($f) or exit 1;',
+ 'my $base = ($ENV{XDG_CACHE_HOME} || "$ENV{HOME}/.cache") . "/cc-intelligent-ui/fonts";',
+ 'my $key = unpack("%32C*", $f) . "-$st[7]-$st[9]";',
+ 'my $d = "$base/ghostty-$key";',
+ 'if (-d $d) { utime(undef, undef, $d); print "$d\\n"; exit 0 }',
+ 'open(my $h, "<:raw", $f) or exit 1; my $b = do { local $/; <$h> }; close $h;',
+ 'my $want = "\\0" . join("\\0", split(//, "JetBrains Mono"));',
+ 'system("mkdir", "-p", $base) == 0 or exit 1;',
+ 'my $t = "$d.$$"; mkdir($t) or exit 1;',
+ 'my (%seen, $n);',
+ 'while ($b =~ /\\x00\\x01\\x00\\x00/g) {',
+ ' my $o = pos($b) - 4; my $k = unpack("n", substr($b, $o + 4, 2));',
+ ' next if $k < 4 || $k > 40;',
+ ' my ($end, $fvar, $name, $bad) = (0, 0, "", 0);',
+ ' for my $i (0 .. $k - 1) {',
+ ' my ($tag, $cs, $off, $len) = unpack("a4NNN", substr($b, $o + 12 + 16 * $i, 16));',
+ ' if ($tag !~ m{^[A-Za-z0-9/ ]{4}$} || $off + $len > 20000000) { $bad = 1; last }',
+ ' $end = $off + $len if $off + $len > $end;',
+ ' $fvar = 1 if $tag eq "fvar";',
+ ' $name = substr($b, $o + $off, $len) if $tag eq "name";',
+ ' }',
+ ' next if $bad || !$fvar || index($name, $want) < 0 || $seen{$end}++;',
+ ' open(my $w, ">:raw", "$t/JetBrainsMono-" . ++$n . ".ttf") or next;',
+ ' print $w substr($b, $o, $end); close $w;',
+ '}',
+ 'if (!$n) { rmdir $t; exit 1 }',
+ 'rename($t, $d) or system("rm", "-rf", $t);',
+ '-d $d or exit 1; print "$d\\n";',
+].join('\n')
+// Runs GHOSTTY_FONTS_PL (with the perl of perlFor) on the first Ghostty
+// program found: the one of GHOSTTY_BIN_DIR, the PATH's, then each other
+// argument (the apps' places).
+export const GHOSTTY_FONTS_SH = [
+ 'perl=$1; pl=$2; shift 2',
+ 'for f in "${GHOSTTY_BIN_DIR:+$GHOSTTY_BIN_DIR/ghostty}" "$(command -v ghostty)" "$@"; do',
+ ' [ -n "$f" ] && [ -f "$f" ] && exec "$perl" -e "$pl" "$f"',
+ 'done',
+ 'exit 1',
+].join('\n')
+// Where the apps keep their Ghostty program.
+const GHOSTTY_PROGRAMS = ['/Applications/cmux.app/Contents/Resources/bin/ghostty', '/Applications/Ghostty.app/Contents/MacOS/ghostty']
// Asks the terminal for its background (OSC 11) and prints the answer. It
// opens the tty itself, non-blocking, changes no tty mode, and waits 300 ms at
// most. Claude Code reads the same tty, so the answer may go to it instead.
@@ -114,10 +166,10 @@ export const HEADERS_SH = `for f in "$@"; do head -c 24 "$f" | od -An -v -tx1; e
// kitty's font_family, Rio's [fonts] family; '' elsewhere or when it can't
// be read. On Linux, when the terminal's config names none: fontconfig's
// monospace font (fc-match), which kitty and most terminals use.
-export async function termFontOf($: EngineInterface, program: string, isMac: boolean): Promise<string> {
+export async function termFontOf($: EngineInterface, isMac: boolean): Promise<string> {
// Over ssh, a config here is not the one of the user's terminal.
if (S.isRemote) return ''
- const font = await configFontOf($, program, isMac)
+ const font = await configFontOf($, isMac)
if (font || isMac) return font
return fcFamily($, 'monospace')
}
@@ -129,15 +181,21 @@ async function fcFamily($: EngineInterface, pattern: string): Promise<string> {
return got?.exitCode === 0 ? familyOfFc(got.stdout) : ''
}
-// Ghostty draws its own JetBrains Mono when no font-family is set. On Linux
-// it is used when fontconfig has it too (Typst can then draw it).
-async function ghosttyDefaultFont($: EngineInterface): Promise<string> {
+// Ghostty draws its own JetBrains Mono when no font-family is set. Typst
+// draws it from the system's fonts when fontconfig has it (Linux), else
+// from a copy of the one in Ghostty's program (S.fontPaths).
+async function ghosttyDefaultFont($: EngineInterface, isMac: boolean): Promise<string> {
const got = await processRun($, ['fc-list', '-q', GHOSTTY_DEFAULT_FONT], { timeoutMs: 5000 }).catch(() => null)
- return got?.exitCode === 0 ? GHOSTTY_DEFAULT_FONT : ''
+ if (got?.exitCode === 0) return GHOSTTY_DEFAULT_FONT
+ const made = await processRun($, ['sh', '-c', GHOSTTY_FONTS_SH, 'sh', perlFor(isMac), GHOSTTY_FONTS_PL, ...GHOSTTY_PROGRAMS], { timeoutMs: 10000 }).catch(() => null)
+ const dir = made?.exitCode === 0 ? firstLine(made.stdout) : ''
+ if (!dir) return ''
+ S.fontPaths = dir
+ return GHOSTTY_DEFAULT_FONT
}
// The font that the terminal's own config or profile names.
-async function configFontOf($: EngineInterface, program: string, isMac: boolean): Promise<string> {
+async function configFontOf($: EngineInterface, isMac: boolean): Promise<string> {
if (S.isIterm && isMac) {
const profile = await envGet($, 'ITERM_PROFILE')
const [marks, guid] = await Promise.all([
@@ -149,10 +207,9 @@ async function configFontOf($: EngineInterface, program: string, isMac: boolean)
const named = await processRun($, ['osascript', '-l', 'JavaScript', '-e', FAMILY_JXA, spec.name], { timeoutMs: 5000 }).catch(() => null)
return named?.exitCode === 0 ? firstLine(named.stdout) : ''
}
- if (/ghostty/i.test(program)) {
+ if (isGhosttyHere()) {
const shown = await processRun($, ['sh', '-c', GHOSTTY_SH], { timeoutMs: 5000 }).catch(() => null)
- const family = ghosttyFontOf(shown?.stdout ?? '')
- return family ?? (isMac ? '' : await ghosttyDefaultFont($))
+ return ghosttyFontOf(shown?.stdout ?? '') ?? (await ghosttyDefaultFont($, isMac))
}
if (S.isKitty) {
// A family name as is; a PostScript name to its family (macOS: AppKit;
diff --git a/hooks/lib/state.ts b/hooks/lib/state.ts
index c161427..3e8c3d6 100644
--- a/hooks/lib/state.ts
+++ b/hooks/lib/state.ts
@@ -167,6 +167,9 @@ export const S = {
// iTerm2 (isItermIn) and cmux (Ghostty inside, with its CMUX_* variables), set in setUp.
isIterm: false,
isCmux: false,
+ // A font folder for Typst (TYPST_FONT_PATHS): the fonts Ghostty carries in
+ // its program, when it draws them (no font-family set). '' for none.
+ fontPaths: '',
// Over ssh (set in setUp): the terminal's config and the OS appearance here
// are the remote computer's, not those of the user's screen.
isRemote: false,
diff --git a/hooks/lib/terminal.ts b/hooks/lib/terminal.ts
index 4aa7b09..8b564bc 100644
--- a/hooks/lib/terminal.ts
+++ b/hooks/lib/terminal.ts
@@ -32,16 +32,23 @@ export function fitBox(box: { columns: number; rows: number }, room: number): {
// WezTerm report device pixels already, so there is no backing-scale step.
// `cell` is null where the tty reports no pixels or a cell that can't be
// right (under 4 or over 64 px wide); the whole is null with no rows or
-// columns.
-export function sizeOf(stdout: string): { rows: number; columns: number; cell: Cell | null } | null {
+// columns. `padded`: the pixels include the window padding (Ghostty, cmux),
+// so the cell is rounded down to whole pixels (a cell is whole device
+// pixels, and the padding is less than one pixel per column or row).
+export function sizeOf(stdout: string, padded = false): { rows: number; columns: number; cell: Cell | null } | null {
const [rows, columns, x, y] = stdout.trim().split(/\s+/).map(Number)
if (!rows || !columns || !Number.isInteger(rows) || !Number.isInteger(columns)) return null
if (!x || !y) return { rows, columns, cell: null }
- const width = x / columns
- const height = y / rows
+ const width = padded ? Math.floor(x / columns) : x / columns
+ const height = padded ? Math.floor(y / rows) : y / rows
return { rows, columns, cell: width >= 4 && width <= 64 && height >= 4 ? { width, height } : null }
}
+// 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
+
// 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())
diff --git a/hooks/lib/typst.ts b/hooks/lib/typst.ts
index bf9a8b0..27e06dc 100644
--- a/hooks/lib/typst.ts
+++ b/hooks/lib/typst.ts
@@ -3,7 +3,7 @@
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 { DEFAULT_METRICS, type Cell, type FontMetrics, type Job, type LeanFonts, type Metrics, type Page, type Result } from './state'
+import { DEFAULT_METRICS, 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 { fontFit, placeFirstLine, sizing } from './draw'
@@ -15,7 +15,8 @@ import { leanFontsFor } from './fonts'
import { clockAfter, envGet, fsExists, fsList, fsRead, fsWrite, processRun, processSpawn } from './api'
// The typst command and its environment. Network off (see NO_NETWORK) and a
-// package cache of our own, so only the vendored packages load. `fonts`:
+// package cache of our own, so only the vendored packages load, and the
+// fonts of S.fontPaths (Ghostty's own font). `fonts`:
// the lean font folder (fonts.ts) in place of all system fonts.
export function typstCall(o: {
typst: string
@@ -85,6 +86,7 @@ export function noNetworkEnv(cache: string): Record<string, string> {
NO_PROXY: '',
no_proxy: '',
TYPST_PACKAGE_CACHE_PATH: `${cache}/pkg-cache`,
+ ...(S.fontPaths ? { TYPST_FONT_PATHS: S.fontPaths } : {}),
}
}
diff --git a/tests/fonts.test.ts b/tests/fonts.test.ts
index 3279ce7..a76f1a8 100644
--- a/tests/fonts.test.ts
+++ b/tests/fonts.test.ts
@@ -61,6 +61,28 @@ test('the font list reads each family with its files and variants', () => {
expect([...list.keys()].length).toBe(7)
})
+test('a variable font is read by its file, without the (Variable) mark', () => {
+ const list = fontListOf([
+ 'JetBrains Mono',
+ ' ├ /c/fonts/ghostty-1/JetBrainsMono-1.ttf (Variable)',
+ ' │ Style: Normal',
+ ' │ Stretch: 100%',
+ ' │ Weight: 100-800 (Default: 400)',
+ ' └ /c/fonts/ghostty-1/JetBrainsMono-2.ttf (Variable)',
+ ' Style: Italic',
+ ' Stretch: 100%',
+ ' Weight: 100-800 (Default: 400)',
+ '',
+ ].join('\n'))
+ expect(list.get('jetbrains mono')).toEqual([
+ { file: '/c/fonts/ghostty-1/JetBrainsMono-1.ttf', variant: 'Normal' },
+ { file: '/c/fonts/ghostty-1/JetBrainsMono-2.ttf', variant: 'Italic' },
+ ])
+ // The lean set links the two files first, as the terminal font.
+ const both = new Map([...fontListOf(LISTING), ...list])
+ expect(leanFiles(both, 'JetBrains Mono', FONTS)?.slice(0, 2)).toEqual(['/c/fonts/ghostty-1/JetBrainsMono-1.ttf', '/c/fonts/ghostty-1/JetBrainsMono-2.ttf'])
+})
+
test('the lean set has the terminal font and the Latin fonts, not the CJK and emoji fonts', () => {
expect(leanFiles(fontListOf(LISTING), 'MesloLGS NF', FONTS)).toEqual([
'/Users/me/Library/Fonts/MesloLGS NF Regular.ttf',
diff --git a/tests/pure.test.ts b/tests/pure.test.ts
index 311555d..a71cce5 100644
--- a/tests/pure.test.ts
+++ b/tests/pure.test.ts
@@ -13,7 +13,7 @@ import {
} from '../hooks/register'
import { DRAWING_ROWS } from '../hooks/lib/settings'
import { wrapPid } from '../hooks/lib/typst'
-import type { Env, Job } from '../hooks/lib/state'
+import { S, type Env, type Job } from '../hooks/lib/state'
import { placeFirstLine } from '../hooks/lib/draw'
import { DEFAULT_GRID, gridFirstRow, gridOf, gridRowsOf } from '../hooks/lib/grid'
@@ -435,6 +435,15 @@ test('the cell comes from the tty in device pixels, with no scale step', () => {
expect(sizeOf('50 20 1700 1700')?.cell).toBe(null)
})
+test('Ghostty pixels include the window padding: the cell is rounded down to whole pixels', () => {
+ // 183 x 42 cells of 16 x 34 px, with 8 px and 14 px of padding.
+ expect(sizeOf('42 183 2936 1442', true)?.cell).toEqual({ width: 16, height: 34 })
+ // Without the flag the padding goes into the cell.
+ expect(sizeOf('42 183 2936 1442')?.cell?.width).toBe(2936 / 183)
+ // Exact pixels stay exact.
+ expect(sizeOf('40 200 3200 1360', true)?.cell).toEqual({ width: 16, height: 34 })
+})
+
test('the terminal font is read from iTerm2 and Ghostty settings', () => {
expect(parseFontSpec('MesloLGS-NF-Regular 14')).toEqual({ name: 'MesloLGS-NF-Regular', size: 14 })
expect(parseFontSpec('Menlo-Regular 12.5')).toEqual({ name: 'Menlo-Regular', size: 12.5 })
@@ -451,6 +460,17 @@ test('the terminal font is read from iTerm2 and Ghostty settings', () => {
expect(ghosttyFontOf('font-size = 13')).toBe(null)
})
+test('typst also reads the font folder of the font that Ghostty carries, when there is one', () => {
+ const call = () => typstCall({ typst: 't', root: '/mod', cache: '/tmp/c', ppi: 144, inputs: {}, out: '/tmp/o.png' })
+ expect(call().env.TYPST_FONT_PATHS).toBe(undefined)
+ S.fontPaths = '/home/u/.cache/cc-intelligent-ui/fonts/ghostty-1'
+ try {
+ expect(call().env.TYPST_FONT_PATHS).toBe('/home/u/.cache/cc-intelligent-ui/fonts/ghostty-1')
+ } finally {
+ S.fontPaths = ''
+ }
+})
+
test('typst runs with the network off and its own package cache', () => {
const { argv, env } = typstCall({
typst: '/opt/homebrew/bin/typst', root: '/mod', cache: '/tmp/c', ppi: 210.5,