skim icon indicating copy to clipboard operation
skim copied to clipboard

Support images (or more ANSI codes) in preview

Open atsepkov opened this issue 5 years ago • 2 comments

There are a few image formats supported by terminals: sixel, iTerm2 (imgcat), and most-recent one by Kitty (https://sw.kovidgoyal.net/kitty/graphics-protocol.html). Each of these works by sending a special escape sequence to the terminal, similar to the ANSI codes used for colors.

These sequences are still not standardized, but that is technically for end-user to deal with. What is standardized is the ESC prefix they all use, which currently seems to get stripped by skim based on a quick test I did. Would it be possible to add support for this for preview window (by forwarding the ESC code to the terminal)? It could even be hidden behind a special flag, similar to --ansi, such as --extended-esc-codes.

The main benefits of this would be:

  • image previews for regular files on disk
  • other scripts/projects that can make use of image previews

One example of the 2nd bullet is my own project that currently uses FZF but considering a change to Skim due to easier customization and ability to configure key interaction: https://github.com/atsepkov/Graphene. Image support would allow webpage previews, as well as better representation of image-based search results (such as an Amazon product search).

atsepkov avatar May 28 '19 18:05 atsepkov

@atsepkov It's a great idea. I've been thinking how to achieve it once I saw this, but seems no easy way with skim. Here are the obstacles:

  1. As you suggested, skim need to support more ANSI codes instead of just ignore them. (this is relatively easy)
    • When the input contains invalid ANSI codes, they'll be ignored.
    • If somehow the ANSI did goes into the memory, the rendering engine will escape them, otherwise the output will be messed up.
  2. Skim need to find a way to output all these whole bunch of base64 encoded content.
    • Currently skim use a cache layer for rendering, e.g. all the characters first output to a in-memory buffer, and then output only the differences.
    • Also, current rendering logic would try to eliminate the rows/columns that exceed the screen.

The difficult part is actually the second part in that skim needs to treat some output differently. I don't know how fzf achieve this, but IMO there was no simple way.

Anyway, I'll keep thinking and I do think it would be nice to have this.

lotabout avatar May 30 '19 01:05 lotabout

There is a rust crate viu that can show images in the terminal if that is helpful.

derrickcope avatar Oct 27 '19 23:10 derrickcope