Repository navigation
Kitty graphics - #20872
Kitty graphics#20872Matthew Wilding (mbwilding) wants to merge 15 commits into
Conversation
Implements the kitty graphics protocol, along with XTVERSION so that applications can identify the terminal. * The parser dispatches APC strings to a handler, and the input engine passes APC responses through ConPTY. * Images can be transmitted directly, in chunks, or via files, temporary files and shared memory, as PNG or raw RGB/RGBA data, optionally zlib compressed. Network and device paths are rejected. * Placements are attached to the rows they cover, so they scroll and reflow with the text and aren't erased by text output. The cell footprint uses the virtual cell size so ConPTY and the terminal agree on the cursor position. * Virtual placements and Unicode placeholders are supported, along with all delete modes, queries and feature queries. * AtlasEngine (D3D and D2D) and GDI draw images below backgrounds, below text or above text, according to their z-index.
* Exceptions in the graphics command handler no longer escape into the state machine. * Shared memory is only read when its pages are committed. * Images larger than the device's maximum bitmap size are downscaled instead of failing every frame. * Like kitty, all images count towards the storage quota, and evicted images are removed from the screen as well. * Like kitty, only images entirely within the scroll margins move with them, and scrolling the whole region removes its images. * Deleting by id without an id no longer matches every anonymous image. * A hard reset removes all placements. * Reflow keeps the graphics of rows joined onto a previous row. * GDI caches several images instead of only the most recent one. * EFBIG replies identify the command that was too large. * ConPTY no longer keeps the pixel data, since it never renders it.
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
This comment has been minimized.
This comment has been minimized.
Formats the changed files with clang-format, keeping the placeholder diacritic table on a grid, and adds the new API and protocol names to the spelling expect list.
@microsoft-github-policy-service agree |
* Rows replaced by ResizeTraditional are destroyed, so the images and other resources they own are no longer leaked. * Images are attached to every row they're drawn on, while the cursor still moves by the footprint kitty uses. * Images larger than the storage quota are rejected, the image being added is never evicted, and the number of images is limited. * Freeing an image keeps it while virtual placements still use it. * Rows joined during reflow keep a single strip of each placement. * ConPTY marks its cursor position as uncertain after placements, and only reads the image dimensions instead of decoding the pixels. * The D3D renderer draws the cursor above images below the text, and doesn't retry bitmaps that failed to be created in every frame. * GDI clamps the source rectangle, clips images above the text to the invalidated area, and limits its bitmap cache by size.
This comment has been minimized.
This comment has been minimized.
absolutely not :) |
FWIW, I would have hoped to see something explaining the "placement diacritics" and stuff in this section. It seems like a pretty significant part of how it.. works.. 🙂 |
Dustin L. Howett (DHowett)
left a comment
There was a problem hiding this comment.
(blocking for direction review)
The cursor is drawn after the images below the text, which places its quads within the range that the cursor foreground pass treats as text. That pass now skips everything that isn't text, so it no longer recolors the cursor itself.
They're part of the kitty unicode placeholders spec. the app prints U+10EEEE as normal text, the image id goes in the fg colour, the placement id in the underline colour, and the diacritics give the row/column (plus the top byte of the id if it needs it). since it's just text it scrolls and reflows like everything else, so tmux/nvim for example can move images around without knowing anything about the protocol. renderer decodes them per row and draws that part of the image under the text. |
Certain things rely on this for functionality as it identifies the terminal (admittedly some things use this value to apply work arounds for particular terminal emulators). For example the snacks image plugin for neovim will read this value. What's the aversion to having it as part of WT? |
So, mostly on principle. There's a long discussion in both a PR which attempted to introduce it (#20268) and the original feature request for it (#18382), which I won't go all the way into here. The TL;DR:
I don't think he knows about second user-agent, Pip. |
|
No worries, I have removed the logic for XTVERSION. |
|
If you want to have some good test/benchmark, you can use my music software that support kitty graphic rendering. rustel.cc (ctrl-o for settings > then choose kitty graphics in rendering mode) |
There was a problem hiding this comment.
I gave this PR a glance and I think this is generally the right direction. It may be worth basing our implementation on this PR out of the 3 we have. Perhaps unsurprisingly it requires significant polishing.
There's also some things that I have personal feelings on. For instance, I think that deflate compressed raw RGB is a particularly bad aspect of the Kitty protocol, to put it mildly.
PNG is literally deflated RGB with a prefilter. Why on god's green earth would you not use it??
I have a strong urge to ask you to remove its support, and similar blasphemous features, but I'm not entirely sure about that yet. 🫥
# Conflicts: # src/terminal/parser/ut_parser/StateMachineTest.cpp
Dustin L. Howett (DHowett)
left a comment
There was a problem hiding this comment.
just some thoughts while commit 2917bdc went by my inbox
No worries, I sorted those out. Now, to get this more production ready, what would you like me to sort out in the meantime to move it closer to an approval? |
Summary of the Pull Request
This adds support for the kitty graphics protocol to Windows Terminal and conhost. Tools that use the protocol, such as snacks.nvim's image viewer, can display images directly in Windows Terminal, including inline markdown images in Neovim.
References and Relevant Issues
#8389
Detailed Description of the Pull Request / Additional comments
What's supported
What isn't supported
Animation, relative placements and the palette-indexed formats (
f=8andf=16) reply with an error.New dependency
zlib is added to
vcpkg.jsonto decompress zlib-compressed transmissions (o=z).Change to existing code
ResizeTraditionalpreviously freed rows without destroying them, so image data leaked on resize. This affected sixel images too, so the fix changes existing behaviour.How it works
Validation Steps Performed
PR Checklist
Written with AI assistance.