skim-rs / skim

Fuzzy Finder in rust!
MIT License
5.22k stars 191 forks source link

Support images (or more ANSI codes) in preview #174

Open atsepkov opened 5 years ago

atsepkov commented 5 years ago

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:

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).

lotabout commented 5 years ago

@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.

derrickcope commented 5 years ago

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