Solvedalacritty w3mimgdisplay not working correctly

Which operating system does the issue occur on?
Void Linux

If on linux, are you using X11 or Wayland?

As the title implies image previews for ranger are not behaving correctly for me. Instead of displaying the image properly the preview pane simply stays empty. I can confirm that using the same methods in the urxvt-terminal leads to the images beeing displayed properly. The issue persist whether or not I am using a composite manager (compton).

Configurations used:
set preview_images true
set preview_images_method w3m

set preview_images true
set use_preview_script true
set preview_script /usr/share/doc/ranger/config/
Taken from Issue #107

34 Answers

✔️Accepted Answer

I guess that the only non-hacky way to make this working is to incorporate image preview functionality into the terminal itself (like Kitty or Terminology do).
Writing this mostly to subscribe on a thread :)

Other Answers:

A workaround is available here, by replacing w3m by ueberzug. I just tested it and it works for me. The dotfiles are available as well, and here is the commit Alkeryn made : Alkeryn/dotfiles@c4f7072

thestinger/termite#501 (comment)

@FichteFoll I had the same problem, and managed to fix it. Turns out that w3mimgdisplay directly draws on the X11 window of the terminal. If the terminal happens to redraw after that, the image is lost. I believe there is a race condition, Alacritty may or may not swap buffers (or repaint for some other reason) after the image has been drawn. I don't think this is a bug in Alacritty, just that w3mimgdisplay is a huge hack.

Edit: I feel a need to say that the hack was probably born out of necessity and appreciate the hard work of its author, despite my harsh words.

Edit 2: The script still seems to fail when the throbber is shown in the top right corner of ranger.

I wrote a Bash script that delays image drawing requests by 100ms, which was enough to make the preview stable:

  while read line; do 
    if [[ $firstchar = '0' ]]; then
      # Showing a picture - pause for a moment, in case the terminal has a pending redraw.
      sleep 0.1
    echo "$line"
} | /usr/lib/w3m/w3mimgdisplay

You can make Ranger use that by exporting W3MIMGDISPLAY_PATH to point to the script. Note that the script references w3mimgdisplay by its absolute path, you might need to change it depending on your distro.

Oh and moreover, I have found that calling neofetch --w3m /path/to/image (neofetch is a sysinfo-script that can display pictures in the terminal using the w3m backend) also does not produce the correct result. So the issue should most definitely not be related to ranger.

ranger's preview works for me most of the time, but occasionally the image only shows up for a brief period of time and then disappears. This seems to be related to w3m moreso than ranger, but I don't know anything about the internals

More Issues: