lf icon indicating copy to clipboard operation
lf copied to clipboard

sixel image preview not working with script but outputs multiple lines of characters when quitting lf

Open lukeflo opened this issue 1 year ago • 2 comments

I know here are multiple issues concerning image preview, but not the exact same outcome.

I use a preview script taken from the wikipage:

case "$(file -Lb --mime-type -- "$1")" in
 ...
 ...
    *text/plain*|*text/x-shellscript*)
        # return false to always repaint, in case terminal size changes
        bat --force-colorization --paging=never --style=changes,numbers \
            --terminal-width $(($2 - 3)) "$1" && false
        ;;
    *image/*)
        chafa -f sixel -s "$2x$3" --animate off --polite on "$1"
        exit 1
        ;;
    *)
        echo "unknown format"
        ;;
esac

My config file is set up with sixel and sourcing the script:

# previewer
set previewer /home/user/.config/lf/previewer.sh
set sixel true

But i get no preview and when I quit lf the terminal is flooded with characters:

2024-03-12_22-00

From inside my terminal the command chafa -f sixel -s 100 --animate off --polite on "file" works fine, also the simple one img2sixel "file".

Maybe I'm missing something obvious, but I've tried out different things. ctpv is also not working correctly when trying to use chafa for unclear reasons (even the patched version). But since it is not as good configurable, I would be happy with the preview script.

My setup: Manjaro Linux chafa 1.14 alacritty terminal with sixel support (also not working in wezterm) lf r31

lukeflo avatar Mar 12 '24 21:03 lukeflo

I have the same issue, even when using the exact preview script from the lf wiki. All I get is a line of strings like this:

P0;0;0q"1;1;1900;1062#0;2;0;0;0#1;2;5;5;5#2;2;10;10;9#3;2;12;12;12#4;2;14;14;14#5;2;50;5;6#6;2;13;

Used terminal: foot

config:

set previewer ~/.config/lf/sixelPreview.sh

contents of sixelPreview.sh

#!/bin/sh

case "$(file -Lb --mime-type -- "$1")" in
    image/*)
        chafa -f sixel -s "$2x$3" --animate off --polite on "$1"
        exit 1
        ;;
    *)
        cat "$1"
        ;;
esac

I can run chafa just fine outside of lf

vam67423 avatar Apr 09 '24 21:04 vam67423

Since the problems wasn't solved so far, I just switched to fff. It works very similar to lf. And because it is written entirely in bash, it's much easier to modify things by myself.

Thus, I forked the fff repo and implemented a simple file and image preview using sixel which works just good enough for me. Maybe it also satisfies your needs: https://github.com/lukeflo/f3

Maybe someone of the lf guys can still solve the original issue posted here. I, myself, have no experience programming in Go...

lukeflo avatar Apr 10 '24 06:04 lukeflo

Are you using lfcd? I had the same issue, but solved it by updating to the latest version (r32). (See this thread and #1451.) You may need to build it from source, as not every distribution has packaged the latest version.

ericmurphyxyz avatar May 08 '24 10:05 ericmurphyxyz

@ericmurphyxyz Thanks for the investigation, I can also reproduce with lfcd on version r31. Closing this as the issue has already been fixed.

joelim-work avatar May 12 '24 06:05 joelim-work