Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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.sh now turns it on; KITTY_GRAPHICS=false still 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 through GHOSTTY_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 than tRNS are ignored, as Wuffs ignores them by default. Dimensions are capped at 10,000 (Kitty's and libghostty's limit).
  • 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=MediumVoyager7
ddirect, base64 chunksalways
ffileon: upstream's Windows path checks refuse UNC, device, NT object and reserved device names before the open, and anything but X:\... after it
ttemporary fileon: 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
sshared memoryon: 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 for FILE_MAP_ALL_ACCESS.
  • It bounds the read by the committed region and the S/O keys.

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 / 2 before 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.
  • 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/r cells comes from libghostty's destination size.
  • An image quad is an ordinary Instance with 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_resize receives. Voyager7 passes its real cell size (it passed 8x16 before) and updates it when the font size or DPI changes. The same size answers CSI 14 t / CSI 16 t / CSI 18 t through libghostty's size callback, which Voyager7 did not install before. Programs ask CSI 16 t for 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_tick from 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:

BackendAPCa=qImages
Win10 22H2, bundled OpenConsole 1.25 (default)passed throughOK for t=d, f, t, sdrawn
Win10 22H2, inbox conhost (v7-conpty = system)painted as textnone (conhost answers DA1 itself)none
Win7 SP1, hook (x64 programs writing VT)streamedOK for t=d, f, t, sdrawn
Win7 SP1, Scraper only (WOW64, MSYS, v7-win7-vt = false)lostnonenone

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:

BuildBytesChange
main eb7b6a6, graphics compiled out4,737,536
lib-vt graphics on, upstream (with Wuffs), no Rust side (measured on main cebcfce)+220,160
this ADR, everything4,884,992+147,456

Where the +147,456 bytes go (cargo xtask size attribution):

PartBytes
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 reportsabout 11,800
v7_gpu_d3d11: image textures and split drawsabout 1,900
voyager7 and runtime: quads, texture sync, animation, settingsabout 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.zig and include/ghostty/vt/sys.h, and removes the Wuffs wiring from src/build/GhosttyZig.zig.
  • A PNG decoder of our own (about 300 lines, tested against the png crate as a dev-dependency).
  • No new third-party code in the shipped binary.