Skip to content

Commit 83a7264

Browse files
author
=
committed
use IMV to preview images, it works on DWL wayland
1 parent 391f061 commit 83a7264

1 file changed

Lines changed: 38 additions & 1 deletion

File tree

ranger/ext/img_display.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
import warnings
2323
import json
2424
import threading
25-
from subprocess import Popen, PIPE
25+
from subprocess import Popen, PIPE, run
26+
import time
2627
from collections import defaultdict
2728

2829
import termios
@@ -779,3 +780,39 @@ def quit(self):
779780
self.process.communicate()
780781
finally:
781782
timer_kill.cancel()
783+
784+
785+
@register_image_displayer("imv")
786+
class IMVImageDisplayer(ImageDisplayer):
787+
"""Implementation of ImageDisplayer using imv
788+
add following line into rc.conf to make it work
789+
set preview_images_method imv
790+
"""
791+
is_initialized = False
792+
793+
def __init__(self):
794+
self.process = None
795+
796+
def initialize(self):
797+
""" start imv """
798+
if (self.is_initialized and self.process.poll() is None
799+
and not self.process.stdin.closed):
800+
return
801+
802+
self.process = Popen(['imv'], cwd=self.working_dir, stdin=PIPE, universal_newlines=True)
803+
self.is_initialized = True
804+
sleep(5)
805+
806+
def draw(self, path, start_x, start_y, width, height):
807+
self.initialize()
808+
run(['imv-msg',str(self.process.pid),'close'])
809+
run(['imv-msg',str(self.process.pid),'open',path])
810+
811+
812+
def clear(self, start_x, start_y, width, height):
813+
self.initialize()
814+
run(['imv-msg',str(self.process.pid),'close'])
815+
816+
def quit(self):
817+
if self.is_initialized and self.process.poll() is None:
818+
self.process.terminate()

0 commit comments

Comments
 (0)