raphamorim/glyph-protocol-examples

★ 19Forks 1GoGitHub ↗Compare

README

glyph-protocol-examples

Small demos that exercise Glyph Protocol's three payload formats across Rust, Go, TypeScript, and Jam — plus an ultraviolet full-screen TUI variant in Go.

Each demo probes the terminal for fmt support, then prints four lines:

  • colrv1 example (twice, once over a blue background block): the string "Rio Terminal Emulator" rendered from fmt=colrv1 payloads extracted from Typearture's Nabla isometric COLRv1 typeface.
  • colrv0 example: the string "Using Glyph protocol" rendered from fmt=colrv0 payloads extracted from Antonio J. Morata's Zupra 3D eYe/FS layered COLRv0 typeface.
  • glyf examples: five Nerd Font outlines (branch, folder, home, heart, Rust cog) registered at empty PUA-B codepoints U+100000–U+100004 as fmt=glyf payloads, extracted from JetBrainsMono Nerd Font so the icons look like Nerd Fonts even without a Nerd Font installed.

Format support is negotiated per-session via the protocol's s verb. Missing formats degrade to a labelled fallback line (e.g. (colrv0 not advertised by terminal)) instead of failing the whole demo. Rio is the reference implementation of the protocol.

Background, rationale, and the full protocol spec live in the blog posts:

Demos

Directory Language Run
ratatui Rust cd ratatui && cargo run
bubbletea Go cd bubbletea && go run .
ink TypeScript cd ink && npm install && npm run build && npm start
ncurses-jam Jam cd ncurses-jam && jam run -lncurses glyph.jam
ultraviolet Go cd ultraviolet && go run .

The first four share the same wire behaviour, printed layout, and payload constants — only the language differs. The ratatui / bubbletea / ink directory names are historical: those demos no longer use the framework they're named after, since the point is the protocol, not the TUI. The exception is ultraviolet, which does drive Charm's ultraviolet as a real alt-screen TUI rather than a plain-CLI print. If you want to port the protocol to another language, the wire helpers at the top of each entry file are the whole story (APC sequence construction + base64 payloads).

Extracting your own glyphs

The demo payloads come from one-off extraction scripts. All three scripts share a virtualenv:

python3 -m venv .venv && . .venv/bin/activate
pip install fonttools lxml

Monochrome (fmt=glyf). Pull glyf simple-glyph bytes from a TrueType font (Nerd Fonts, Powerline, etc.):

python3 extract_glyphs.py /path/to/font.ttf  # edit TARGETS to pick codepoints

Composite glyphs are flattened via fontTools.pens.ttGlyphPen, hinting is stripped, output is base64 ready to paste.

Colour (fmt=colrv1). Pull a full COLR v1 paint graph for a single codepoint from a colour font. The script auto-subsets the font to the minimal set of glyphs the paint graph touches, so the container fits in the 256-glyph / 64 KiB per-payload cap:

python3 extract_colrv1.py fonts/Nabla.ttf 52  # letter "R"

Output is one base64 string — the colrv1 container defined in the spec's §8.7.

Colour (fmt=colrv0). Same container shape, carrying a COLR v0 table (flat layered colour — each layer is a full-alpha glyph with a CPAL palette index). Works against any TrueType-outline COLRv0 font:

python3 extract_colrv0.py fonts/zupra-3d-eye-fs.colr.ttf 55  # letter "U"

Bundled demo generators. build_nabla_rio.py and build_zupra_using.py chain the extractors across every unique letter of their respective strings and emit language-specific modules. Pass --lang to pick the output dialect; default is Rust to stdout:

python3 build_nabla_rio.py                 > ratatui/src/colorv2.rs
python3 build_nabla_rio.py --lang go       > bubbletea/nabla_rio.go
python3 build_nabla_rio.py --lang ts       > ink/source/nabla_rio.ts

python3 build_zupra_using.py               > ratatui/src/zupra_using.rs
python3 build_zupra_using.py --lang go     > bubbletea/zupra_using.go
python3 build_zupra_using.py --lang ts     > ink/source/zupra_using.ts

Re-run whichever ones you care about after swapping fonts or demo strings.

Vendored fonts

License

Code: MIT, same as Rio. Nabla: SIL Open Font License 1.1.

Contributors

raphamorimaymanbagabas

Issues