patat icon indicating copy to clipboard operation
patat copied to clipboard

w3mimgdisplay command 6 (clear image) is not sent

Open sersorrel opened this issue 5 years ago • 10 comments

I'm running into an issue that patat doesn't tell w3mimgdisplay when it should remove images from the screen – it would be ideal if patat could emit a w3mimgdisplay command (apparently it should look something like 6;x;y;w;h) when the current slide is an image and the slide is changed.

(the reason I noticed this is because I'm writing a pair of wrapper scripts for ueberzug that means it can be used as a drop-in replacement for w3mimgdisplay, but when used in patat my script doesn't have any way to know when to erase the image)

sersorrel avatar Aug 06 '19 17:08 sersorrel

I was thinking about this for a bit and it shouldn't be too hard, although it does require significantly changing the Images API.

Basically, right here I'd need to update the type be:

hDrawImage :: FilePath -> IO (IO ())

where the method not only draws the image, but also returns a cleanup function. We then collect those cleanup methods and run them after we change the slide.

@anowlcalledjosh Is this something you are interested in working on, or should I give it a stab?

jaspervdj avatar Aug 11 '19 10:08 jaspervdj

I've created #69 where I define such a cleanup action; I don't actually implement the cleanup action yet though.

jaspervdj avatar Aug 13 '19 09:08 jaspervdj

Awesome! I'm unlikely to be able to help, sorry – I've got a lot on my plate at the moment and I barely know Haskell, but maybe eventually I'll get around to it.

sersorrel avatar Aug 14 '19 18:08 sersorrel

@anowlcalledjosh My branch at #69 now calls w3mimgdisplay again to clear the image. I'll see if I can try it out with ueberzug at some point -- the fact that it doesn't work in tmux is also mildly annoying for me personally.

jaspervdj avatar Aug 20 '19 09:08 jaspervdj

Nice!

My wrapper script is now available on GitHub, if you want to test with that: https://github.com/anowlcalledjosh/uberw3m

You should be able to use something like this in a presentation header:

patat:
  images:
    backend: w3m
    path: /path/to/uberw3m

then use a command line like uberwrap patat /path/to/presentation.

sersorrel avatar Aug 21 '19 15:08 sersorrel

Right, I had time to install Stack and test your PR; I made some changes to my wrapper script, and now it works perfectly for me. I've not tested in tmux, though.

sersorrel avatar Sep 01 '19 11:09 sersorrel

Great! In that case I'll merge it in.

jaspervdj avatar Sep 10 '19 05:09 jaspervdj

FWIW, this doesn't seem to erase the image in konsole ; has anyone else noticed this?

at least the image can be displayed though!

-- edit:

i guess it's because the command

echo -e "6;0;0;$width;$height"|/usr/lib/w3m/w3mimgdisplay

doesn't work

(bafflingly, i think i did work briefly, but i certainly can't reproduce it working now)

silky avatar Jan 10 '21 20:01 silky

for any poor desperate souls investigating this, i have some notes from the totally inappropriate amount of time i spent looking into it:

  1. on konsole, the clear doesn't work. it does clear if another konsole action forces a redraw; such as: 1) return is pressed after an image display; forcing the terminal to redraw; 2) the terminal is resized, 3) zoom in or out ( this is why in my comment above i was a bit confused about wither it was clearing or not )

  2. i got totally desparate and finally figured out that i can just return, as the cleanup command, a blank draw image command. i just redraw an image of the same size as the original, in the colour of my terminal background. it might work as a transparent image; i haven't bothered to check. it has to be the same size.

  3. probably one could build this into the library; but it feels too hacky to do that.

-- edit: ps, thanks for such a neat library @jaspervdj - it was really easy to hack around in this codebase!

silky avatar Jan 14 '21 09:01 silky

I don't know if this helps (since this seems a bit old) but if you send the command for clear, you need to sync and sync the draw.

so echo -e "6;0;0;$width;$height;\n4;\n3; | /usr/lib/w3m/w3mimgdisplay"

apparently the \n4; is redundant, but yeah.

vantreeseba avatar Apr 28 '21 20:04 vantreeseba