junegunn / fzf

:cherry_blossom: A command-line fuzzy finder
https://junegunn.github.io/fzf/
MIT License
65.4k stars 2.41k forks source link

Possible to use iTerm2's `imgcat` shell integration? #1102

Closed mattbaker closed 1 year ago

mattbaker commented 7 years ago

Is it possible to get iTerm2's imgcat shell integration working in an fzf preview? https://www.iterm2.com/documentation-images.html

I'm guessing this is at the core of the issue:

iTerm2 extends the xterm protocol with a set of proprietary escape sequences. In general, the pattern is: ESC ] 1337 ; key = value ^G Whitespace is shown here for ease of reading: in practice, no spaces should be used. For file transfer and inline images, the code is: ESC ] 1337 ; File = [optional arguments] : base-64 encoded file contents ^G The optional arguments are formatted as key=value with a semicolon between each key-value pair [...]

Right now I just see plain text (1337 followed by the relevant key-value pairs) which wasn't a shock, but I am curious if there's a way to get it working :) As you can imagine, piping images through imgcat in a fzf preview command would look really cool!

Townk commented 5 years ago

I was just trying to do the same and got the same result. If this is not possible, is there an alternative to preview images on MacOS?

atsepkov commented 5 years ago

I glanced at the preview function (https://github.com/junegunn/fzf/blob/master/src/terminal.go#L1018), I can see it's doing some parsing for the ANSI codes used to represent colors. I wonder if the problem is that it ends up stripping part of the escape sequence iTerm2 expects to see in the output to trigger the image rendering.

atsepkov commented 5 years ago

So I did some more digging around, extractColor in https://github.com/junegunn/fzf/blob/master/src/ansi.go is the function used to detect the color sequences, which are different, but start in a similar way. It does it like this:

So my takeaway (as a random developer who stumbled into this, not as any one who has experience with this project) is we can't reuse ansi functionality for this escape sequence because neither the state variable in ansi.go, nor CFill was designed to handle this case, and won't be able to handle it without significant changes to the logic (so to keep things clean, it's better to leave that alone).

However, what I would recommend (to the brave soul who decides to implement this, since I don't have time to do so myself, unfortunately), is the following:

rien333 commented 4 years ago

Would other image protocols fare any better? Kitty's implementation seems fairly diffrent, though maybe not in the relevant ways. sixel aims at more universal support, see e.g.: https://github.com/hackerb9/lsix

khughitt commented 3 years ago

Somewhat related, but would it be difficult to allow preview to support image rendering via mdcat?

mdcat renders markdown documents with images in kitty fine, but when attempting to use mdcat to preview files (--preview 'mdcat {}'), the image get replaced with some long string starting with "Ga=T,t=d,..", e.g.:

Ga=T,t=d,f=24,s=659,v=374,m=1;/////Pz8////9PT0/Pz88/Pz+...
bonnefoi commented 3 years ago

Could you add sixel support ?

guilhermeprokisch commented 3 years ago

Somewhat related, but would it be difficult to allow preview to support image rendering via mdcat?

mdcat renders markdown documents with images in kitty fine, but when attempting to use mdcat to preview files (--preview 'mdcat {}'), the image get replaced with some long string starting with "Ga=T,t=d,..", e.g.:

Ga=T,t=d,f=24,s=659,v=374,m=1;/////Pz8////9PT0/Pz88/Pz+...

I'm also wondering if it is possible.