kamiyaa / joshuto

ranger-like terminal file manager written in Rust
https://crates.io/crates/joshuto
GNU Lesser General Public License v3.0
3.35k stars 151 forks source link

Simplify image preview #450

Open alvaro17f opened 8 months ago

alvaro17f commented 8 months ago

Hi, I've recently have found another terminal file manager called Yazi, It simplifies the image preview process till the point that's built in. So as a user, you don't need to configure anything. Could Joshuto achieve something like this?

Thank you.

superiums commented 8 months ago

it's not a same direction. yazi has it builtin. joshuto just let it be done by the one you prefer.

both are great, choice was yours.

alvaro17f commented 8 months ago

I think it would be awesome to have this built into joshuto.

For example, I'm having a problem to setup the image preview along with the following script:

function joshuto() {
    ID="$$"
    mkdir -p /tmp/$USER
    OUTPUT_FILE="/tmp/$USER/joshuto-cwd-$ID"
    env joshuto --output-file "$OUTPUT_FILE" $@
    exit_code=$?

    case "$exit_code" in
        # regular exit
        0)
            ;;
        # output contains current directory
        101)
            JOSHUTO_CWD=$(cat "$OUTPUT_FILE")
            cd "$JOSHUTO_CWD"
            ;;
        # output selected files
        102)
            ;;
        *)
            echo "Exit code: $exit_code"
            ;;
    esac
}

To me, the ability to cd on exit, and the image preview built in are sane default.

superiums commented 8 months ago

i did the same thing in fish, and success to cd to the selected dir after exit. i guess bash may do too.

superiums commented 8 months ago

img preview, may be done by imv, mvi, swayimg, etc. the ueberzug way, seems not work in wayland. SIXEL way maybe better. but seems it's not supported.

alvaro17f commented 8 months ago

Do you know how to setup img preview using these alternatives to ueberzug?

superiums commented 8 months ago

SIXEL way has to wait the author support. i use swayimg as image opener, just open with it.

alvaro17f commented 8 months ago

I'm able to preview images with ueberzugpp modifying the preview_file script from exit 1 to exit 0:

            ## Image
        image/*)
            ## Preview as text conversion
            exiftool "${FILE_PATH}" && exit 0
            exit 0 ;;

The thing is, I'm unable to cd on quit as I used to if using img preview.

superiums commented 8 months ago

if preview with exiftool, file info displayed instead of img. https://github.com/kamiyaa/joshuto/issues/336 discussed sixel.

cd on quit i did in fish only.

DLFW commented 8 months ago

Hi, some thoughts from my side:

Sixel should be usable via Überzug++. I haven't tried it myself, but it's one of the supported backends. If you have Überzug++ running with Sixel, you can just integrate it into Joshuto.

if preview with exiftool, file info displayed instead of img.

Not sure what you mean, but in Joshuto, you can have both. I want meta data and a visual preview together, which can be done as explained here.

I see this as one of the advantages in Joshuto, you have more freedom in assembling your preview. But I also agree that image preview is a very important feature for most users and that the setup-effort in Joshuto is a hassle for some new users, especially those who are not comfortable with scripting.

If we can figure out a way how we can keep the flexibility and the option of combining text- and image-preview, I would also appreciate a build-in solution.

@kamiyaa: Would you be open to merge a hard integration of image-previews like in Yazi? We could get some “inspiration” from its code base. My proposal would be to define special “commands” that can be placed in the text-preview output, and that would get replaced by an image. This would allow the combination of text and images. Scrolling of the preview might be tricky though. BTW: I'm working on a thumbnail-program (AllMyToes) that we could use as a Rust library. It provides XDG thumbnails for images and I guess I will add support thumbnails for other mime types soon as well. This would also be an enhancement because the thumbs are of course much smaller in most cases and loading would be way faster, and when AllMyToes supports other mime types, we get image previews for PDF, videos, etc. in a configurable way for free. Also, it would always tell Joshuto the image ratio, so we could calculate the height when combining images with text. Downside: AllMyToes is developed only for Linux, I'm not sure if it works on MacOS. Don't get me wrong, I don't volunteer for this feature right now, but we could start a discussion on that.

superiums commented 8 months ago

i think the ueberzug and sixel does the same thing in different way. they all try to display image in terminal. if SIXEL protocal is supported, no need to use ueberzug then.

superiums commented 8 months ago

by the way, the compute of info height , maybe not so neccesary. we may display img first. the info at bottom. if too long, cut or scroll both ok.

kamiyaa commented 6 months ago

Personally, I haven't used image previews much because they rarely work on Wayland. I also find its performance a bit undesirable at times, so I usually only have text preview enabled.

I'm open to the idea of building in more features into joshuto that helps with image previews. But I think we should still make it configurable to the user on which image preview program they want to use, where it should be placed, etc.

ikimmit commented 6 months ago

In case it is of interest to anyone, while trying and failing to make Überzug++ work for me under MacOS+iTerm2 I realised I could just fall back to unicode art by installing chafa and adding a couple of lines to my preview_file.sh.

image/png | image/jpeg)
    chafa --size=${PREVIEW_WIDTH}x${PREVIEW_HEIGHT} "${FILE_PATH}" && exit 0
    exit 1
    ;;

Some people might mind the quality loss but I find the rendering adorably retro. Maybe it helps another newbie like me.

CassandraCat commented 5 months ago

Überzug++

I also have Überzug++ unable to work on my macos+iTerm2. I tried your method and it can be displayed, but it looks like a mosaic. Is there any better solution?