joshuto icon indicating copy to clipboard operation
joshuto copied to clipboard

Simplify image preview

Open alvaro17f opened this issue 2 years ago • 14 comments

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.

alvaro17f avatar Oct 19 '23 07:10 alvaro17f

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.

superiums avatar Oct 25 '23 06:10 superiums

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.

alvaro17f avatar Oct 25 '23 13:10 alvaro17f

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

superiums avatar Oct 25 '23 14:10 superiums

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.

superiums avatar Oct 25 '23 14:10 superiums

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

alvaro17f avatar Oct 25 '23 14:10 alvaro17f

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

superiums avatar Oct 25 '23 14:10 superiums

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.

alvaro17f avatar Oct 25 '23 14:10 alvaro17f

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.

superiums avatar Oct 25 '23 15:10 superiums

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.

DLFW avatar Oct 25 '23 21:10 DLFW

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 avatar Oct 26 '23 14:10 superiums

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.

superiums avatar Oct 26 '23 14:10 superiums

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.

kamiyaa avatar Dec 19 '23 15:12 kamiyaa

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.

ikimmit avatar Dec 25 '23 16:12 ikimmit

Ü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?

CassandraCat avatar Jan 18 '24 12:01 CassandraCat