Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

icat preview image method (suggestion/enhancement) #983

Closed
innateessence opened this issue Dec 3, 2017 · 23 comments
Closed

icat preview image method (suggestion/enhancement) #983

innateessence opened this issue Dec 3, 2017 · 23 comments

Comments

@innateessence
Copy link

ISSUE TYPE

  • Improvement/feature request

EXPECTED BEHAVIOR

A picture is worth a thousand words, I've linked to one at the bottom of this post

CURRENT BEHAVIOR

Better image rendering within the terminal

CONTEXT

Better overall Terminal Experience

POSSIBLE SOLUTIONS

Modify the rc.conf setting to use icat

IMAGES / VIDEOS

image
You may also be interested in these links :
kovidgoyal/kitty#33
https://github.com/kovidgoyal/kitty/blob/master/graphics-protocol.asciidoc

@soredake
Copy link

soredake commented Dec 20, 2017

@hut
kitty icat recently gained support of specifying display region and clearing displayed images
kovidgoyal/kitty@0b3a5a7
kovidgoyal/kitty@9456135

kovidgoyal/kitty#228 (comment)

@toonn
Copy link
Member

toonn commented Feb 8, 2018

@JackofSpades707 @soredake Does icat work on terminals other than kitty, how about inside of tmux? If it does then implementing kitty's graphics protocol for ranger might be worth the effort. So far we've avoided doing image previews with anything more than a program called from scope.sh because there just hasn't been a universal method that just works. We don't want to get stuck maintaining some custom hack with similar failings to w3mimgdisplay.

@mark-dawn
Copy link
Contributor

mark-dawn commented Feb 13, 2018

I have spent some days implementing this for myself and I got it to work with reasonable performance.
I am using directly kitty's image protocol instead of kitty's icat, which misbehaves with some sizes.
kittyranger
I think there are two main problems with this system: first, I used PIL/pillow to resize and convert images, which is not a dependency right now (w3m is external and other terminals accept different filetypes). However it doesn't seem unreasonable to ask for an image library if the user is interested in images, and I was planning of implementing a fallback to ImageMagick too.
Second, there is a nasty bug when scrolling very fast in a directory full of pics, where kitty's response fails to be caught and leaks into stdin, where the leading \033 corrupts the terminal quite badly. I am unsure if I can fix this on my end, but it might be possible to ask kovidgoyal to implement a command to suppress responses in the protocol.
Anyway I'll try forking/uploading the code somehow tomorrow, I am too tired for today to figure how to do it properly

@mark-dawn
Copy link
Contributor

FYI, I have a branch in my repository with what I currently have, if someone wants to check it out. Technically speaking everything is ready for a merge, I just need to finish filling up the pull request; but I'd like to check kitty's codebase to see if I could implement the fix and discuss it with kovidgoyal, and if it can be resolved quickly I would wait before merging it with the master branch. After all it's not nice to have the manpage mentioning that a feature has a bug.

@mark-dawn mark-dawn mentioned this issue Feb 16, 2018
9 tasks
@toonn
Copy link
Member

toonn commented Feb 16, 2018

Would appreciate kitty users to test that PR.

@cosmojg
Copy link

cosmojg commented Sep 1, 2018

@mark-dawn @toonn Thank you so much for your work on Ranger and this issue!

I'm running the latest release of Ranger (1.9.1) on Kitty (0.12.0) on XWayland (1.20.1) on Sway (0.15.2) on Arch Linux. I also have python-pillow (5.2.0) installed. With both "set preview_images true" and "set preview_images_method kitty" in my rc.conf, nothing is displayed when previewing images (tested with PNGs).

Kitty's icat works just fine, but Ranger's image previews don't. Am I doing something wrong? Do I need to set additional config options?

@toonn
Copy link
Member

toonn commented Sep 2, 2018

@cosmojg, not doing anything wrong except this is gonna be in the next release. On arch you can already get it by installing ranger-git from the AUR, that installs the head of the master branch. We keep master in working condition but breakages do creep in occasionally (mostly when I push to master x )).

@cosmojg
Copy link

cosmojg commented Sep 2, 2018

@toonn Ahh, thanks a million for the prompt reply! Keep up the awesome work. :)

@nicoulaj
Copy link

nicoulaj commented Sep 18, 2018

I just tested it with kitty 0.12.1 and ranger master @ g8e9451e6, it mostly works but I could see a few bugs:

  • the images are offset (see screenshot)
  • sometimes the image blinks and disappears
  • moving the focus to another window makes the image disappear
  • resizing the window makes the image disappear

screenshot_18-09-18_21 32 31

@mark-dawn
Copy link
Contributor

@nicoulaj Did you set the image preview method to kitty? The issues you describe seems the same when w3m is used with kitty. You can set the preview type temporarily without changing your config using the command :set preview_images_method kitty

@nicoulaj
Copy link

@mark-dawn indeed, it works perfectly now!

@mark-dawn
Copy link
Contributor

Also @nicoulaj, you should append kitty to your $TERM environment variable. Sadly I haven't found a better way to test if your actual terminal emulator is kitty except asking manual intent from the user. It's a bit annoying but without it that ranger freezes, and I prefer not to lock people in a tty when launching ranger during some emergency situation.

@nicoulaj
Copy link

It's already this way, kitty sets it to xterm-kitty. But my ranger config explicitly contained set preview_images_method w3m, so I guess it's fine in this case.

@toonn
Copy link
Member

toonn commented Oct 21, 2018

Closing because the feature has been released.

@toonn toonn closed this as completed Oct 21, 2018
@dufferzafar
Copy link
Contributor

dufferzafar commented Feb 24, 2019

@toonn Which ranger version has this? I'm running ranger 1.9.2 and can't get image previews to work.

I do have set preview_images_method kitty in rc.conf

@dufferzafar
Copy link
Contributor

This was because I was using a very old scope.sh file. I had some of my customizations in there. I copied the scope file from GitHub and things worked!

@dufferzafar
Copy link
Contributor

dufferzafar commented Feb 24, 2019

I came back to my ranger config and I'm noticing something weird. Image previews stop working when I set preview method to kitty, but otherwise work fine!

Preview doesn't work when I have this in config (tested on both Kitty & ranger):

set preview_images true
set preview_images_method kitty

But work fine, when I just keep it like:

set preview_images true
# set preview_images_method kitty

BTW, how is Konsole able to show image previews?

@toonn
Copy link
Member

toonn commented Feb 24, 2019

Do you have PIL (pillow) installed for your python? That's a requirement for kitty previews. Konsole might work with w3m and would probably work with ueberzug.

@dufferzafar
Copy link
Contributor

@toonn Yes, I do have pillow installed. Just ran pacman -S python-pillow and conirmed.

@toonn
Copy link
Member

toonn commented Feb 24, 2019

I'm out of ideas. You're not running inside tmux, are you? The kitty image preview method only works if "kitty" is a substring of TERM.

@dufferzafar
Copy link
Contributor

This was it. I was manually setting TERM to be xterm-256color in my .zshrc

Fixed it. Thanks.

@dufferzafar
Copy link
Contributor

dufferzafar commented Mar 1, 2019

@toonn is there any way i can get kitty preview method, while still having my TERM set to xterm-256color?

using xterm-kitty as my term breaks a lot of the other tools, and instead of trying to fix all of them, i'm thinking maybe i could get ranger working?

P.S: I found that you've had similar problems with kitty as well 😆

@toonn
Copy link
Member

toonn commented Mar 2, 2019

@dufferzafar, the only working solution for now is TERM=xterm-kitty, whenever you ssh use env TERM=xterm-256color ssh instead, then if you want previews on the remote ssh side too use env TERM=xterm-kitty ranger. You can probably alias these or put them in scripts to reduce typing, or use fish its history completion makes this pretty painless.

I know this isn't ideal but the kitty image preview method needs to be restricted to kitty terminals otherwise you'd get a corrupted ranger and this is the only way to detect what terminal you're running in. If you find a better solution I'd love to know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants