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

Fake bold by region; clean TYPST_FONT_PATHS; font names in any case

razorback167e5933a06955
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1ed588e..f240012 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,12 +19,12 @@ All releases of Intelligent UI for Claude Code (`cc-intelligent-ui`). Claude Cod
### Fixed
- **Rio:** the pictures use Rio's own font, Cascadia Code NF. This font is inside the Rio program, so Typst did not have it and drew the theme's fonts. Now the mod copies the font from the program, as it does for Ghostty's JetBrains Mono. A font in Rio's config that is not installed also gives Rio's own font, because Rio draws that font.
-- The terminal font is the font that the terminal draws, also when its config names a font that is not installed: Ghostty and cmux on macOS draw their JetBrains Mono, Ghostty and kitty on Linux draw the nearest font of fontconfig, kitty on macOS draws Menlo (also for a font that is not fixed-pitch), iTerm2 draws the user's fixed-pitch font. For a Ghostty `font-family` list, the first font of the list that is installed. kitty on macOS with no `font_family` now gives Menlo for body text too.
-- The font folder that the mod gives Typst goes after your own `TYPST_FONT_PATHS`. Before, it replaced it.
+- The terminal font is the font that the terminal draws, also when its config names a font that is not installed: Ghostty and cmux on macOS draw their JetBrains Mono, Ghostty and kitty on Linux draw the nearest font of fontconfig, kitty on macOS draws Menlo (also for a font that is not fixed-pitch), iTerm2 draws the user's fixed-pitch font. For a Ghostty `font-family` list, the first font of the list that is installed. kitty on macOS with no `font_family` now gives Menlo for body text too. A name in another case or spacing (for example `iosevkaterm`) gives the installed name, so that Typst finds the font.
+- The font folder that the mod gives Typst goes after your own `TYPST_FONT_PATHS`. Before, it replaced it. An empty entry in `TYPST_FONT_PATHS` (for example `/a:`) no longer stops each Typst run.
- iTerm2: a profile font with font settings after its size (for example, ligatures off) is read. Before, the terminal font was not known.
- cmux: a `font-family` in cmux's own config (`config.ghostty` in its Application Support folder) is read.
- `/iui details` tells you when Typst does not have the terminal font.
-- **Bold text in a terminal font with no bold face** (for example, Monaco in iTerm2): the pictures draw a fake bold, as the terminal does. Before, bold text in that font was drawn regular, because Typst does not make a bold face. Text in other fonts does not change.
+- **Bold text in a terminal font with no bold face** (for example, Monaco in iTerm2): the pictures draw a fake bold, as the terminal does. Before, bold text in that font was drawn regular, because Typst does not make a bold face. Text in other fonts does not change. Refer to [Limitations](docs/limitations.md).
- Picture select: a push of the button on a page that had just gone off the screen no longer waits for ever (no highlight until a reload).
- Picture select: two tall pages on the screen no longer make each other ready again and again (the page cache keeps the pages on the screen, and the page of the selection).
- Picture select: a drawing drawn again with new page files (a stream, a resize, a theme or size change) no longer keeps its old pages in the queue.
diff --git a/docs/limitations.md b/docs/limitations.md
index 2dab243..a63f624 100644
--- a/docs/limitations.md
+++ b/docs/limitations.md
@@ -32,6 +32,9 @@
- It needs `perl` (with `MIME::Base64`, a core module) to write the frames. With no `perl`, the selection and the copy work with no highlight (the mod tries one time, then writes the reason to the debug log).
- **The cache folder:** the mod uses only its private cache folder (`$TMPDIR/cc-intelligent-ui-<uid>`, mode 700, your own and not a link). If that folder is a link, is not a folder or is not yours, the mod draws nothing and picture select is off. `/iui`, `/iui details` and a toast at the start tell you why. Remove or fix that folder, then start Claude Code again.
- It copies at the button's up, also when `copyOnSelect` is `false` in `/config`.
+- **A fake bold** (a terminal font with no bold face, for example Monaco): bold text gets a thin outline in its colour. These limits apply:
+ - A character that the terminal font does not have (for example, CJK text in Monaco) comes from another font. If that font has a bold face, the character gets both the real bold face and the outline, so it is a little bolder than in the terminal.
+ - Bold text in a live Typst drawing (for example, `text(weight: "bold", font: theme.mono)`) does not get the fake bold. It shows as regular text.
- **Links in a picture:** a click on the picture does not open a link, because the mod cannot put a link on a picture. Use the link rows under the picture (refer to [Links, file paths and commands](usage.md#links-file-paths-and-commands)). A click on a command row copies the command only where Claude Code gets mouse clicks (fullscreen mode). A `file://` link opens in the app that the terminal chooses. A file row shows only when the file exists when the mod draws the answer.
- **PDF files** (refer to [What it draws](usage.md#what-it-draws)): a click on `‹`, `›` or the page number works only where Claude Code gets mouse clicks (fullscreen mode). The page field gets the keyboard only when the prompt is empty. If the prompt has text, the field opens without the keyboard: click the field to type. Then Esc goes to the prompt, not to the field. To close the field, click it and push Esc, or click its close mark. The mod draws one page at a time, and it does not show the number of pages. You cannot copy text from a PDF page.
- **The row grid** (`/iui grid on`, refer to [Selection and the row grid](usage.md#selection-and-the-row-grid)) has these limits:
diff --git a/hooks/lib/host.ts b/hooks/lib/host.ts
index 52adf9e..0185748 100644
--- a/hooks/lib/host.ts
+++ b/hooks/lib/host.ts
@@ -91,6 +91,8 @@ const FAMILY_JXA = 'function run(argv) { ObjC.import("AppKit"); var f = argv[0]
// Whether a family (argv[0]) is installed, as CoreText finds it by name:
// yes or no; with argv[1] `mono`, `proportional` when no style of it is fixed-pitch.
const HAS_FAMILY_JXA = 'function run(argv) { ObjC.import("AppKit"); var m = $.NSFontManager.sharedFontManager.availableMembersOfFontFamily(argv[0]); if (m.isNil()) return "no"; if (argv[1] !== "mono") return "yes"; for (var i = 0; i < m.count; i++) if (m.objectAtIndex(i).objectAtIndex(3).js & 0x400) return "yes"; return "proportional" }'
+// The installed family (`=Name`) whose name is argv[0] in any case, else `no`.
+const FAMILY_NOCASE_JXA = 'function run(argv) { ObjC.import("AppKit"); var a = $.NSFontManager.sharedFontManager.availableFontFamilies, w = argv[0].toLowerCase(); for (var i = 0; i < a.count; i++) { var f = a.objectAtIndex(i).js; if (f.toLowerCase() === w) return "=" + f } return "no" }'
// 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`
@@ -105,13 +107,15 @@ const GHOSTTY_SH = `"\${GHOSTTY_BIN_DIR:+\$GHOSTTY_BIN_DIR/}ghostty" +show-confi
// not read the program again); exit 1 for other failures. Made in a
// temporary folder first, so a compile never sees half. Each new copy or
// marker removes the tag's temporary folders of 1 day and its other folders
-// and markers of 7 days (an older build's).
+// and markers of 30 days (an older build's). The key has the scanner's
+// version and the family, so a change to either reads the program again.
+// A write that fails leaves no folder and no marker (exit 1).
export const PROGRAM_FONTS_PL = [
'use strict;',
'my ($tag, $family, $f) = @ARGV; $f 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 $key = "v2-" . unpack("%32C*", "$family/$f") . "-$st[7]-$st[9]";',
'my $d = "$base/$tag-$key";',
'if (-d $d) { utime(undef, undef, $d); print "$d\\n"; exit 0 }',
'exit 3 if -e "$d.none";',
@@ -120,15 +124,16 @@ export const PROGRAM_FONTS_PL = [
' for my $e (readdir $dh) {',
' next unless index($e, "$tag-") == 0; my $p = "$base/$e";',
' next if $p eq $d || $p eq "$d.none"; my $age = -M $p; next unless defined $age;',
- ' next unless $e =~ /\\.\\d+$/ ? $age > 1 : $age > 7;',
+ ' next unless $e =~ /\\.\\d+$/ ? $age > 1 : $age > 30;',
' if (-d $p) { system("rm", "-rf", $p) } else { unlink $p }',
' }',
'}',
'open(my $h, "<:raw", $f) or exit 1; my $b = do { local $/; <$h> }; close $h;',
'my $want = "\\0" . join("\\0", split(//, $family));',
'system("mkdir", "-p", $base) == 0 or exit 1;',
- 'my $t = "$d.$$"; mkdir($t) or exit 1;',
- 'my (%seen, $n);',
+ 'my $t = "$d.$$"; system("rm", "-rf", $t); mkdir($t) or exit 1;',
+ 'sub fail { system("rm", "-rf", $t); exit 1 }',
+ 'my %seen; my $n = 0;',
'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;',
@@ -141,8 +146,8 @@ export const PROGRAM_FONTS_PL = [
' $name = substr($b, $o + $off, $len) if $tt eq "name";',
' }',
' next if $bad || !$fvar || index($name, $want) < 0 || $seen{$end}++;',
- ' open(my $w, ">:raw", "$t/$tag-" . ++$n . ".ttf") or next;',
- ' print $w substr($b, $o, $end); close $w;',
+ ' open(my $w, ">:raw", "$t/$tag-" . ($n + 1) . ".ttf") or fail();',
+ ' (print $w substr($b, $o, $end)) && close($w) or fail(); $n++;',
'}',
'if (!$n) { rmdir $t; if (open(my $m, ">", "$d.none")) { close $m } sweep(); exit 3 }',
'rename($t, $d) or system("rm", "-rf", $t);',
@@ -226,23 +231,26 @@ async function macFamily($: EngineInterface, family: string, mono = false): Prom
return got?.exitCode === 0 ? firstLine(got.stdout) : ''
}
-// Whether a family is installed: CoreText on macOS, fontconfig on Linux
-// (`exact`: the name as is, as Rio's font database matches it; else in
-// any case and spacing). Null when that can't be read (then the family is
-// taken as is).
-async function hasFamily($: EngineInterface, isMac: boolean, family: string, exact = false): Promise<boolean | null> {
+// The installed family of a name, as Typst must name it: CoreText on
+// macOS, fontconfig on Linux (in any case and spacing; `exact`: in any
+// case only, as Rio's font database matches it). '' when it is not
+// installed; null when that can't be read (then the name is taken as is).
+async function installedFamily($: EngineInterface, isMac: boolean, family: string, exact = false): Promise<string | null> {
+ if (isMac && exact) {
+ const got = await processRun($, ['osascript', '-l', 'JavaScript', '-e', FAMILY_NOCASE_JXA, family], { timeoutMs: 5000 }).catch(() => null)
+ const line = got?.exitCode === 0 ? firstLine(got.stdout) : ''
+ return line.startsWith('=') ? line.slice(1) : line === 'no' ? '' : null
+ }
if (isMac) {
const seen = await macFamily($, family)
- return seen ? seen === 'yes' : null
- }
- if (exact) {
- const got = await processRun($, ['fc-list', ':', 'family'], { timeoutMs: 5000 }).catch(() => null)
- if (got?.exitCode !== 0) return null
- // Each line is a family's names, split by commas, with `\` escapes.
- return got.stdout.split('\n').some(line => line.split(/(?<!\\),/).some(name => name.replace(/\\(.)/g, '$1').trim() === family))
+ return seen === 'yes' ? family : seen === 'no' ? '' : null
}
- const got = await processRun($, ['fc-list', '-q', fcPatternOf(family)], { timeoutMs: 5000 }).catch(() => null)
- return got?.exitCode === 0 ? true : got?.exitCode === 1 ? false : null
+ const got = await processRun($, ['fc-list', exact ? ':' : fcPatternOf(family), 'family'], { timeoutMs: 5000 }).catch(() => null)
+ if (got?.exitCode !== 0) return null
+ // Each line is a font's family names, split by commas, with `\` escapes.
+ const names = got.stdout.split('\n').flatMap(line => line.split(/(?<!\\),/).map(name => name.replace(/\\(.)/g, '$1').trim())).filter(Boolean)
+ const loose = (n: string) => (exact ? n : n.replace(/\s/g, '')).toLowerCase()
+ return names.find(n => loose(n) === loose(family)) ?? (exact ? '' : names[0] ?? '')
}
// Copies the font a terminal carries in its program (PROGRAM_FONTS_PL) and
@@ -251,8 +259,10 @@ async function hasFamily($: EngineInterface, isMac: boolean, family: string, exa
async function programFont($: EngineInterface, isMac: boolean, o: { tag: string; family: string; name: string; paths: readonly string[] }): Promise<'copied' | 'none' | 'failed'> {
const argv = ['sh', '-c', PROGRAM_FONTS_SH, 'sh', perlFor(isMac), PROGRAM_FONTS_PL, o.tag, o.family, o.name, ...o.paths]
const made = await processRun($, argv, { timeoutMs: 10000 }).catch(() => null)
- if (made?.exitCode === 3) return 'none'
const dir = made?.exitCode === 0 ? firstLine(made.stdout) : ''
+ // No copy now: an older folder (maybe gone) is not given to Typst.
+ if (!dir) S.fontPaths = ''
+ if (made?.exitCode === 3) return 'none'
if (!dir) return 'failed'
S.fontPaths = dir
return 'copied'
@@ -275,7 +285,10 @@ async function ghosttyDefaultFont($: EngineInterface, isMac: boolean): Promise<s
// fontconfig's sorted list). No list: its own JetBrains Mono.
async function ghosttyFont($: EngineInterface, isMac: boolean, names: readonly string[]): Promise<string> {
if (!names.length) return ghosttyDefaultFont($, isMac)
- for (const name of names) if ((await hasFamily($, isMac, name)) !== false) return name
+ for (const name of names) {
+ const found = await installedFamily($, isMac, name)
+ if (found !== '') return found ?? name
+ }
if (isMac) return ghosttyDefaultFont($, isMac)
return (await fcFamily($, fcPatternOf(names[0]!))) || names[0]!
}
@@ -287,12 +300,13 @@ async function ghosttyFont($: EngineInterface, isMac: boolean, names: readonly s
// Code (the same letters) when it is installed.
async function rioFont($: EngineInterface, isMac: boolean): Promise<string> {
const named = rioFontOf((await readRioConfig($)).config)
- if (named !== RIO_DEFAULT_FONT && (await hasFamily($, isMac, named, true)) !== false) return named
+ const found = named === RIO_DEFAULT_FONT ? '' : await installedFamily($, isMac, named, true)
+ if (found !== '') return found ?? named
const home = (await envGet($, 'HOME')) ?? ''
const copy = await programFont($, isMac, { tag: 'rio', family: RIO_DEFAULT_FONT, name: 'rio', paths: rioProgramsOf(home) })
if (copy === 'copied') return RIO_DEFAULT_FONT
if (copy === 'none') return RIO_OLD_FONT
- return (await hasFamily($, isMac, RIO_OLD_FONT)) ? RIO_OLD_FONT : RIO_DEFAULT_FONT
+ return (await installedFamily($, isMac, RIO_OLD_FONT)) ? RIO_OLD_FONT : RIO_DEFAULT_FONT
}
// The font that the terminal's own config or profile names.
@@ -332,7 +346,8 @@ async function configFontOf($: EngineInterface, isMac: boolean): Promise<string>
const named = await processRun($, ['osascript', '-l', 'JavaScript', '-e', FAMILY_JXA, name], { timeoutMs: 5000 }).catch(() => null)
return named?.exitCode === 0 ? firstLine(named.stdout) || KITTY_MAC_FONT : ''
}
- if ('family' in font && (await hasFamily($, isMac, name)) !== false) return name
+ const found = 'family' in font ? await installedFamily($, isMac, name) : ''
+ if (found !== '') return found ?? name
const exact = (await fcListFamily($, `:postscriptname=${fcPatternOf(name)}`)) || (await fcListFamily($, `:fullname=${fcPatternOf(name)}`))
return exact || (await fcFamily($, `${'family' in font ? fcPatternOf(name) : `:postscriptname=${fcPatternOf(name)}`}:spacing=mono`))
}
diff --git a/hooks/lib/typst.ts b/hooks/lib/typst.ts
index adf05c6..db1fd7a 100644
--- a/hooks/lib/typst.ts
+++ b/hooks/lib/typst.ts
@@ -87,10 +87,17 @@ export function noNetworkEnv(cache: string): Record<string, string> {
no_proxy: '',
TYPST_PACKAGE_CACHE_PATH: `${cache}/pkg-cache`,
// The user's own folders stay (':' is the separator on macOS and Linux).
- ...(S.fontPaths ? { TYPST_FONT_PATHS: [S.userFontPaths, S.fontPaths].filter(Boolean).join(':') } : {}),
+ ...fontPathsEnv(cache),
}
}
+// TYPST_FONT_PATHS with no empty entries (Typst stops at one); a folder that
+// is not there when the user's value has only empty entries.
+function fontPathsEnv(cache: string): { TYPST_FONT_PATHS?: string } {
+ const paths = [...S.userFontPaths.split(':'), S.fontPaths].filter(Boolean).join(':')
+ return paths ? { TYPST_FONT_PATHS: paths } : S.userFontPaths ? { TYPST_FONT_PATHS: `${cache}/no-fonts` } : {}
+}
+
// Width and height from a PNG's first 24 bytes (signature, then IHDR).
export function pngSize(bytes: readonly number[]): { width: number; height: number } | null {
const sig = [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]
diff --git a/render/md.typ b/render/md.typ
index 7c98dbe..24848b4 100644
--- a/render/md.typ
+++ b/render/md.typ
@@ -171,7 +171,10 @@
// term-bold=0: Typst has no bold face of the terminal font (Monaco, for
// one), so its bold text would draw regular. As a terminal does, bold
// text in that font gets a stroke of its own fill (0.04em: as thick as
-// Menlo's and DejaVu Sans Mono's bold). Text in other fonts stays.
+// Menlo's and DejaVu Sans Mono's bold). Text in other fonts stays. The
+// stroke goes on bold regions (strong, headings, table headers), never
+// on each text: a show text rule stops the long-word and probe rules
+// from matching across texts, and makes each compile slower.
#let faux-bold = term-font != "" and inp.at("term-bold", default: "1") == "0"
#let faux-stroke = 0.04em
#let weight-num = (thin: 100, extralight: 200, light: 300, regular: 400, medium: 500, semibold: 600, bold: 700, extrabold: 800, black: 900)
@@ -182,16 +185,18 @@
let x = if type(f) == array { f.at(0, default: "") } else { f }
lower(if type(x) == dictionary { x.name } else { x })
}
-#show: doc => if not faux-bold { doc } else {
- let term = lower(term-font)
- // strong adds its delta when it is shaped; as a weight, the text rule sees it.
- show strong: it => context if first-font() != term { it } else {
- text(weight: calc.min(weight-of(text.weight) + it.delta, 900), it.body)
- }
- show text: it => context if weight-of(text.weight) < 600 or first-font() != term { it } else {
- text(stroke: faux-stroke + text.fill, it)
+#let is-term() = first-font() == lower(term-font)
+// A bold region: the stroke in its fill, when it is in the terminal font
+// and has no stroke yet (a stroke that is set stays).
+#let faux(body) = if not faux-bold { body } else {
+ context if text.stroke != none or not is-term() { body } else { text(stroke: faux-stroke + text.fill, body) }
+}
+// strong as an explicit weight (its delta), with the stroke when bold.
+#show strong: it => if not faux-bold { it } else {
+ context if not is-term() { it } else {
+ let w = calc.min(weight-of(text.weight) + it.delta, 900)
+ if w >= 600 and text.stroke == none { text(weight: w, stroke: faux-stroke + text.fill, it.body) } else { text(weight: w, it.body) }
}
- doc
}
// ---------- the row grid (grid=1) ----------
@@ -306,29 +311,33 @@
show raw: set text(top-edge: g.top, bottom-edge: g.bottom)
set par(leading: 0pt)
heading-pad.update(pad)
+ let body = if weight-of(H.weight) >= 600 { faux(it.body) } else { it.body }
block(
width: 100%, above: calc.max(row, rows-near(above)), below: if pad > 0pt { row } else { calc.max(row, rows-near(below)) },
sticky: true, inset: (y: pad), stroke: if pad == 0pt { rule },
- if pad == 0pt { it.body } else { block(width: 100%, stroke: rule, it.body) },
+ if pad == 0pt { body } else { block(width: 100%, stroke: rule, body) },
)
}
}
}
set text(size: size, weight: H.weight)
set par(leading: H.leading-em * 1em)
+ let body = if weight-of(H.weight) >= 600 { faux(it.body) } else { it.body }
if lvl <= H.rule-levels {
block(
width: 100%, above: above, below: below, sticky: true,
inset: (bottom: H.rule-pad-em * 1em), stroke: (bottom: px + C.border),
- it.body,
+ body,
)
} else {
- block(width: 100%, above: above, below: below, sticky: true, it.body)
+ block(width: 100%, above: above, below: below, sticky: true, body)
}
}
// ---------- links, emphasis ----------
#show link: set text(fill: C.link)
+// In a fake bold region, the stroke takes the link's colour too.
+#show link: it => if not faux-bold { it } else { context if text.stroke == none { it } else { text(stroke: faux-stroke + C.link, it) } }
#set strike(stroke: 0.06em)
// ---------- lists ----------
@@ -365,6 +374,8 @@
#show raw: set text(font: mono, top-edge: "ascender", bottom-edge: "descender")
#show raw.where(block: false): set text(size: code-size(E.inline-code.size) / 0.8 * 1em)
#show raw.where(block: true): set text(size: code-size(E.code-block.size) / 0.8 * 1em)
+// Code in a font that has a bold face gets no fake bold of the text around it.
+#show raw: it => if faux-bold and lower(mono.at(0)) != lower(term-font) { text(stroke: none, it) } else { it }
// Inline code: like VS Code's `code { padding: 1px 3px; border-radius: 4px }`,
// the background covers the code font's ascender to descender plus the
// padding. highlight (not box) so long inline code can wrap across lines.
@@ -385,7 +396,7 @@
highlight(
fill: C.inline-code-bg, extent: pad-x, radius: IC.radius-px * px,
top-edge: asc + pad-y, bottom-edge: -(desc + pad-y),
- text(fill: C.inline-code-fg, it),
+ text(fill: C.inline-code-fg, ..if faux-bold and text.stroke != none { (stroke: faux-stroke + C.inline-code-fg) }, it),
)
h(pad-x)
}
@@ -483,6 +494,7 @@
// Live ```typst drawings (the only scale here) keep the "rules" look.
#show scale: set table(inset: rules-inset, stroke: rules-stroke)
#show table.cell.where(y: 0): set text(weight: E.table.header-weight)
+#show table.cell.where(y: 0): it => if weight-of(E.table.header-weight) >= 600 { faux(it) } else { it }
#show table: set par(leading: 0.38em)
// ---------- footnotes ----------
diff --git a/tests/bold-sh-test.sh b/tests/bold-sh-test.sh
index c315fc4..90354f7 100644
--- a/tests/bold-sh-test.sh
+++ b/tests/bold-sh-test.sh
@@ -2,7 +2,8 @@
# Renders render/md.typ with the real Typst in a terminal font that has no
# bold face (Monaco), with and without term-bold=0 (the fake bold): the
# flag changes a page with bold text, and does not change a page with no
-# bold text or a page with no terminal font. It keeps the PNGs in
+# bold text or a page with no terminal font. A long bold word still wraps,
+# and the probe's marks do not change (a show text rule would split them). It keeps the PNGs in
# $IUI_BOLD_OUT when that is set, to look at.
# Usage: sh tests/bold-sh-test.sh (exit 0 when all pass; skips with no
# typst or no Monaco)
@@ -37,6 +38,20 @@ for theme in claude-code vscode; do
same bold $theme && bad "$theme: the fake bold does not change bold text" || ok
same plain $theme && ok || bad "$theme: the fake bold changes a page with no bold text"
done
+# A long bold word (cmarker splits it at each \_) and smart quotes: the
+# probe's marks are the same with the flag (term-bold=0); with it the word
+# can wrap, and don't is one mark.
+printf 'A **aaaaaaaaaaaaaaaaaaaa\\_bbbbbbbbbbbbbbbbbbbbbbbb\\_cccccccccccccccccccccc**\n\n**Bold don'"'"'t a\\_b "q"**\n\n## Head don'"'"'t a\\_b\n' | doc long
+for b in 0 1; do
+ typst query --root / --input theme=dark --input width=300 --input term-font=Monaco --input "term-bold=$b" --input "theme-dir=$here/render/themes/claude-code" \
+ --input "doc=$tmp/long.json" --input probe=1 "$here/render/md.typ" '<mdpos>' --field value > "$tmp/marks-$b.json" 2> "$tmp/err" || bad "probe, term-bold=$b: $(head -3 "$tmp/err")"
+done
+cmp -s "$tmp/marks-0.json" "$tmp/marks-1.json" && ok || bad "the fake bold changes the probe's marks"
+# The long-word rule gives each letter of it a break chance (a mark of its own).
+n=$(grep -o '"t":"a"' "$tmp/marks-0.json" | wc -l | tr -d ' ')
+[ "$n" -ge 20 ] && ok || bad "the long bold word has no break chances ($n marks of its letters)"
+grep -q '"t":"don'"'"'t"' "$tmp/marks-0.json" && ok || bad "a mark of don't is split"
+
# With no terminal font, the flag does nothing.
for b in 0 1; do
typst compile "$here/render/md.typ" "$tmp/bold-none-$b.png" --root / --ppi 144 --input theme=dark --input width=420 \
diff --git a/tests/fonts-sh-test.sh b/tests/fonts-sh-test.sh
index 2e9f694..e881dac 100644
--- a/tests/fonts-sh-test.sh
+++ b/tests/fonts-sh-test.sh
@@ -4,7 +4,7 @@
# bash: on a fake program that holds small sfnt fonts (with `fvar` and
# `name` tables), it checks the folder and its files, a second run from
# the cache, the `.none` marker, the sweep of old folders, two runs at the
-# same time, and no program.
+# same time, a family of its own key, a write that fails, and no program.
# Usage: sh tests/fonts-sh-test.sh (exit 0 when all pass)
set -u
here=$(cd "$(dirname "$0")/.." && pwd)
@@ -37,6 +37,7 @@ EOF
"$perl" "$tmp/font.pl" "Test Mono" 0 "$tmp/regular.ttf"
"$perl" "$tmp/font.pl" "Test Mono" 8 "$tmp/italic.ttf"
"$perl" "$tmp/font.pl" "Other Font" 4 "$tmp/other.ttf"
+"$perl" "$tmp/font.pl" "Big Mono" 4000 "$tmp/big.ttf"
# A program: filler, the fonts (the regular one twice, as in a universal
# program), and another family's font.
program() {
@@ -54,13 +55,13 @@ for s in $shells; do
mkdir -p "$bin"; program "$bin/term"
run() { XDG_CACHE_HOME=$xdg PATH=$bin:/usr/bin:/bin $s -c "$sh_text" sh "$perl" "$pl" "$@"; }
# Old folders of the tag: a temporary one of 2 days and a key folder of
- # 8 days go; a key folder of today and another tag's old folder stay.
+ # 31 days go; a key folder of today and another tag's old folder stay.
mkdir -p "$base/test-old" "$base/test-1-2-3.999" "$base/test-new" "$base/other-old"
touch -t 202001010000 "$base/test-old" "$base/test-1-2-3.999" "$base/other-old"
# The first run: the folder, one file for each size of the family.
out=$(run test "Test Mono" term /nowhere); code=$?
dir=$(echo "$out" | sed -n 1p)
- [ "$code" = 0 ] && case $dir in "$base"/test-*) true ;; *) false ;; esac && ok || bad "$s: exit $code, folder '$dir'"
+ [ "$code" = 0 ] && case $dir in "$base"/test-v2-*) true ;; *) false ;; esac && ok || bad "$s: exit $code, folder '$dir'"
[ "$(ls "$dir" | tr '\n' ' ')" = "test-1.ttf test-2.ttf " ] && ok || bad "$s: the files are $(ls "$dir" | tr '\n' ' ')"
same "$dir/test-1.ttf" "$tmp/regular.ttf" && same "$dir/test-2.ttf" "$tmp/italic.ttf" && ok || bad "$s: a copied font is not the same"
[ ! -e "$base/test-old" ] && [ ! -e "$base/test-1-2-3.999" ] && [ -d "$base/test-new" ] && [ -d "$base/other-old" ] && ok || bad "$s: the sweep is wrong ($(ls "$base" | tr '\n' ' '))"
@@ -85,6 +86,14 @@ for s in $shells; do
wait $a; ca=$?; wait $b; cb=$?
[ "$ca" = 0 ] && [ "$cb" = 0 ] && [ "$(cat "$tmp/a-$k")" = "$(cat "$tmp/b-$k")" ] && ok || bad "$s: two runs gave $ca/$cb, '$(cat "$tmp/a-$k")' and '$(cat "$tmp/b-$k")'"
[ "$(ls -d "$base"/two-* | wc -l | tr -d ' ')" = 1 ] && [ "$(ls "$(cat "$tmp/a-$k")" | wc -l | tr -d ' ')" = 2 ] && ok || bad "$s: two runs left $(ls -d "$base"/two-* | tr '\n' ' ')"
+ # Another family of the same program: a key of its own.
+ out=$(run test "Other Font" term); code=$?
+ # (the copy ends at its last table: the file's padding after it is not copied)
+ [ "$code" = 0 ] && [ -n "$out" ] && [ "$out" != "$dir" ] && [ "$(ls "$out")" = test-1.ttf ] && head -c "$(wc -c < "$out/test-1.ttf")" "$tmp/other.ttf" | cmp -s - "$out/test-1.ttf" && ok || bad "$s: another family gave exit $code, '$out'"
+ # A write that fails (a file size limit): exit 1, no folder and no marker.
+ { head -c 3000 /dev/urandom; cat "$tmp/big.ttf"; } > "$bin/term3"; chmod 755 "$bin/term3"
+ (trap '' XFSZ; ulimit -f 2; run big "Big Mono" term3 >/dev/null); code=$?
+ [ "$code" = 1 ] && [ -z "$(ls -d "$base"/big-* 2>/dev/null)" ] && ok || bad "$s: a failed write gave exit $code, left $(ls -d "$base"/big-* 2>/dev/null | tr '\n' ' ')"
# No program: exit 2.
run test "Test Mono" nothing-here /nowhere/term > /dev/null; code=$?
[ "$code" = 2 ] && ok || bad "$s: no program gave exit $code"
diff --git a/tests/pure.test.ts b/tests/pure.test.ts
index a3d82c8..021e13e 100644
--- a/tests/pure.test.ts
+++ b/tests/pure.test.ts
@@ -1075,6 +1075,14 @@ test('typst gets no network in either case of the proxy variables, and its packa
// The user's own TYPST_FONT_PATHS stays, first.
S.userFontPaths = '/u/fonts'
expect(noNetworkEnv('/c').TYPST_FONT_PATHS).toBe('/u/fonts:/f1:/f2')
+ // Empty entries go (Typst stops at one), also with no copied font.
+ S.userFontPaths = '/a::/b:'
+ expect(noNetworkEnv('/c').TYPST_FONT_PATHS).toBe('/a:/b:/f1:/f2')
+ S.fontPaths = ''
+ expect(noNetworkEnv('/c').TYPST_FONT_PATHS).toBe('/a:/b')
+ // Only empty entries: a folder that is not there.
+ S.userFontPaths = ':'
+ expect(noNetworkEnv('/c').TYPST_FONT_PATHS).toBe('/c/no-fonts')
} finally {
S.fontPaths = saved
S.userFontPaths = ''
diff --git a/tests/termfont.test.ts b/tests/termfont.test.ts
index 47a61a6..e35674b 100644
--- a/tests/termfont.test.ts
+++ b/tests/termfont.test.ts
@@ -63,9 +63,15 @@ function world(on: any, o: {
if (!families.some(f => f.toLowerCase() === family.toLowerCase())) return ok('no\n')
return ok(argv.includes('mono') && o.proportional?.includes(family) ? 'proportional\n' : 'yes\n')
}
+ if (argv[0] === 'osascript' && cmd.includes('availableFontFamilies')) {
+ const found = families.find(f => f.toLowerCase() === argv.at(-1)!.toLowerCase())
+ return ok(found ? `=${found}\n` : 'no\n')
+ }
if (argv[0] === 'osascript' && cmd.includes('fontWithNameSize')) return ok(`${o.names?.[argAfter(argv, 'fontWithNameSize')] ?? ''}\n`)
if (argv[0] === 'fc-list' && argv[1] === ':') return ok(families.map(f => fcPatternOf(f)).join('\n'))
- if (argv[0] === 'fc-list' && argv.at(-1) === 'family') return ok(o.names?.[argv[1]!.replace(/^:\w+=/, '').replace(/\\(.)/g, '$1')] ?? '')
+ // A full or PostScript name: its family; a family: the installed ones it matches loosely.
+ if (argv[0] === 'fc-list' && argv.at(-1) === 'family' && argv[1]!.startsWith(':')) return ok(o.names?.[argv[1]!.replace(/^:\w+=/, '').replace(/\\(.)/g, '$1')] ?? '')
+ if (argv[0] === 'fc-list' && argv.at(-1) === 'family') return ok(families.filter(f => loose(f) === loose(argv[1]!)).map(f => fcPatternOf(f)).join('\n'))
if (argv[0] === 'fc-list' && argv[1] === '-q') return ok('', families.some(f => loose(f) === loose(argv[2]!)) ? 0 : 1)
if (argv[0] === 'fc-match' && argv[1] === 'monospace') return ok('DejaVu Sans Mono')
if (argv[0] === 'fc-match') {
@@ -124,6 +130,23 @@ fontTest("Rio on Linux finds a family by its exact name only (its font database)
expect(await details($)).toContain(`terminal font ${RIO_DEFAULT_FONT}.`)
})
+for (const isMac of [true, false]) {
+ fontTest(`Rio on ${isMac ? 'macOS' : 'Linux'} finds a family in any case (Rio compares lower case): the installed name`, async ($, on) => {
+ const w = world(on, { isMac, env: { TERM_PROGRAM: 'rio' }, copied: FONTS_DIR, families: ['Iosevka Term'], files: { '/h/.config/rio/config.toml': '[fonts]\nfamily = "iosevka term"\n' } })
+ expect(await details($)).toContain('terminal font Iosevka Term.')
+ expect(w.copies()).toEqual([])
+ })
+}
+
+for (const term of ['ghostty', 'kitty']) {
+ fontTest(`${term} on Linux with a family in another case and spacing: the name fontconfig has, for Typst`, async ($, on) => {
+ const files: Record<string, string> = term === 'kitty' ? { '/h/.config/kitty/kitty.conf': 'font_family iosevkaterm\n' } : {}
+ const env: Record<string, string> = term === 'kitty' ? { TERM: 'xterm-kitty' } : { TERM_PROGRAM: 'ghostty' }
+ world(on, { isMac: false, env, families: ['Iosevka Term'], files, run: shows('font-family = iosevkaterm\n') })
+ expect(await details($)).toContain('terminal font Iosevka Term.')
+ })
+}
+
fontTest('Rio with no Cascadia Code NF in its program (a Rio up to 0.4): Cascadia Code', async ($, on) => {
world(on, { isMac: true, env: { TERM_PROGRAM: 'rio' }, copied: 'none' })
expect(RIO_OLD_FONT).toBe('Cascadia Code')