sergei-grechanik / tupimage

A utility to upload and display terminal images using the unicode placeholder extension of the kitty graphics protocol
MIT No Attribution
9 stars 1 forks source link

setting -x/-y position broken in fzf preview? #5

Open Twix53791 opened 3 months ago

Twix53791 commented 3 months ago

Hi, I am using tupimage to display an image preview in fzf. It is working well, but to be perfect I would like change the position of the image on the x axis. I saw the -x/-y options, they are working outside of fzf in the terminal, but not inside the fzf preview. I am wondering if there is a possibility to fix this.

To reproduces:

fzf --preview 'tupimage --force-upload --less-diacritics --fzf {} -x 5'

Output: the image is displayed on a line, broken. Setting the -y position has the same effect.

Thanks for any clue!

sergei-grechanik commented 3 months ago

I've tried it, and I see the same effect: image -x and -y uses cursor movement sequences. My guess is that fzf filters them out. I'm not sure if it should be considered a bug of fzf or an intended behavior.

(Also, -y and -x need absolute coordinates, so they should be shifted by $FZF_PREVIEW_TOP and $FZF_PREVIEW_LEFT)

As a workaround, I would suggest prepending space symbols to each line of the placeholder generated by tupimage. You will also need to adjust the max number of columns. Something like this will create both left and right margins (but it would be cleaner to write a wrapper, of course):

fzf --preview 'tupimage --force-upload --less-diacritics --fzf --max-cols "$((FZF_PREVIEW_COLUMNS - 10))" {} | sed "s/^/     /" '

Note that --max-cols should come after --fzf.

If you want something like centering, however, you need to know the actual width/height of the image. This is achievable with a wrapper, but not as easy, probably would be easier to modify tupimage itself to support it.