lf icon indicating copy to clipboard operation
lf copied to clipboard

chafa --format=kitty not working inside lf

Open MunifTanjim opened this issue 10 months ago • 4 comments
trafficstars

I'm using Tmux, with allow-passthrough enabled.

If I run chafa outside lf, (still inside tmux), it works:

image

But inside lf preview window it shows this:

image

They're both using the same command chafa --format=kitty --polite=on $f.

MunifTanjim avatar Jan 08 '25 07:01 MunifTanjim

I sort of managed to get it working using kitty directly, inside tmux with allow-passthrough enabled. Didn't use chafa at all. Someone else made a similar post on Reddit as well.

joelim-work avatar Jan 12 '25 05:01 joelim-work

You have to redirect it directly to the tty with >/dev/tty. However, it won't work well with chafa as far as I can tell. You can align it to the right, but the fact that it can't take in positional arguments causes images to always display at the bottom.

What worked for me in ghostty was installing the kitty-kitten package and using icat as described here in the wiki, but I had to change icat to use --transfer-mode=memory.

Hopefully there is a way this could be done with chafa in the future since the kitten package is superfluous for only this purpose.

brianclinkenbeard avatar Feb 06 '25 05:02 brianclinkenbeard

setting cursor position feels like it works fine for me in a regular terminal, but i dont think this works via passthrough, regardless if it helps anyone this is what i use on ghostty (you might have to print different escape codes to save and load cursor position)

   printf "\0337" > /dev/tty
   tput cup "$5" "$4" > /dev/tty
   chafa --polite on --relative on -f kitty -s "$2x$3" --animate off "$1" > /dev/tty
   printf "\0338" > /dev/tty

kaizoplant avatar Feb 06 '25 18:02 kaizoplant

I managed to set the position of the image using chafa on ghostty (using the kitty image protocol). The trick is to first load the output of chafa into a variable, set the cursor to the desired position, and then print the chafa output. If you try to directly use the output of chafa, lf redraws (and therefore repositions the cursor) before chafa can print the image into the console.

This snippet is written in fish, but it should easily be adoptable to bash.

# Buffer the output of chafa
set output $(chafa -f kitty --animate off -s "$width"x"$height" $file)
printf "\e["$y";"$x"H" >/dev/tty # set the cursor to the correct position
printf $output >/dev/tty # print the chafa output
exit 1 # exit with non-zero, so that the image gets redrawn every time 

And cleaning the preview is possible with simple escape sequences.

# Remove all Kitty Images
printf "\e_Ga=d,d=A;\e\\" >/dev/tty

janicsc avatar May 16 '25 07:05 janicsc