Skip to content

ariadne(tui): Kitty and Sixel graphics for the terminal backend - #724

Closed
transfix wants to merge 2 commits into
masterfrom
feat/ariadne-terminal-graphics
Closed

transfix wants to merge 2 commits into
masterfrom
feat/ariadne-terminal-graphics

Conversation

@transfix

Copy link
Copy Markdown
Owner

Real pixels for images in the FTXUI terminal backend: the Kitty graphics protocol first, then Sixel, with half-blocks as the fallback. Roadmap §16.6, phasing step 3.

What changes

Kitty (kitty, Ghostty, WezTerm, Konsole)

  • Each image is sent once, out of band, after the frame that first draws it: a=T,U=1,f=24,q=2, chunked base64.
  • It is shown through Unicode placeholder cells: U+10EEEE plus row/column diacritics, with a 24-bit fg that names the image. A window or menu over an image hides exactly the cells it covers, and FTXUI's full repaint redraws the placeholders for free.
  • An image is re-sent only when its pixels change; a republished identical frame is hashed and skipped. It is deleted (a=d,d=I) once no frame draws it, and everything is released on exit.
  • A placement addresses at most 297 cells per axis, so bigger images go as tiles.
  • Text drawn over placeholder cells gets a readable fg instead of the id colour.

Sixel (xterm -ti vt340, foot, mlterm, WezTerm, Windows Terminal)

  • Bitmaps are re-sent after each draw, inside synchronized-output marks (CSI ? 2026). Kitty transmissions go after the closing mark, because a big frame overflowed kitty's pending-update buffer.
  • Each bitmap is clipped to the cells nothing covers. The node draws a half-block underlay, and a pass after the whole frame finds the cells still showing it. Those cells are covered column first, one bitmap per rectangle, top first.
  • A rectangle's last six-pixel band may reach into the row below only where that row shows the image too.
  • The screen's last row is never covered, so a terminal that moves the cursor below a bitmap can't scroll.
  • Colours use a fixed 6×7×6 palette (fewer where XTSMGRAPHICS reports fewer registers) with a 4×4 ordered dither.

Detection and units

  • run() probes before FTXUI takes the tty: a kitty query, CSI 16 t and DA1, on /dev/tty in raw mode. FTXUI's parser has no APC case, so a later kitty reply would arrive as typed text.
  • Sixel is DA1 feature 4, merged with FTXUI's own TerminalCapabilities().
  • The cell size in pixels comes from TIOCGWINSZ (else CSI 16 t) and is re-read every frame, so a font-size change follows.
  • Options::cell_px_w/h stays the layout unit, so persisted geometry stays portable. The real size only sets the raster: image_raster(), and max_image_pixels (1 Mi) caps Kitty transmissions.
  • ImageColor gains Kitty and Sixel. Auto picks Kitty, else Sixel (only when the cell size is known), else half-blocks.
  • Hosted mode (tvision) keeps half-blocks, because tvision owns the output. This is documented.

Testable pieces

  • inc/cvc/ariadne/term_graphics.h holds the pure functions: base64, kitty transmit/delete/placeholder, the Sixel encoder, the probe query and reply parser, and the rectangle cover.
  • take_graphics() returns the bytes run() writes after a frame, so the backend paths are tested headless.

cvcGL

  • TerminalScene renders at the cells' real pixels when a pixel mode is on, and maps drags with the frame's own pixels per cell.

Hosts

  • ari and ariadne_terminal take --graphics auto|kitty|sixel|color|mono.
  • ari also takes --image NAME=FILE, to publish a picture for image: widgets; the new example is terminal_images.ari.
  • snapshot --ansi --graphics kitty|sixel prints the images too, with --cell-size WxH where the terminal can't be asked.
  • The .ari schema now allows an image widget's scalar size:. components/raster_view.ari warned on it too.

