New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Kitty's graphic protocol support #12991
Comments
I would love to have protocol in Neovim that pretty much tells GUIs: you can render this region as image/html/markdown instead of the alt-text that's actually there. |
Yes, this would be really neat, making neovim stand up against modern IDEs on every level! |
I am looking at the source code trying to understand where this would fit, can anyone point at me the files/function to look at? |
maybe we want some kind of concept for representing images in GUI:s in general. then a kitty-protocol implementation in TUI would just follow, as TUI is just another GUI already. |
Not too sure about the extent of what you mean by concept.
|
@nscotto I guess what bfredl is trying to say is that implementing special escape sequences shouldn't live in the main TUI client and in this repo. There could be kitty-client in a separate repo that could display images. For that it must be able to ask nvim where there are actually images (and meta data like size etc.). This could implemented by nvim lua module that places extmarks at ranges where images can be displayed. The kitty client can just ask the lua module for the images and then output the escape codes. This way there would be virtually no code in the main repo and each client can implement the rendering of the meta data their way. |
Just wanted to note that there's already image support in Markdown; some LSP servers use that to get VS Code to show hover previews with images, e.g., as ![preview](data:image/png;base64, .... ) I second the suggestion of @theHamsta to start with extending the floating window protocol to include "rich" content so you can indicate that the buffer is in fact Markdown or HTML that should be interpreted rather than shown literally (which a GUI can then do, while the TUI may instead strip the markup and do its best with conceal, like the current LSP hover/signature help code). The next step would then be "extended language injection" to allow applying this to specific regions of a buffer. |
We don't want to hard code the kitty sequences in the versioned ui protocol ( |
I'd love to have something like this in neovim, but I am having a hard time imagining what an API for this would look like - you'd definitely want to have a way for programatically drawing images, not just a file on a disk. Maybe an API where you could specify a framebuffer to draw at a specific position on the buffer? And then different UIs would implement it differently - the TUI could implement it if it detects a compatible terminal, for example. |
Another alternative to kitty's protocol, which I think only kitty supports, is sixel which IIRC was recently implemented by vte-ng, which gnome-terminal and termite use. Of course, the best option here would really be to just have a way for plugins to implement the details of the graphics protocol themselves, while neovim just forwards a buffer with raw pixel data. |
I tried to understand sixel from the available documentation but I think I failed |
It makes sense. In this discussion kitty's author explain why he wrote a new protocol, worth checking out. |
@bfredl The problem with Sixel sadly is, that the amount of grid cells involved depends on the font metrics and size being used. Before going to "just implement" one image protocol, I think we've to admit there is some fragmentation and it would make sense to whatever image protocol is going to be supported by (Neo)?vim it should probably made in a more abstract way to support not just one image protocol (NB: there's great work from @csdvrx to display pixmaps via a unicode rasterizer, a great way to work around non-supporting terminals). There is (or was) quite some heat discussions on a future image protocol in the terminal-wg forum however, that I think is worth keeping an eye on: 12 and 16. p.s.: I'd love to see that happening in a somewhat terminal-independant manner at some point so that when I'm editing latex, my latex plugin can render math formulas in little popup windows :D |
In addition to kitty and libsixel, there is also imgcat in iTerm2 and tycat in terminology. Without understanding how involved these different approaches would be to implement in Neovim, from a user's perspective I think it seems reasonable to focus on supporting just one solution to start out, so that people who are really keen on viewing images could use that setup. kitty seems like a good choice based on that it is available on both Linux and MacOs. Maybe there could also be a fallback mode using half blocks similar to the image viewer viu? I tried displaying images using kitty's icat in the floatterm plugin, but ran into issue #8259. Viu works with floatterm, but only in fallback mode. |
I am sorry, that would be a really hard choice - trying to be objective here... But the kitty image protocol is implemented by only one terminal emulator and was already said to be easy to complex to be adopted by the general public. It is not a bad protocol, just to have that said, but only implementing half of it would make it so. I am not a fan of either, but (again, objectively speaking) i think Sixel is, despite all all odds of complains, the one implemented by most TEs. |
we can do that already by using virtual text which can be placed anywhere on the buffer. |
Konsole in kde also supports the kitty image protocol. When I try to use the same command inside of a neovim |
@cathaysia Although, one forgot to mention how amazed dankamongmen is about the blazingly fast performance of the Kitty image protocol. From an adopters point of view, that must be considered as well. ;-) |
Window size in pixels is required by some programs, reporting it in terminal emulators supporting it can help those programs work inside the NeoVim terminal as outside. See also: neovim#8259, neovim#12991
Window size in pixels is required by some programs, reporting it can help those programs work inside NeoVim terminals. See also: neovim#8259, neovim#12991
nvim --version
: 0.4.4$TERM
: xterm-kittyKitty terminal created a protocol for graphic support using escape characters, we could display images in neovim by supporting the protocol.
I would love to see this feature implemented as it would enable full notebook (R notebook, jupyter notebook, also markdown) experience in neovim as well as many other applications.
While Kitty is (as far as I know) the only terminal to support graphics at the moment, their protocol is designed to integrate well with current terminal architectures.
The text was updated successfully, but these errors were encountered: