pystardust / ytfzf

A posix script to find and watch youtube videos from the terminal. (Without API)
GNU General Public License v3.0
3.78k stars 343 forks source link

Thumbnails non-functional in Wayland using normal terminal emulators #64

Open littlediobolic opened 3 years ago

littlediobolic commented 3 years ago

Thumbnails do not display in Wayland using a normal terminal emulator due to ueberzug relying on X. This is obviously an upstream issue but something I feel is worth mentioning. For example gnome-terminal does not work.

I tested in kittyhowever, which has its own image protocol and it does work, but in 99% of terminals it will likely not work by default.

pystardust commented 3 years ago

We are using ueberzug for image previews. Ueberzug doesn't work well with wayland. We will need to look for other terminal viewers.

SamsiFPV commented 3 years ago

I did a little bit of testing on this. It works on X11 based terminal emulators such as urxvt. Wayland based ones such as terminator don't work. Which has definitely to do with ueberzug being X11 based. Adding an additional option for us Wayland users would be appreciated. PS: @littlediobolic i didn't got it to work with kitty, how did you do that? It's a wayland native app so it shouldn't work, since ytfzf only supports ueberzug and not kittys own protocol.

napcok commented 3 years ago

@SamsiFPV Terminator is not Wayland based, and thumbnails works very well in Terminator on X11.

SamsiFPV commented 3 years ago

@napcok wrong wording form my side, i meant it runs in wayland natively. My bad.

pystardust commented 3 years ago

How about we use an external viewer? I was able to make it work with sxiv (any viewer that auto updates when the file changes) . The only caveat is that it wouldn't look great since you have 2 windows, one with names and the other with thumbnails.

tekakutli commented 3 years ago

maybe a pretext to re-invent ueberzug but for wayland? could be useful for tons of things

littlediobolic commented 3 years ago

PS: @littlediobolic i didn't got it to work with kitty, how did you do that? It's a wayland native app so it shouldn't work, since ytfzf only supports ueberzug and not kittys own protocol.

@SamsiFPV I did not do anything special to get it working. I just downloaded kitty, ran it, and thumbnails displayed properly. I can send logs if necessary but I am unsure what caused it to work.

tgunnoe commented 3 years ago

I would recommend looking at kitty https://sw.kovidgoyal.net/kitty/graphics-protocol.html

DanKGooGLy commented 3 years ago

What about sixel?

Euro20179 commented 3 years ago

I tried img2sixel and lsix both didnt work but the problem is that fzf interprates input itself and doesnt let the terminal interprate the input, so sixel and anything that draws the image on the terminal itself wont work, w3m could work but the image does not stay on the screen.

DanKGooGLy commented 3 years ago

Try chafa

Euro20179 commented 3 years ago

254 adds a few different methods for viewing thumbnails, chafa is one of them, it has been accepted into the development branch, so if you clone the development branch and run ytfzf --thumb-disp-method=chafa it should use chafa for displaying thumbnails (it is a bit laggy but not as laggy as catimg)

I also will probably keep trying to implement w3m since it's a proper image viewer

duffydack commented 3 years ago

would love sixel support so I can use in sway, with 'foot'. Ranger works well with a sixel patch. Tried chafa, it works, but looks a bit rubbish. Hope sixel gets supported.

Euro20179 commented 3 years ago

sixel just does not work in fzf, it ends up displaying the actual characters (yes I tried in a terminal that supports sixel).

duffydack commented 3 years ago

Shame. Guess I'll use chafa then, and squint a bit. :)

Euro20179 commented 3 years ago

Haha, chafa imo is actually decent but not as good as true image viewers ofc. w3m's image viewer might work with fzf but it seems to not stay on the screen for very long.

timsofteng commented 3 years ago

Doesn't work on nixos in foot terminal even with this flag ytfzf --thumb-disp-method=chafa

dnkl commented 3 years ago

@timsofteng you also need --show-thumbnails

timsofteng commented 3 years ago

@timsofteng you also need --show-thumbnails

Thanks! Yes, it works with ansi format. image

P.s is it limitation of fzf? Images in terminal is a big pain... Tmux doesn't suppor sixel as wel...

Euro20179 commented 3 years ago

is it limitation of fzf

yes

VarLad commented 3 years ago

Was anyone able to get it to work with Kitty's icat?

Euro20179 commented 3 years ago

Did some testing with w3m, learned it's protocol to understand what is happening with this command

printf "%b\n%s\;\n%s\n" "0;1;$x;$y;$width;$height;;;;;$image" 3 4 | w3mimgdispaly

here's the docs (yes this is all i could find)

Basically what I think is happening is, w3m is drawing the image THEN fzf is drawing the preview window, however i also tried using skim and it had the exact same issue.

If anyone knows an fzf alternative/fork that includes the --preview flag I can try it.

My solution to this is to put that line of code in a while true loop so that w3m is always drawn ontop of the preview window, this is a very bad solution, but it works.

Euro20179 commented 3 years ago

w3m image support has been merged into the rewrite, I wasn't able to find a better way to do it though.

VarLad commented 3 years ago

@Euro20179 Isn't w3m-img X11 specific?

Euro20179 commented 3 years ago

@VarLad Damn, didn't realize that, tested it on say, yes it's x11 specific. If you can't get thumbnails on wayland with w3m i'm not sure how you can, so this will remain open for the foreseeable future.

VarLad commented 3 years ago

@Euro20179 Can you try out kitty's icat? https://github.com/kovidgoyal/kitty/issues/2238

Euro20179 commented 3 years ago

I have no idea why I just realized this now, but when i tested w3m on wayland, i tested it in alacritty, in which w3m doesn't work at all, retested it in sway with xterm, and yes w3m works.

TLDR: messed up my testing in wayland, w3m does work in wayland.

VarLad commented 3 years ago

@Euro20179 Its because XTerm runs on XWayland. ueberzug works that way too That runs with Wezterm with Wayland disabled too (which means its using XWayland)

Euro20179 commented 3 years ago

I was not using XWayland, i ran sway by itself. And to test, i logged into another tty, and launched sway from there. w3m worked, ueberzug did not.

ankkax commented 2 years ago

Thumbnails do not display in Wayland using a normal terminal emulator due to ueberzug relying on X. This is obviously an upstream issue but something I feel is worth mentioning. For example gnome-terminal does not work.

I tested in kittyhowever, which has its own image protocol and it does work, but in 99% of terminals it will likely not work by default.

how did you get images showing with kitty, it is my main terminal and I don't get pictures.

adworacz commented 2 years ago

This appears to be broken currently. I just tried to use chafa on Arch, and I get an error stating that ueberzug is not found.

Screenshot: 20211229_12h15m20s_grim

Edit: Appears to be this line: https://github.com/pystardust/ytfzf/blob/dc7b0056e9b84cf786e6e4adda7f91564d1d012f/ytfzf#L921

We're checking for ueberzug regardless of the thumb display method.

Euro20179 commented 2 years ago

We're checking for ueberzug regardless of the thumb display method.

You are exactly correct, and I thought I fixed this but I guess not

Euro20179 commented 2 years ago

mk well i accidently pushed the rewrite branch to master, it was pretty much done though, so it's probably a good thing because i've wanted to merge it for like 3 days now.

(it fixes the issue you were having, and... a lot more to say the least)

adworacz commented 2 years ago

BTW another crossenv (X11/Wayland) option may be to use imv, which supports IPC (with a helper utility called imv-msg).

https://git.sr.ht/~exec64/imv https://git.sr.ht/~exec64/imv/tree/master/item/doc/imv.1.txt#L315-322 https://git.sr.ht/~exec64/imv/tree/master/item/doc/imv-msg.1.txt

I might take a crack at this myself, since we'd get image display from a real image viewer.

Edit: Holy hell I have this working. I'll post a branch soon. If the community is interested, I can open a PR.

My branch with imv support: https://github.com/adworacz/ytfzf/tree/addImvSupport

Edit2: Lulz I wrote this right as the 2.0 rewrite was posted. I'll take a look at updating this eventually.

Euro20179 commented 2 years ago

unless I'm missing something, imv won't display ontop of the terminal, and it'll be hard to place where we want.

Euro20179 commented 2 years ago

Alright I got something going, apply this diff to the newest commit on the master branch to test

diff --git a/ytfzf b/ytfzf
index 55660ef..28bb793 100755
--- a/ytfzf
+++ b/ytfzf
@@ -967,6 +967,12 @@ preview_start () {
            exec 3> "$UEBERZUG_FIFO" # to keep the fifo open
            ;;
        chafa|chafa-16|chafa-tty|catimg|catimg-256|display|w3m) : ;;
+       imv) 
+           #this will select the first video in the list to display
+           first_vid="$(jq -r '.[0].ID|select(.!=null)' < "$ytfzf_video_json_file")"
+           imv "${thumb_dir}/${fist_vid}.jpg" &
+           export imv_pid="$!"
+           ;;
        *)
            "$thumbnail_viewer" "start" "$FZF_PREVIEW_COLUMNS" "$FZF_PREVIEW_LINES" 2>/dev/null ;;
    esac
