Pictures
Programs that draw pictures in a terminal show them in a Terminal Delight pane. Run kitten icat photo.png, chafa, or an agent that renders a chart with the Kitty graphics protocol, and the picture lands in the cells the program asked for, scrolls with the text around it, and bends with the glass like everything else in the tube.
Pictures stay while you are looking at their pane. When you switch to another tab, the pane forgets them, and coming back shows the text alone. They are not saved with the session and do not come back when a window reattaches.
There is nothing to switch on. Sixel and iTerm2 pictures are not drawn yet. To open a picture file in a square beside the prompt instead, Alt+click its path; that is Documents.
Technical lists what is drawn, what a program is told when it asks, and how a picture reaches a window attached to a session host.
Pictures
What draws
The terminal core, rio-vt, receives and keeps Kitty graphics; the pane draws what the core holds, over and under the grid.1
| Part of the protocol | In a pane |
|---|---|
Formats: PNG (f=100), RGB (f=24), RGBA (f=32) | Drawn |
Sending: inline data (t=d), a file (t=f), a temporary file (t=t), shared memory (t=s) | All four |
A file, temporary file or shared memory that also says more chunks follow (m=1), as mpv's shared-memory mode sends every frame | Not drawn yet: the picture waits for a chunk that never comes (issue 833) |
Placement in cells (c=, r=), cropping (x= y= w= h=), offsets within a cell (X=, Y=) | Drawn |
Stacking (z=) | Negative draws under the text, zero and above over it |
Deleting (a=d) | Honoured |
| Many placements at once | The topmost 256 in a pane are drawn |
Unicode placeholders (U=1, U+10EEEE cells) | Not drawn yet: the cells show as text |
| Sixel, iTerm2 inline images | Not drawn yet |
A picture is not drawn while the rows are read upside down (the anchor-to-top read) or in text crawl, where it has no single cell to sit in. It is still held, and it returns with the plain read.1
A temporary file (t=t) is deleted after it is read, by kitty's rule: only when its name contains tty-graphics-protocol and it sits in /tmp, /dev/shm or $TMPDIR. Any other file named that way is read and left alone. Shared memory (t=s) is read only when it names a regular file in /dev/shm.1
When a picture goes
forget_pictures_out_of_sight, which checks every frame which panes stopped being shown.A tab stops being shown by any route: a click in the left bar, a keyboard jump, a notification, or the pane being carried to another tab. A picture resent by its program gets a new key, so the pane draws the new pixels.1
No snapshot carries a picture, so a window that attaches to a pane shows its text and none of the pictures drawn before it arrived. TD_PICTUREDEBUG=1 makes a window print one line to its log each time a hidden pane lets pictures go, for checking this by script.
What a program is told
Picture programs, and agents choosing their colours, ask the terminal about itself before they draw. Terminal Delight answers as itself.2
| Question | Answer |
|---|---|
Kitty graphics query (a=q) | OK, from the core |
Primary device attributes (CSI c) | ?62;22c: a VT220 with ANSI colour, and no claim to sixel or clipboard access |
XTVERSION (CSI > 0 q) | terminal-delight and the build's version, such as terminal-delight 0.4.0-rc.3 |
Cell size in pixels (CSI 16 t) | The cell the pane told the pseudoterminal |
Text area in pixels (CSI 14 t) | The pane's columns and rows times that cell |
Colours: a palette entry (OSC 4), foreground (OSC 10), background (OSC 11), cursor (OSC 12) | The colour the pane draws it in now, with its theme and gauges applied |
Kitty keyboard protocol (CSI ? u) | No answer, and a request to switch it on changes nothing: keys are sent in the legacy encodings |
XTGETTCAP (DCS + q) | No answer, so a program falls back to terminfo |
Grapheme clustering (CSI ? 2027 $ p) | Not recognised (?2027;0$y) |
kitten icat decides from the first two answers together, and the device-attributes answer is long enough for its detector, so it draws without waiting. Codex asks for the foreground and background as it starts, which is why the colour answers come from the pane: the pane is the one place that knows the colours it draws.23
Panes on a session host
A pane on a session host is parsed twice: by the host, which answers the program, and by your window, which draws. The host answers device attributes and the version, and both size questions from the size it was last told. A colour question is the exception: the host has no theme, so it passes the question to your window, and the pane answers it from the colours it draws.3
A picture sent as a temporary file or as shared memory is deleted by the first terminal that reads it, and the host reads first. So for those two methods the host rewrites the picture into its copy of the stream as inline data before the original is deleted. Inline data and plain files reach the window as the program sent them.4
A window attached to a session host left running from 0.3.0 still draws pictures sent as inline data or a file, because the bytes pass through the old host to the window's own core. That host answers the questions in the table above the 0.3.0 way, so kitten icat waits there before it draws until the host is replaced.
Try it
printf '\033_Ga=T,f=24,s=2,v=1,c=8,r=2;/wAAAP8A\033\\\n'
Two pixels, red and green, stretched over eight cells by two. The line after it starts below the picture.
What would prove this page wrong
A picture that stays on screen after its tab has been hidden and shown again; a picture drawn over the wrong cells after the pane scrolls; a temporary-file picture that shows in a window-owned pane and not in a hosted one; or kitten icat pausing before it draws in a pane whose host was started from this build.
Sources
- The core boundary and the picture verbs: vt/mod.rs and vt/rio.rs (
pictures,MOST_SHOWN, and the tests beside them); the temporary-file and shared-memory rules: vt/kitty.rs; drawing:picture_elementsin pane.rs; forgetting:Workspace::forget_pictures_out_of_sightin main.rs. - The answers:
as_terminal_delightandDEVICE_ATTRIBUTESin vt/rio.rs, with the tests beside them; the colour answers:asked_colourand theColorRequestarm in pane.rs; kitty's detector iskittens/icat/detect.goin the kitty repository. - Which side answers on a hosted pane:
EventProxyin term.rs, and the host's own answers in host.rs. - The rewrite: picturewire.rs; the test that fails without it:
a_picture_sent_as_a_temporary_file_reaches_the_attached_windowin host.rs.