Skip to content

tui: draw the screen with the kitty graphics protocol - #10

Merged
frinfo702 merged 1 commit into
mainfrom
kitty-renderer
Nov 26, 2026
Merged

frinfo702 merged 1 commit into
mainfrom
kitty-renderer

Conversation

@frinfo702

Copy link
Copy Markdown
Owner

The setting renderer = "kitty" draws each line of the screen as a picture over the text that Bubble Tea draws. A line that changes gets a new picture, which replaces the old one at once in a synchronized update, so the screen does not flicker. Box lines and blocks are drawn as shapes, so they join the next cells with no gap. The keys, the mouse, and the text of the pane work as before: the text is still there, under the pictures.

A line keeps its picture while it scrolls, so a scroll sends only the lines that come into view. Bubble Tea scrolls the text with scroll regions, and the terminal moves the pictures with it, so each frame with a change places every row again. A placement with the same image and placement ID moves to where it is placed.

The pictures go after the text of their frame, so a clear of the screen in the text cannot delete them. Before Bubble Tea leaves the alternate screen, to quit or to run an editor, the pictures are deleted, or they would cover the shell. The terminal answers the questions for its colours one by one; the screen waits until they settle and draws once, not once for each answer. A frame that waits for a slow terminal does not stop the program, so q still quits.

The pictures are RGBA compressed with zlib, which is a few times faster than PNG. The buffers, the compressors, and the cells of the screen are reused from frame to frame, and a frame that changes nothing sends nothing.

The setting renderer = "kitty" draws each line of the screen as a
picture over the text that Bubble Tea draws. A line that changes gets a
new picture, which replaces the old one at once in a synchronized
update, so the screen does not flicker. Box lines and blocks are drawn
as shapes, so they join the next cells with no gap. The keys, the
mouse, and the text of the pane work as before: the text is still
there, under the pictures.

A line keeps its picture while it scrolls, so a scroll sends only the
lines that come into view. Bubble Tea scrolls the text with scroll
regions, and the terminal moves the pictures with it, so each frame
with a change places every row again. A placement with the same image
and placement ID moves to where it is placed.

The pictures go after the text of their frame, so a clear of the
screen in the text cannot delete them. Before Bubble Tea leaves the
alternate screen, to quit or to run an editor, the pictures are
deleted, or they would cover the shell. The terminal answers the
questions for its colours one by one; the screen waits until they
settle and draws once, not once for each answer. A frame that waits for
a slow terminal does not stop the program, so q still quits.

The pictures are RGBA compressed with zlib, which is a few times faster
than PNG. The buffers, the compressors, and the cells of the screen are
reused from frame to frame, and a frame that changes nothing sends
nothing.
@frinfo702
frinfo702 merged commit a4d446d into main Nov 26, 2026
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