@@ -978,6 +984,7 @@ preview_stop () {
            exec 3>&- # close file descriptor 3, closing ueberzug
            ;;
        chafa|chafa-16|chafa-tty|catimg|catimg-256|display|w3m) : ;;
+       imv) kill "$imv_pid" ;;
        *)
            "$thumbnail_viewer" "stop" "$FZF_PREVIEW_COLUMNS" "$FZF_PREVIEW_LINES" 2>/dev/null ;;
    esac
@@ -1062,6 +1069,10 @@ preview_display_image () {
            dep_check "display" || die 3 "\nimagemagick is not installed\n"
            killall display
            display "$thumb_dir/${id}.jpg" ;;
+       imv)
+           imv-msg "$imv_pid" open "$thumb_dir/${id}.jpg"
+           imv-msg "$imv_pid" next
+           ;;
        w3m)
            while true; do
                printf "%b\n%s;\n" "0;1;10;130;$((FZF_PREVIEW_COLUMNS*5));$((FZF_PREVIEW_COLUMNS*3));;;;;$thumb_dir/${id}.jpg" 3 | $w3mimgdisplay_path
VarLad commented 2 years ago

@Euro20179 Any idea if something like https://github.com/pystardust/ytfzf/pull/437 can be implemented for Wezterm as well?

Wezterm has an in-built protocol for images as well image

Euro20179 commented 2 years ago

Tested it out, fzf does not play well with wezterm, so it probably won't be added unless I'm missing something.

VarLad commented 2 years ago

@Euro20179 kitty option is extremely buggy

https://user-images.githubusercontent.com/51269425/148566753-e59c33f4-bdcc-4de0-9e8c-a22435d50314.mp4

Euro20179 commented 2 years ago

Yep, I noticed that myself, I honestly have no idea what the problem is, I haven't looked at it long but i opened an issue: #454

Euro20179 commented 2 years ago

Ok, I think fzf gets messed up with kitty so easily because, we are using --transfer-mode stream (which must be done or it breaks) which sends terminal escape codes, but fzf probably also reads the terminal escape codes, because when you say press up that actually sends a terminal escape code. However this still doesn't explain why the image ends up on the wrong side.

timsofteng commented 2 years ago

How can I try thumbnail viewing with imv? Is it in release branch already?

Euro20179 commented 2 years ago

Yes, but you have to update, and since the install location changed on linux, there is an extra command for this update (sudo make uninstall-old). (there will be a 2.1 release once I figure out what I want to do with the kitty viewier cause it's really buggy)

git clone https://github.com/pystardust/ytfzf
cd ytfzf
sudo make uninstall-old
sudo make install doc

sudo make uninstall-old removes /usr/bin/ytfzf, /usr/share/man/man1/ytfzf.1* and /usr/share/man/man5/ytfzf.5*

doc installs the man pages, conf.sh to /usr/local/share/doc/ytfzf and the license to /usr/local/share/licenses/ytfzf

timsofteng commented 2 years ago

I've tried to use imv with last master ytfzf but it's pretty buggy. Sometimes it show wrong thumbnail, sometimes it even shows nothing. And quality of images are very bad (big weird pixels)

Euro20179 commented 2 years ago

And quality of images are very bad (big weird pixels)

This doesn't happen to me, a screehshot would be helpful, it might be because thumbnail_quality is set to default, maybe try ytfzf --thumbnail-quality=maxres to get better thumbnails

I've tried to use imv with last master ytfzf but it's pretty buggy. Sometimes it show wrong thumbnail,

This I can replicate, although inconsistently, a silmilar thing happens with kitty, (although kitty is so damn buggy), but I'm not sure how to fix it yet.

SIDE NOTE: I might change the default thumbnail-quality cause it's so low rn.

Euro20179 commented 2 years ago

Ok, i commited (226e4c0) a possible fix for showing the wrong thumbnail. Try updating again (if you already ran make uninstall-old you don't have to run it again.

timsofteng commented 2 years ago

Works definitely better with last master. One thing is may focus still on terminal and not jump to imv window? I'm using sway. It's slightly annoying to move focus back every time on result response.

Euro20179 commented 2 years ago

One thing is may focus still on terminal and not jump to imv window? I'm using sway. It's slightly annoying to move focus back every time on result response.

This would have to be done by configuring sway.

Euro20179 commented 2 years ago

@VarLad Try out the latest commit, I fixed kitty a week or so ago, but forgot to mention it here, you should try it out.

Euro20179 commented 2 years ago

Swayimg has been pushed to the latest commit in development branch, i'd recommend everyone try it if you're using sway.