lf: kitty-0.27.0 preview not working due to change in icat's transfer mode

Hi, I was having a problem with my previewer script, which is rather complex.

So I just commented everything and tried the basic example script from the documentation:

#!/bin/sh

file=$1
w=$2
h=$3
x=$4
y=$5

if [[ "$( file -Lb --mime-type "$file")" =~ ^image ]]; then
	kitty +icat --silent --transfer-mode file --place "${w}x${h}@${x}x${y}" "$file" && echo "$file" >> lemmesee
	exit 1
fi

As you can see, I added the && echo 'success' >> lemmesee at the bottom of the command.

The file never gets created in the first place when I hover on some image. The weird part is that, if I manually run that command it works flawlessly.

This is the relevant configuration file:

set shell sh
set shellopts '-eu'
set ifs "\n"
set icons
set mouse

set scrolloff 10
set drawbox

set ignorecase true

set previewer ~/.config/lf/preview.sh
set cleaner ~/.config/lf/clean.sh

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Reactions: 10
  • Comments: 20 (4 by maintainers)

Commits related to this issue

Most upvoted comments

When I switch between two png image files (up and down arrow keys), the following message appears. … may be a binary file. See it anyway? Then it will lose response and the keys will not work, if I try ctrl-c to terminate, the key codes will be printed at the bottom line.

I had the same issue when I tried running it without --transfer-mode file, however with it, all works as expected. This is what my scripts currently look like: lf_kitty_clean:

#!/usr/bin/env bash

kitty +kitten icat --clear --stdin no --silent --transfer-mode file < /dev/null > /dev/tty

lf_kitty_preview:

#!/usr/bin/env bash
file=$1
w=$2
h=$3
x=$4
y=$5

if [[ "$( file -Lb --mime-type "$file")" =~ ^image ]]; then
    kitty +kitten icat --silent --stdin no --transfer-mode file --place "${w}x${h}@${x}x${y}" "$file" < /dev/null > /dev/tty
    exit 1
fi

I am having the exact same issue. I am able to view images in my kitty terminal and in the shell created by clicking w, But Lf isn’t able to display the generated image even though I can view it directly in my terminal with kitty. I verified that the thumbnail was generated like expected but Lf is unable to display the image. I have a gut feeling that it might have something to do with the new improvements in kitty.

@ignamartinoli NOTE: due to a recent change in kitty 0.27.0, the '+kitten' subcommand is needed to run all kitty kittens .ie $ kitty +kitten icat but this still doesn’t work.

- A new statically compiled, standalone executable, kitten (written in Go) that 
can be used on all UNIX-like servers for remote control (kitten @), 
viewing images (kitten icat), manipulating the clipboard (kitten clipboard), etc.

- icat kitten: Speed up by using POSIX shared memory when possible to transfer 
image data to the terminal. Also support common image formats 
GIF/PNG/JPEG/WEBP/TIFF/BMP out of the box without needing ImageMagick.

@rockyzhang24 I use your previewer config but ended in crash once I push w button trying to enter bash with the image’s preview by the side. Peek 2023-06-19 17-38 return zsh: suspended (tty output) lf once I tried to input something, kitty closed. I didn’t find the reason.

@Kazuma-chan Anyway it works on my side, so it means no issues for kitty and lf. I recommend you to install lf by the command I mentioned above and see if your issue is resolved.

The new kitty preview and clean command work perfectly but this sometimes crushs the lf instance or the shell when entering/opening a sub shell with the w default map.

To reproduce

open lf in a new terminal window highlight an image for previewer to kick in press the w key

This produces an error zsh: suspended (tty output) lf

when you try to reopen lf imediately afterwards in the shell you are drop in you get the error zsh: error on TTY read: Error from entering/leaving Captura de pantalla de 2023-02-16_23:28:15 Captura de pantalla de 2023-02-16_23:34:42

The link to my lf configuration files

The author of kitty pointed out a trick to fix this. Please change the command to kitten icat --transfer-mode file --stdin no --place "${w}x${h}@${x}x${y}" "$file" < /dev/null > /dev/tty.

For details, see https://github.com/kovidgoyal/kitty/issues/6010 please.