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!
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?
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.
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:
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
Most helpful comment
So I did some more digging around,
extractColorin 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: