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

support ueberzug image displayer #1284

Merged
merged 21 commits into from Nov 7, 2018
Merged

support ueberzug image displayer #1284

merged 21 commits into from Nov 7, 2018

Conversation

seebye
Copy link
Contributor

@seebye seebye commented Aug 25, 2018

Überzug is a command line util which allows to draw images on terminals by using child windows.
It has some advantages over w3mimgdisplay, e.g.:

  • it has no memory leak (/ unlimited cache) (related: w3mimgdisplay consumes a lot of memory #451)
  • no race conditions as a new window is used to display images
  • tmux support
  • faster as the current w3mimgdisplay implementation as the communication goes only in one direction

More: https://github.com/seebye/ueberzug#%C3%9Cberzug

ISSUE TYPE

  • Improvement/feature implementation

RUNTIME ENVIRONMENT

  • Operating system and version: Debian Buster
  • Terminal emulator and version: xterm / alacritty
  • Python version: 2.7.15 (default, Jul 28 2018, 11:29:29) [GCC 8.1.0]
  • Ranger version/commit: ranger-master v1.9.1-173-gd37e4b2c
  • Locale: None.None

CHECKLIST

  • The CONTRIBUTING document has been read [REQUIRED]
  • All changes follow the code style [REQUIRED]
  • All new and existing tests pass [REQUIRED]
  • Changes require config files to be updated
    • Config files have been updated
  • Changes require documentation to be updated
    • Documentation has been updated
  • Changes require tests to be updated
    • Tests have been updated

DESCRIPTION

MOTIVATION AND CONTEXT

w3mimgdisplay does not work with alacritty, tmux is also not supported

TESTING

IMAGES / VIDEOS

@toonn
Copy link
Member

toonn commented Aug 25, 2018

Looks pretty cool for a first contribution. Does überzug only support python 3.x? That's somewhat unfortunate. If it's not could you run it with the same python that's running ranger, or just the python on the PATH?

@seebye
Copy link
Contributor Author

seebye commented Aug 25, 2018

Does überzug only support python 3.x? That's somewhat unfortunate. If it's not could you run it with the same python that's running ranger, or just the python on the PATH?

I used python3 features like asyncio to avoid dealing with thread safety, so it won't run with python2.

@toonn
Copy link
Member

toonn commented Aug 25, 2018

Is the threading module an option, afaik that's been backported?

@jaelpark
Copy link

Somehow it always draws the picture to the upper left corner, regardless of the given x,y parameters. Happens both in ranger and with this simpler demonstration (using termite):

from subprocess import Popen,PIPE

p = Popen(['python3','-m','ueberzug','layer'],stdin=PIPE,universal_newlines=True);
p.stdin.write('{"action":"add","x":500,"y":200,"identifier":"preview","path":"image.png"}\n');
p.stdin.flush();
input("...");

@seebye
Copy link
Contributor Author

seebye commented Aug 26, 2018

@jaelpark I think this belongs to https://github.com/seebye/ueberzug/issues.
Termite is not in the debian testing repository, but I guess that termite does not support extracting the terminal size in pixels via termios.TIOCGWINSZ.
Therefore the font size can't be determied.
Another way to optain the terminal size isn't implemented currently, but it's easily fixable by using python-Xlib.
You can test whether your terminal emulator supports extracting the terminal size in pixels by executing the following code:

#!/usr/bin/env python3
import sys
import struct
import fcntl
import termios

farg = struct.pack("HHHH", 0, 0, 0, 0)
fd_stdout = sys.stdout.fileno()
fretint = fcntl.ioctl(fd_stdout, termios.TIOCGWINSZ, farg)
rows, cols, xpixels, ypixels = struct.unpack("HHHH", fretint)
print('rows', rows, 'cols', cols, 'xpixels', xpixels, 'ypixels', ypixels)

@toonn Honestly, I don't really wan't to support python2.
Python3 should be installed on the most linux systems anyways and
if it's not it shouldn't be a problem as people were already willing to install an entire browser to display images with ranger
.
So it would just increase the effort to maintain ueberzug in my opinion.

Edit: You're right didn't saw the additonal package in debians repository.

@toonn
Copy link
Member

toonn commented Aug 26, 2018

Entire browser? w3m-img doesn't depend on w3m.

@jaelpark
Copy link

@seebye I created a quick fix and opened a PR, see if it's something you want to merge. At least the problem with termite is fixed. This could be configurable, whether to get the dimensions with Xlib or using the original method.

@toonn
Copy link
Member

toonn commented Aug 27, 2018

This doesn't work for me. ueberzug doesn't work on the command line either. Using a virtualenv with python 3.7 and the terminology terminal emulator.
ueberzug_corrupted_output

@seebye
Copy link
Contributor Author

seebye commented Aug 27, 2018

In the newest version there are some changes for python3.7.
(The preview worked for me after these modifications in terminology in a python3.7 virtualenv)
However your error message looks like the window lacks the _NET_WM_PID property?
Ueberzug can't work without it as it uses the pid to determine the window id.

@toonn
Copy link
Member

toonn commented Aug 27, 2018

I have no idea why the property would be missing. No funny business on my end afaik.

@seebye
Copy link
Contributor Author

seebye commented Aug 27, 2018

I think it should work with version 6 if it's not terminology itself which lacks the property.

Copy link
Member

@toonn toonn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works with v6 yes. It seems to work quite nicely. The quality is a little less than with native terminology previews but I'm not sure that can be achieved in a method compatible with multiple terminals. It's mostly noticeable with text:
comparison-terminology-ueberzug-ranger-preview

I did notice a problem though. I was testing the method and wanted to compare to the terminology method on that screenshot of text because I thought I noticed a quality difference. The ueberzug window didn't close, it just stayed open overlapping that part of ranger. Switching back to the ueberzug method didn't help either, the new ueberzug windows were drawn under the one that stuck. I really think this should be fixed before we include the method in the release.

@seebye
Copy link
Contributor Author

seebye commented Aug 28, 2018

I really think this should be fixed before we include the method in the release.

On the latest version of ranger the preview image also stays if you switch from terminology to e.g. w3m.
So I also implemented the quit method for the preview methods which still missed it.

Copy link
Member

@toonn toonn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous problem was fixed, so we're making progress but I ran into another problem when ueberzug tries to preview an svg I get this error:
ueberzug-svg-error

It's probably not possible to have ueberzug preview svg's but it shouldn't mess up the interface. Either log the mesasge with self.fm.notify or suppress it entirely.

@toonn
Copy link
Member

toonn commented Aug 28, 2018

For me the image never stayed when I switched from terminology to another method. If you did have that problem then that sounds like a good fix though.

@seebye
Copy link
Contributor Author

seebye commented Aug 28, 2018

I enabled the redirection of stderr to /dev/null.
So errors should be suppressed now.

Copy link
Member

@toonn toonn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might make troubleshooting a little harder when people do expect a preview but it's an ok fix imo.

And I checked again and indeed changing away from the terminology method left an image too.

@toonn
Copy link
Member

toonn commented Aug 28, 2018

This is an awesome first contribution. Thanks for the work. I'm gonna allow for a little time for another team member to check out the changes but this is probably going in the next release. 👍

@toonn toonn added the next-release Wants to be included in the next release label Aug 28, 2018
@vifon
Copy link
Member

vifon commented Sep 5, 2018

Looks really interesting! Sadly I cannot get it to work. I'm using set preview_images_method ueberzug and I'm running ranger with Python 3. Anything else I need to know? Can a tiling window manager (XMonad) be the cause?

@vifon
Copy link
Member

vifon commented Sep 5, 2018

It also needs documentation in the rc.conf comment and a new allowed value here.

@toonn
Copy link
Member

toonn commented Sep 6, 2018

@vifon, you did actually install ueberzug first, right? And good catch about the documentation and the ALLOWED_VALUES, although that seems to be a misnomer because I was able to test and afair tab complete the ueberzug method without any problem : )

