Skip to main content

Module kitty

Module kitty 

Source
Expand description

Kitty terminal graphics renderer.

Renders a ChartSpec to an RGB bitmap via plotters, encodes it as PNG via the image crate, then wraps the PNG in kitty’s graphics Application Programming Command (APC) escape sequence so the result can be written directly to stdout inside a kitty-compatible terminal.

Protocol reference: https://sw.kovidgoyal.net/kitty/graphics-protocol/. Key choices:

  • f=100 — the payload is PNG, not raw RGB. Lets the terminal decode via libpng without us having to specify pixel dimensions.
  • a=T — transmit and display immediately at the cursor.
  • m=1/m=0 — chunking. The protocol caps each APC chunk at 4096 base64 characters; any more gets silently dropped.

Structs§

KittyOpts
Dimensions, in pixels, for the rendered chart.

Functions§

encode_png_apc
Encode PNG bytes as one or more kitty APC graphics commands. The chunks share an implicit image ID; the final chunk sets m=0 to tell the terminal to display.
render_kitty
Render spec to a PNG and return the kitty APC escape string that displays it at the current cursor.
render_png
Render spec to a PNG byte vector. Returns None on any drawing or encoding failure; callers decide whether to substitute a text fallback.