Verification

  • Unit tests:
    • ariadne_term_graphics_test: 15 new tests. They cover RFC 4648 vectors, the diacritic table, chunking and the stride, and the probe parser on kitty, xterm, error and partial replies. A small in-test Sixel decoder round-trips solid colours exactly, dithered colours within one level, run-length coding and the stride.
    • ariadne_ftxui_test: 8 new tests on top of 42. They cover mode resolution (tvision stays half-blocks), the raster size, Kitty send-once / resend-on-change / delete, the background under a window, tiling past 297 columns, Sixel rectangles, bands and order, and a window over a Sixel image.
    • cvcgl_terminal_scene: extended for real-pixel rendering in both modes, and checks that an unchanged frame is not re-sent.
    • Locally ctest -R 'ariadne|Ariadne|cvcgl_terminal_scene': 403/403.
  • Sixel encoder: ImageMagick's independent decoder (convert sixel:) decodes the output to the source image within a fixed-palette dither (RMSE 7.6%).
  • Kitty, by hand, in kitty 0.32.2:
    • ari run terminal_images.ari --image photo=… showed the picture in real pixels. A second window dragged onto it (SGR mouse via kitty @ send-text) hid exactly the cells it covered.
    • When the picture's window was moved, the image followed with nothing left behind.
    • Ctrl-C quit cleanly.
    • ariadne_terminal terminal_scene.ari drew the 3D scene at full pixel resolution behind its window, background drags orbited it, and kitty logged no warnings.
    • kitty's own parser (kitty +runpy, headless) accepted the transmission: one image of the expected size, one virtual placement, and the expected placeholder count.
  • Sixel: not tested in a native Sixel terminal. None is installed here (VTE is built without SIXEL, and there are no Xaw headers to build xterm). Instead, snapshot --ansi --graphics sixel --cell-size 9x17 frames were fed to xterm.js with @xterm/addon-image (VS Code's Sixel implementation) in a browser. Both the picture under an overlapping window and the 3D scene with its menu bar rendered correctly. The interactive loop's per-draw re-send has not been watched in a live Sixel terminal.

Not covered (follow-ups)

  • tmux: the probe gets no kitty reply, so the fallback is half-blocks. Passthrough is not wired.
  • Windows and wasm: no probe runs, so Auto stays half-blocks there; Kitty and Sixel can still be forced.
  • The tvision desktop keeps half-blocks.

FtxuiBackend now draws images in real pixels where the terminal can:

- Kitty: each image is sent once, out of band, after the frame that first
  draws it (a=T, U=1, f=24, q=2, chunked base64), and shown through Unicode
  placeholder cells (U+10EEEE + row/column diacritics, fg = image id). A
  window or menu over an image hides exactly the cells it covers, and
  FTXUI's full repaint redraws the placeholders. An image is re-sent only
  when its pixels change and deleted once no frame draws it; images wider
  or taller than 297 cells go as tiles.
- Sixel: a bitmap is re-sent after each draw, inside synchronized-output
  marks, clipped to the cells nothing covers (the node draws a half-block
  underlay; a pass after the frame finds the cells still showing it).
  Fixed 6x7x6 palette (fewer where XTSMGRAPHICS says so), ordered dither.

run() probes the terminal before FTXUI takes the tty (a kitty query,
CSI 16 t and DA1 on /dev/tty in raw mode), merges FTXUI's DA1 capabilities
for Sixel, and reads the cell size in pixels from TIOCGWINSZ every frame.
Options::cell_px_w/h stays the layout unit; the real cell size only sets
the raster. Options::ImageColor gains Kitty and Sixel; Auto picks Kitty,
else Sixel (when the cell size is known), else half-blocks. Hosted mode
(tvision) keeps half-blocks.

The encoders and the probe-reply parser are pure functions in
term_graphics.h, unit-tested in ariadne_term_graphics_test. take_graphics()
returns the bytes run() writes after a frame, so the backend paths are
tested headless too.

cvcGL's TerminalScene renders at the cells' real pixels when a pixel mode
is on (FtxuiBackend::image_raster) and maps drags with the frame's own
pixels per cell. ari and ariadne_terminal take --graphics; ari also takes
--image NAME=FILE (new example terminal_images.ari), and snapshot
--cell-size. The .ari schema now allows an image widget's scalar size.
…-terminal-graphics

# Conflicts:
#	docs/ARIADNE.md
#	src/ari/main.cpp
#	src/cvc/CMakeLists.txt
#	src/cvc/tests/CMakeLists.txt
transfix added a commit that referenced this pull request Oct 20, 2026
…the row-split first-walk fix (#727)

Carries #724 (Kitty + Sixel image modes for FtxuiBackend) and adds table column persistence.

- Kitty: images sent once, out of band, shown through Unicode placeholder cells (window occlusion and FTXUI's full repaint just work), re-sent only when their pixels change, deleted when no longer drawn, tiled past 297 cells. Sixel: re-sent after each draw inside synchronized-output marks, clipped to the cells nothing covers. run() probes the tty before FTXUI (kitty query, CSI 16 t, DA1; TIOCGWINSZ per frame); ImageColor gains Kitty/Sixel, Auto picks the best. Pure encoders in term_graphics.h with unit tests. TerminalScene renders at the cells' real pixels. Host flags --graphics, --image NAME=FILE and --cell-size join the shared host CLI.
- Resizable tables persist column widths to tree.<id>.columns (Backend::seed_grid_columns / grid_columns), px for every column, 0 = not set; ImGui seeds stretch columns as weights and reads Columns[i].WidthGiven, FTXUI fixes seeded columns.
- Row-split fix: a naturally laid-out pane reports 0 instead of the 16 px of a box never laid out, so a reload no longer pins it at one row.
@transfix

Copy link
Copy Markdown
Owner Author

Landed on master through #727 (squash 8a84b9c), which carried this PR's commit underneath its own. Every change here is in master; the only differences are #727's own additions (table columns and the row-split fix). Closing as included.

@transfix transfix closed this Oct 20, 2026
@transfix
transfix deleted the feat/ariadne-terminal-graphics branch October 20, 2026 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant