Kitty graphics protocol
Status: proposed. Date: 2026-11-29. Owner approved: no.
Voyager7 draws images that programs send with the
kitty graphics protocol,
as Ghostty does. libghostty-vt parses the protocol, keeps the images and
places them. Voyager7 decodes PNG and zlib, and draws the placements in the
D3D11 Renderer. Before this ADR the feature was compiled out for size
(patches/ghostty/0004), and the README listed it as deferred.
libghostty-vt
- Kitty graphics are a build option of our lib-vt build (
-Dvoyager7-kitty-graphics, patch 0004).scripts/build-vt.shnow turns it on;KITTY_GRAPHICS=falsestill builds a library without image parsing or storage. - Upstream lib-vt links Wuffs whenever kitty graphics are on, for zlib, for
RGB and gray to RGBA conversion, and for one src-over blend used by
animation frames. That is 107,223 bytes of x64 code, and the binary already
links an inflater (miniz_oxide). Patch 0010 removes Wuffs from lib-vt:
- Conversion and blending are plain Zig loops with Wuffs' 16-bit arithmetic (the upstream blend test still passes).
- zlib goes through a new sys callback,
GHOSTTY_SYS_OPT_DECODE_ZLIB = 64, numbered clear of upstream options. PNG already goes throughGHOSTTY_SYS_OPT_DECODE_PNG, which upstream leaves unset for lib builds.
- Voyager7 installs both callbacks once per process (
v7_vt::graphics):- zlib is
miniz_oxide, bounded by the limit libghostty passes. - PNG is our own decoder on the same
miniz_oxide: all colour types and bit depths,PLTE/tRNS, all five filters and Adam7. Ancillary chunks other thantRNSare ignored, as Wuffs ignores them by default. Dimensions are capped at 10,000 (Kitty's and libghostty's limit).
- zlib is
- The render state lists every image placement on screen: fixed placements, relative placements and Unicode placeholder cells (U+10EEEE), with layer, z-index, destination size and source rectangle worked out. Voyager7 reads only that list (as the header asks), and reads pixels from the storage when an image's generation changes.
Transmission media
t= | Medium | Voyager7 |
|---|---|---|
d | direct, base64 chunks | always |
f | file | on: upstream's Windows path checks refuse UNC, device, NT object and reserved device names before the open, and anything but X:\... after it |
t | temporary file | on: the canonical path must be under the user's GetTempPathW directory (or /tmp, /dev/shm) and contain tty-graphics-protocol; the file is deleted after reading |
s | shared memory | on: a named file mapping (below) |
Windows has no POSIX shared memory. WezTerm, the Windows terminal with kitty
graphics, treats the name as a file mapping: OpenFileMappingW,
MapViewOfFile, and VirtualQuery for the size. Voyager7 does the same
(patch 0010, readFileMapping), with two differences:
- It opens the mapping read-only (
FILE_MAP_READ); WezTerm asks forFILE_MAP_ALL_ACCESS. - It bounds the read by the committed region and the
S/Okeys.
Windows has no shm_unlink. The mapping lives until its last handle closes,
so a client keeps its handle until it no longer needs the data. A client that
closes it immediately loses the race and gets EINVAL.
Budget: image-storage-limit
Ghostty's key image-storage-limit (bytes per screen, default 320,000,000,
maximum 4,294,967,295) sets libghostty's storage limit. 0 turns the protocol
off: commands are ignored and a query gets no reply, which is how kitty says
"unsupported". Over the limit, libghostty evicts images that have no
placement before placed ones, oldest first within each group.
Drawing
- The Frame adds one quad per placement, in Ghostty's order:
- images with z below
INT32_MIN / 2before the cell backgrounds; - other negative z (and every placeholder image) between backgrounds and text;
- z >= 0 after text and the cursor, below the unfocused-split dim.
- images with z below
- Within a layer, quads are sorted by z, then by list order. Each quad is
clipped to the grid rows on the CPU, with its source rectangle cut to
match. Scaling to
c/rcells comes from libghostty's destination size. - An image quad is an ordinary
Instancewith alpha-2. Its colour carries the image generation, which libghostty never reuses. The pixel shader's existing colour-texture branch samples it. The D3D11 layer binds that image's texture and a linear sampler for that one quad, so the shaders are unchanged. - Textures are premultiplied RGBA8, keyed by generation, and shared by all layers. A texture no layer draws is released. Images larger than the device's texture limit are reduced by an integer factor before upload.
- A layer with images is drawn in full on WARP (no damage bands), because damage tracks instances, not texture contents.
- After a lost device the textures are gone. The next present recreates the device and uploads the missing ones from terminal storage before it paints, so no CPU copy of any image is kept in the Renderer.
- libghostty sizes images in cells from the cell size in pixels that
ghostty_terminal_resizereceives. Voyager7 passes its real cell size (it passed 8x16 before) and updates it when the font size or DPI changes. The same size answersCSI 14 t/CSI 16 t/CSI 18 tthrough libghostty's size callback, which Voyager7 did not install before. Programs askCSI 16 tfor the cell size. The replies are withheld on inbox conhost, which types late replies into the shell (as for DCS replies). - Animation: libghostty keeps the frames and Voyager7 drives
ghostty_kitty_graphics_animation_tickfrom the frame loop, with a timer for the next frame.
Where the sequences arrive
Kitty graphics are APC strings (ESC _ G ... ESC \). Only a backend that
passes them to us unchanged can show images. Measured on 2026-11-29:
| Backend | APC | a=q | Images |
|---|---|---|---|
| Win10 22H2, bundled OpenConsole 1.25 (default) | passed through | OK for t=d, f, t, s | drawn |
Win10 22H2, inbox conhost (v7-conpty = system) | painted as text | none (conhost answers DA1 itself) | none |
| Win7 SP1, hook (x64 programs writing VT) | streamed | OK for t=d, f, t, s | drawn |
Win7 SP1, Scraper only (WOW64, MSYS, v7-win7-vt = false) | lost | none | none |
Evidence: build/fixes/kitty-graphics/ (backends/, demo/, reflow/,
programs/yazi-win10/, gpu-loss/). On both drawing backends, images survive
a window resize (they move with their text, as the console host reflows or
repaints), scroll into scrollback and back, and Yazi's preview appears,
disappears and returns as one browses (Win10).
The console host does not know that an image moved the cursor. On Win7 the
next text can start where the console's cursor is, as many rows higher as the
image moved the cursor down. C=1 avoids it, and programs that position
their own text, such as Yazi, are not affected.
Where APC does not reach us, the query (a=q) doesn't either, so the program
sees no reply and treats the protocol as unsupported. Where it does reach us,
Voyager7 answers and draws.
Size
cargo xtask size, x64 release exe, 5,000,000-byte budget:
| Build | Bytes | Change |
|---|---|---|
main eb7b6a6, graphics compiled out | 4,737,536 | |
lib-vt graphics on, upstream (with Wuffs), no Rust side (measured on main cebcfce) | +220,160 | |
| this ADR, everything | 4,884,992 | +147,456 |
Where the +147,456 bytes go (cargo xtask size attribution):
| Part | Bytes |
|---|---|
| libghostty-vt graphics without Wuffs (terminal/core +89,969, anonymous +20,106, Zig std +5,736, PE padding +1,608) | about 117,400 |
v7_vt: PNG decoder, decoders' glue, placement list, size reports | about 11,800 |
v7_gpu_d3d11: image textures and split draws | about 1,900 |
voyager7 and runtime: quads, texture sync, animation, settings | about 16,300 |
Patch 0010 saves 107,223 bytes of Wuffs. Upstream lib-vt alone would have
cost more than this whole ADR does. The PNG decoder reuses miniz_oxide and is
part of v7_vt's 11.8 KB.
Consequences
- One more patch to rebase (0010). It touches the kitty graphics files and
src/terminal/sys.zig,src/terminal/c/sys.zigandinclude/ghostty/vt/sys.h, and removes the Wuffs wiring fromsrc/build/GhosttyZig.zig. - A PNG decoder of our own (about 300 lines, tested against the
pngcrate as a dev-dependency). - No new third-party code in the shipped binary.