GeezerVison is showing github.com — feat(site): use OpenMono as the mono typeface by iamdavidhill · Pull Request #64796 · anomalyco/opencode
feat(site): use OpenMono as the mono typeface
#64796
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement . We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
Uh oh!
There was an error while loading. Please reload this page.
Show file tree
Hide file tree
Changes from all commits
Commits
File filter
Filter by extension
.css
(18)
.jpg
(1)
.json
(3)
.md
(2)
.py
(2)
.ts
(31)
.tsx
(7)
.txt
(2)
.woff2
(28)
All 9 file types selected
Deleted files
Viewed files
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Hide whitespace
Diff view
Hide whitespace
There are no files selected for viewing
Original file line number
Diff line number
Diff line change
Expand Up
@@ -22,8 +22,8 @@ To add a rule, add one line under its group. Mark a rule that is still being dec
## Type
- Set every font size from the `--fs-*` tokens. Nothing is smaller than 12px, and on phones nothing that carries meaning is smaller than 14px. → [Type scale](/dev/components#type-scale)
- Use OpenTUI Mono (`--font-mono`), Anomaly's own font, for nav, labels, titles and code, and Inter (`--font-sans`) for body and reading text. → [Fonts](/dev/components#fonts)
- Serve only fonts we own or that are openly licensed (OpenTUI Mono , the OpenCode font, Inter), never a commercial face. `test/fonts.test.ts` enforces it.
- Use OpenMono (`--font-mono`), Anomaly's own font, for nav, labels, titles and code, and Inter (`--font-sans`) for body and reading text. → [Fonts](/dev/components#fonts)
- Serve only fonts we own or that are openly licensed (OpenMono , the OpenCode font, Inter), never a commercial face. `test/fonts.test.ts` enforces it.
- Step text once, at 960px. Only page titles (`--fs-h1`) and display titles are fluid. → [Type scale](/dev/components#type-scale)
- Set inputs with `--fs-input`, 16px on touch, so iOS doesn't zoom.
- Give section titles `--title-size` with the `--title-stroke` faux medium; the current nav item gets the same stroke.
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -52,7 +52,7 @@ How it works:
3. It writes a VHS tape that runs `opencode --standalone`, types the prompt and takes three `Screenshot`s: `home` (prompt typed), `permission` (diff and "Allow once"), and `done` (tests pass and summary). `Wait+Screen` reacts to the real UI, so there are no fixed sleeps for model output.
4. It writes `manifest.json` and `opencode-terminal-screenshots.zip`.
Requirements: `opencode` (or `OPENCODE_BIN=/path/to/build`), `vhs` 0.12+ (`brew install vhs`, which installs ttyd and uses headless Chrome), `bun`, `git` and `zip`. Font: `--font` / `CAPTURE_FONT` (default OpenTUI Mono, which must be installed; its OFL files are in anomalyco/opentui `packages/web/public/fonts` ).
Requirements: `opencode` (or `OPENCODE_BIN=/path/to/build`), `vhs` 0.12+ (`brew install vhs`, which installs ttyd and uses headless Chrome), `bun`, `git` and `zip`. Font: `--font` / `CAPTURE_FONT` (default OpenMono Nerd, the terminal family of OpenMono, which must be installed: it has the symbols the TUI draws, each one cell wide ).
Output: `fresh-assets/` next to the checkout (override with `--out` or `FRESH_ASSETS_DIR`; not the temp folder, which a reboot wipes): 6 PNGs, 3200×2000, light and dark, manifest and zip. The /brand terminal pair is the `done` beat, copied to `public/brand/screenshots/opencode-terminal-{dark,light}.png` with 1600×1000 WebP previews (`cwebp -q 82 -m 6 -resize 1600 1000`), and `manifest.json` next to them feeds the "captured from" line.
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -22,7 +22,10 @@ const args = parseArgs({
default: process.env.FRESH_ASSETS_DIR ?? path.join(import.meta.dir, "../../../../../fresh-assets"),
},
surface: { type: "string", multiple: true, default: ["terminal"] },
font: { type: "string", default: process.env.CAPTURE_FONT ?? "OpenTUI Mono" },
// An installed family. OpenMono Nerd is the terminal one: it has the symbols the TUI draws, each one cell wide
// (in OpenMono the arrows and the ellipsis take two cells, and the status marks come from another font). VHS
// draws each cell on its own, so no family shows code ligatures.
font: { type: "string", default: process.env.CAPTURE_FONT ?? "OpenMono Nerd" },
// TUI experiments to turn on in the capture's cli.json, e.g. --experiment new-designs (the
// muted-blue dialogs with the left key line on dev).
experiment: { type: "string", multiple: true, default: [] },
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -3,7 +3,7 @@
// fontkit) and writes their names to src/lib/local-mono-fonts.json, for Settings › Mono font's
// "Installed on this Mac" group. Only the names are kept; the fonts are never copied. fontkit
// installs into a temporary folder, so the app takes no dependency on it.
// Run from packages/console/app : bun script/local-mono-fonts.ts
// Run from services/site : bun script/local-mono-fonts.ts
import { mkdtemp, readdir, rm } from "fs/promises"
import { homedir, tmpdir } from "os"
import { dirname, join } from "path"
Expand All
@@ -22,7 +22,7 @@ const fontkit: { openSync: (path: string) => Face & { fonts?: Face[] } } = await
join(tmp, "node_modules/fontkit/dist/main.cjs")
)
// The families the site offers on their own, and Apple's hidden UI faces.
const skipped = ["IBM Plex Mono", "OpenTUI Mono ", "Apple Color Emoji", "LastResort", "GB18030 Bitmap"]
const skipped = ["IBM Plex Mono", "OpenMono ", "Apple Color Emoji", "LastResort", "GB18030 Bitmap"]
const ascii = Array.from({ length: 95 }, (_, index) => String.fromCharCode(32 + index)).join("")
const folders = [join(homedir(), "Library/Fonts"), "/Library/Fonts", "/System/Library/Fonts"]
const files = (
Expand Down
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
// Captures the flat stills script/og.ts angles into the link preview cards: real pages rendered
// headless in the dark theme, and a frame of the terminal feature clip with the blue themes dialog.
// The rest of the cards use files already in public/ (the product card covers and clips).
// Run by hand when a page's look changes, with the dev server up, from packages/console/app :
// Run by hand when a page's look changes, with the dev server up, from services/site :
// bun script/og-stills.ts [http://localhost:3011]
// Needs Playwright's Chromium (bunx playwright-core install chromium) and ffmpeg.
import path from "node:path"
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -194,12 +194,15 @@ const cards: Card[] = [
},
]
// The site's files (script/openmono.py). Satori keeps one face per family name and weight, so each
// file has a family name of its own, and a title names all three: Latin first, the others for
// anything it lacks.
const mono = { latin: "OpenMono", cyrillic: "OpenMono Cyrillic", rest: "OpenMono Rest" }
const fonts = [
// The site's files (script/opentui-mono.py): Latin first, the rest for anything it lacks.
...(await Promise.all(
["latin", "rest"]. map(async (group) => ({
name: "OpenTUI Mono" ,
data: exact(await decompress(await read(`src/asset/fonts/opentui-mono -regular-${group}.woff2`))),
Object.entries(mono). map(async ([ group, name] ) => ({
name,
data: exact(await decompress(await read(`src/asset/fonts/openmono -regular-${group}.woff2`))),
weight: 400 as const,
})),
)),
Expand Down
Expand Up
@@ -310,7 +313,13 @@ function plate(card: Card, image: string) {
},
el(
"div",
{ fontFamily: "OpenTUI Mono", fontSize: size, lineHeight: 1, letterSpacing: -0.035 * size, color: INK },
{
fontFamily: Object.values(mono).join(", "),
fontSize: size,
lineHeight: 1,
letterSpacing: -0.035 * size,
color: INK,
},
card.title,
),
description(card.description),
Expand Down
Original file line number
Diff line number
Diff line change
@@ -0,0 +1,184 @@
# Builds the site's OpenMono files. With the font build's folder as its argument (the "app-nerd" output
# of the OpenMono build, whose Regular, Bold and Italic OpenCode Desktop bundles too) it reads
# woff2/OpenMonoNerd-<Style>-text.woff2 and LICENSE from there and also writes them to
# src/docs/assets/fonts (as OpenMono-<Style>.woff2) and src/asset/fonts/OpenMono-OFL.txt; without one it
# rebuilds from those copies. The copies are OpenMono 1.000.
#
# Each style is three files, split by unicode-range like Inter: "latin" (Latin, punctuation, arrows,
# shapes, box drawing and a few keys and common symbols: what the site sets in mono), "cyrillic" (the
# Russian and Ukrainian pages, and those languages' names in a language menu) and "rest" (every other
# character the font has), each only fetched when a page uses one of its characters. No character is
# left out. OpenCode Desktop's script (packages/app/script/openmono.py) follows the same rules; with
# the same lists of keys and symbols as below, both make the same files. The ranges are written to
# src/asset/fonts/openmono.json for mono-fonts.ts; if they change, write them into
# src/style/fonts.css too (test/fonts.test.ts compares the two). packages/data/app serves copies of
# the regular and bold files; refresh them too.
#
# The app build has no ligatures and every character one cell wide (0.6 em, like the metric-matched
# fallbacks), so no CSS feature is needed. Only the layout features for accents are kept.
#
# Every input is read and checked and every file is built in a temporary folder first, so a missing
# or wrong input leaves the checkout as it was.
#
# OpenMono is licensed under the SIL Open Font License 1.1 (src/asset/fonts/OpenMono-OFL.txt).
# Run from services/site, after each font build:
# uvx --from 'fonttools[woff]==4.60.1' python script/openmono.py path/to/app-nerd
import json
import shutil
import sys
import tempfile
from pathlib import Path
from fontTools import subset
from fontTools.ttLib import TTFont
source = Path("src/docs/assets/fonts")
out = Path("src/asset/fonts")
styles = {
"regular": "Regular",
"bold": "Bold",
"italic": "Italic",
"bold-italic": "BoldItalic",
}
latin = [(0x0000, 0x017F), (0x2000, 0x206F), (0x20AC, 0x20AC), (0x2122, 0x2122), (0x2190, 0x21FF), (0x2212, 0x2212), (0x2500, 0x25FF)]
# The keys that shortcuts name (⌃ ⌘ ⌥ ⌫ ⎋ ⏎, as in Inter's Latin file), which are in the Latin file too: the
# search box on every page shows ⌘K, and from the "rest" file that one character would cost 123 kB.
keys = {0x2303, 0x2318, 0x2325, 0x232B, 0x238B, 0x23CE}
# Common symbols, in the Latin file too for the same reason. Each is one a terminal prints as a status
# mark, or one that a page of opencode.ai, its docs, the Console or opentui.com sets in mono:
symbols = {
# ✓ ✗ ✕ ✖ ⚠: status marks (✓ is in opentui.com's docs and the Console's demos)
*(0x2713, 0x2717, 0x2715, 0x2716, 0x26A0),
# ∙ ⋅: the dots that two of opentui.com's terminal recordings draw
*(0x2219, 0x22C5),
# ≈ ≠ ≤ ≥ ∞ √ ∑: plain math (≈ is on /font, ∞ is the Console's unlimited allowance)
*(0x2248, 0x2260, 0x2264, 0x2265, 0x221E, 0x221A, 0x2211),
# ⋯ and the replacement character: in code on a changelog page
*(0x22EF, 0xFFFD),
# ⁰ ⁴ ⁵ ⁶ ⁷ ⁸ ⁹, ₀ ₁ and σ: the numbers on /font (¹ ² ³ are in Latin-1). Σ too: the page sets its σ in capitals
*(0x2070, 0x2074, 0x2075, 0x2076, 0x2077, 0x2078, 0x2079, 0x2080, 0x2081, 0x03C3, 0x03A3),
}
cyrillic = [(0x0400, 0x052F), (0x1C80, 0x1C8F), (0x2DE0, 0x2DFF), (0xA640, 0xA69F)]
# The stress marks, which the Cyrillic file has too: a stressed letter such as у́ has no code point of
# its own, and a browser sets a letter and its mark from one file or falls back for both. (A Latin
# letter with one of them has a code point of its own, which the Latin file has.) The "rest" file has
# them too, so the Cyrillic rule must come after the rest rule in a stylesheet: a browser asks the
# last rule that has a character first, and a stressed Russian word then fetches the small file only.
stress = {0x0300, 0x0301}
# Blocks where the font has most characters or a few scattered ones, and the ones it lacks are
# unassigned or rare: Greek, Armenian, phonetic letters, superscripts, currency signs, letterlike
# and technical symbols, Latin Extended-D to G, double-struck letters and legacy computing symbols.
# There a range runs on across the code points the font lacks, up to one that another file has,
# which keeps the stylesheet within the docs' budget (src/docs/script/build.ts). The only cost is
# that a page using one of the lacking characters fetches the "rest" file before falling back. The
# ranges around the Powerline characters are exact, as in Desktop, whose icons file has the code
# points between them.
sparse = [
(0x0370, 0x03FF),
(0x0530, 0x058F),
(0x1D00, 0x1DBF),
(0x1F00, 0x1FFF),
(0x2070, 0x209F),
(0x20A0, 0x20CF),
(0x2100, 0x214F),
(0x2300, 0x23FF),
(0xA720, 0xA7FF),
(0xAB30, 0xAB6F),
(0xF880, 0xF89F),
(0x10780, 0x107BF),
(0x1CC00, 0x1CEBF),
(0x1D400, 0x1D7FF),
(0x1DF00, 0x1DFFF),
(0x1FB00, 0x1FBFF),
]
notice = """The openmono-*.woff2 files in this folder are subsets of OpenMono 1.000, made by
services/site/script/openmono.py from the app build (no ligatures, every
character one cell wide). OpenMono is Anomaly's typeface, built on Iosevka by
Renzhi Li (Belleve Invis). The font declares no Reserved Font Name.
"""
def within(code, spans):
return any(a <= code <= b for a, b in spans)
def spans(codes, others=frozenset()):
"""The ranges of some characters: runs of code points, joined across a gap inside one sparse block unless a
character of another file is in the gap."""
found = []
for code in sorted(codes):
block = next((span for span in sparse if within(code, [span])), None)
gap = range(found[-1][1] + 1, code) if found else range(0)
if found and (not gap or (block and within(gap[0], [block]) and others.isdisjoint(gap))):
found[-1][1] = code
continue
found.append([code, code])
return found
def ranges(codes, others=frozenset()):
return ", ".join(f"U+{a:04X}" if a == b else f"U+{a:04X}-{b:04X}" for a, b in spans(codes, others))
build = Path(sys.argv[1]).expanduser() if len(sys.argv) > 1 else None
inputs = {
file: (build / "woff2" / f"OpenMonoNerd-{file}-text.woff2") if build else source / f"OpenMono-{file}.woff2"
for file in styles.values()
}
licence = build / "LICENSE" if build else None
missing = [str(path) for path in [*inputs.values(), *([licence] if licence else [])] if not path.is_file()]
if missing:
raise SystemExit("Nothing was written. Missing: " + ", ".join(missing))
with tempfile.TemporaryDirectory() as folder:
staged = Path(folder)
members = {}
for name, file in styles.items():
font = TTFont(inputs[file])
wide = sorted(code for code, glyph in font.getBestCmap().items() if font["hmtx"][glyph][0] not in (0, 600))
if wide:
raise SystemExit(f"Nothing was written. {inputs[file]} is not the one-cell build: {ranges(wide)} are not 600 units wide")
codes = set(font.getBestCmap())
if (keys | symbols) - codes:
raise SystemExit(f"Nothing was written. {inputs[file]} lacks {ranges((keys | symbols) - codes)}, which the Latin file is to have")
groups = {
"latin": {code for code in codes if within(code, latin) or code in keys | symbols},
"cyrillic": {code for code in codes if within(code, cyrillic) or code in stress},
"rest": {code for code in codes if not within(code, latin + cyrillic) and code not in keys | symbols},
}
for group, chars in groups.items():
if members.setdefault(group, chars) != chars:
raise SystemExit(f"Nothing was written. {inputs[file]} has other {group} characters than the styles before it: {ranges(members[group] ^ chars)}")
options = subset.Options()
options.flavor = "woff2"
options.layout_features = ["ccmp", "locl", "mark", "mkmk"]
options.name_IDs = [0, 1, 2, 3, 4, 5, 6]
options.notdef_outline = True
options.hinting = False
options.desubroutinize = True
subsetter = subset.Subsetter(options)
subsetter.populate(unicodes=chars)
# The source's own timestamp, so a rebuild from the same files writes the same bytes.
copy = TTFont(inputs[file], recalcTimestamp=False)
subsetter.subset(copy)
copy.flavor = "woff2"
copy.save(staged / f"openmono-{name}-{group}.woff2")
# A file's range may run across code points the font lacks, never across another file's characters.
others = {group: frozenset().union(*(chars for other, chars in members.items() if other != group)) - members[group] for group in members}
for group, chars in members.items():
taken = sorted({code for a, b in spans(chars, others[group]) for code in range(a, b + 1)} & others[group])
if taken:
raise SystemExit(f"Nothing was written. The {group} range would take {ranges(taken)} from another file")
(staged / "openmono.json").write_text(json.dumps({group: ranges(chars, others[group]) for group, chars in members.items()}, indent=2) + "\n")
if licence:
(staged / "OpenMono-OFL.txt").write_text(notice + licence.read_text())
# Everything is built: replace the checkout's files.
if build:
source.mkdir(parents=True, exist_ok=True)
for file, path in inputs.items():
shutil.copyfile(path, source / f"OpenMono-{file}.woff2")
for path in sorted(staged.iterdir()):
shutil.copyfile(path, out / path.name)
print(out / path.name, path.stat().st_size)
Loading
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Loading
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.