@sooriravindra
Copy link

sooriravindra commented Jul 26, 2019

I am using suckless terminal on Arch, ueberzug sample bash script displays image using the terminal. However ranger fails to display the image in preview.

Installed both using "sudo pip install ranger ueberzug"

ranger version: ranger 1.9.2
Python version: 3.7.3 (default, Jun 24 2019, 04:54:02) [GCC 9.1.0]

@toonn
Copy link
Member

toonn commented Jul 26, 2019

You need the master version of ranger this is not in the release.

@sooriravindra
Copy link

I tried with the master version from github, same effect.

I also tried ranger-git in AUR, no luck :(

@toonn
Copy link
Member

toonn commented Jul 26, 2019

You did set preview_images_method ueberzug, right? Also, you're sure you were running the master version and not the installed one?

@sooriravindra
Copy link

Yes, my ~/.config/ranger/rc.conf has

set preview_images true
set preview_images_method ueberzug

And yeah I removed the earlier ranger and cloned master and did a make install. The preview window is blank.

@toonn
Copy link
Member

toonn commented Jul 27, 2019

@seebye, could you chime in? I have no idea why it'd work in the terminal but not ranger.

@ivomac
Copy link

ivomac commented Jul 27, 2019

@sooriravindra, I have the same setup as you, st, ranger-git from AUR and ueberzug from pip. I can see preview images but only if they fit inside the preview pane. It seems like the images are not resized to fit.

Can you check if you can preview a low enough resolution image?

Edit: I checked with urxvt and kitty and the same happens.

@sooriravindra
Copy link

@ivomac that seems like it, I was trying to preview images that don't fit in the preview window. Now when I tried a smaller image, the preview works.

The issue seems to be with resizing.

@toonn
Copy link
Member

toonn commented Jul 27, 2019

Hmm, maybe try uninstalling pillow-simd and installing pillow instead?

@ivomac
Copy link

ivomac commented Jul 27, 2019

I tried uninstalling pillow-simd and installing pillow but now ueberzug complains it is missing pillow-simd. Is there a way to tell it to use pillow?

This doesn't seem to be an issue with ranger. Opening an image with ueberzug on the terminal and forcing a resize using max_width and max_height gives a segmentation fault.

Used bash script:

#!/usr/bin/bash

source "`ueberzug library`"

ImageLayer 0< <(
	ImageLayer::add [identifier]="example" [max_width]="200"
[max_height]="200" [x]="0" [y]="0" [path]="$1"
	read
	ImageLayer::remove [identifier]="example"
)

images smaller than 200x200 are displayed correctly, larger ones give the error

/usr/lib/python3.7/site-packages/ueberzug/lib/lib.sh:
line 41: 11648 Segmentation fault (core dumped)
ueberzug layer -p bash "$@"

@seebye
Copy link
Contributor Author

seebye commented Jul 27, 2019

I tried uninstalling pillow-simd and installing pillow but now ueberzug complains it is missing pillow-simd. Is there a way to tell it to use pillow?

Try to install ueberzug by using pip it shouldn't complain then.
(/ pillow and pillow-simd should be exchangeable if you install it with pip)
(Also someone made the effort to package ueberzug with pillow instead of pillow-simd.
https://aur.archlinux.org/packages/python-ueberzug-nosimd-git/ )

@ivomac
Copy link

ivomac commented Jul 27, 2019

python-ueberzug-nosimd-git worked perfectly. Thank you!

@toonn
Copy link
Member

toonn commented Jul 28, 2019

@seebye, is there any chance you'd consider making pillow the default dependency? We're gonna get a bunch of issue reports about this when ueberzug makes it into the next release.

It'd be far easier if it just always works and we mention you might be able to get a speed improvement with pillow-simd.

@seebye
Copy link
Contributor Author

seebye commented Jul 29, 2019

@toonn Sure, I guess. I'm busy right now, so I'm likely doing it not until next week.

@sooriravindra
Copy link

sooriravindra commented Jul 30, 2019

@seebye python-ueberzug-nosimd-git works great. However the pip install complains if pillow-simd is not installed ( I had pillow installed).

Thank you!

@edjorqs
Copy link

edjorqs commented Aug 2, 2019

Hi, when I try to preview an image in ranger, at the bottom of the terminal appears
[Errno 13] Permission denied 'ueberzug'
Any hint? I have searched everywhere but I don't know what could I do.
I use gentoo, and if I do source "`ueberzug library`" before running ranger, nothing appears at the preview.

@toonn
Copy link
Member

toonn commented Aug 2, 2019

What do you mean by source? Ueberzug is definitely not designed to be sourced by a shell. How did you install ueberzug?

@edjorqs
Copy link

edjorqs commented Aug 2, 2019

I installed following the instructions from ueberzug's github, and by source, I mean this in bash:
source "`ueberzug library`"

@toonn
Copy link
Member

toonn commented Aug 2, 2019

Does that at least print the path to the library?

@edjorqs
Copy link

edjorqs commented Aug 2, 2019

Hey, suddenly, now it shows images whose resolution is smaller than the right side of the terminal, check this out:
image
But nothing happens with a bigger image:
image
And all I have as config is the default config with ueberzug instead of w3m

@sooriravindra
Copy link

@eduardoejorqueras Have you tried making Ueberzug to use pillow instead of pillow-simd?

@edjorqs
Copy link

edjorqs commented Aug 2, 2019

@sooriravindra thank you, I just uninstalled pillow-simd and works very nice 😄 , here the evidence:
image

@remlap
Copy link

remlap commented Aug 3, 2019

Hi I recently did a fresh install and now ueberzug fails to line up properly.

Screenshot at 2019-08-03 12-24-08

@seebye
Copy link
Contributor Author

seebye commented Aug 3, 2019

@remlap The font size & padding is guessed. See: #1284 (comment)
Your terminal doesn't fit the assumptions.
You need to remove the menu bar & the scrollbar.

@remlap
Copy link

remlap commented Aug 3, 2019

It would work previously fine.

@seebye
Copy link
Contributor Author

seebye commented Aug 16, 2019

@toonn I released a new version (on pypi/pip) which uses pillow instead of pillow-simd.

@toonn
Copy link
Member

toonn commented Aug 16, 2019

@seebye, thank you a lot for this. I understand a more performant default is attractive so I would've totally understood if you said no. This'll probably save us a ton of issue reports ❤️

@gxt-kt
Copy link

gxt-kt commented Jan 10, 2023

Hi, when I try to preview an image in ranger, at the bottom of the terminal appears [Errno 13] Permission denied 'ueberzug' Any hint? I have searched everywhere but I don't know what could I do. I use gentoo, and if I do source "ueberzug library" before running ranger, nothing appears at the preview.

Can you share that how do you resolve the problem? I meet the same problem that show [Errno 13] Permission denied 'ueberzug in ranger. I see the ueberzug website has stoped maintained and no issues.

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

Successfully merging this pull request may close these issues.

None yet