summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorShotaro Fujimoto <fuji101ijuf@gmail.com>2016-10-15 17:29:17 +0900
committerWojciech Siewierski <wojciech.siewierski@onet.pl>2017-01-29 23:13:54 +0100
commit1fccef33f31d931757cb2d49674cfbb40f62954d (patch)
tree66a3e67f7494d68cec5efa9aca9ba33c1690f4a0
parentad51cca4893b214d9428248572f7d0b518c9a285 (diff)
downloadranger-1fccef33f31d931757cb2d49674cfbb40f62954d.tar.gz
Fix urxvt based image displayer when running on tmux
-rw-r--r--ranger/ext/img_display.py25
1 files changed, 19 insertions, 6 deletions
diff --git a/ranger/ext/img_display.py b/ranger/ext/img_display.py
index b4deaa39..0fb4ffa7 100644
--- a/ranger/ext/img_display.py
+++ b/ranger/ext/img_display.py
@@ -363,21 +363,34 @@ class URXVTImageDisplayer(ImageDisplayer, FileManagerAware):
         pct_x, pct_y = self._get_offsets()
         pct_width, pct_height = self._get_sizes()
 
+        display_protocol = "\033"
+        close_protocol = "\a"
+        if "screen" in os.environ['TERM']:
+            display_protocol += "Ptmux;\033\033"
+            close_protocol += "\033\\"
         sys.stdout.write(
-            "\033]20;{path};{pct_width}x{pct_height}+{pct_x}+{pct_y}:op=keep-aspect\a".format(
-                path=path, pct_width=pct_width, pct_height=pct_height,
-                pct_x=pct_x, pct_y=pct_y,
+            display_protocol
+            + "]20;" + path + ";"
+            + "{pct_width}x{pct_height}+{pct_x}+{pct_y}:op=keep-aspect".format(
+                pct_width=pct_width, pct_height=pct_height, pct_x=pct_x, pct_y=pct_y
             )
+            + close_protocol
         )
         sys.stdout.flush()
 
     def clear(self, start_x, start_y, width, height):
-        sys.stdout.write("\033]20;;100x100+1000+1000\a")
+        display_protocol = "\033"
+        close_protocol = "\a"
+        if "screen" in os.environ['TERM']:
+            display_protocol += "Ptmux;\033\033"
+            close_protocol += "\033\\"
+        sys.stdout.write(display_protocol
+                         + "]20;;100x100+1000+1000"
+                         + close_protocol)
         sys.stdout.flush()
 
     def quit(self):
-        sys.stdout.write("\033]20;;100x100+1000+1000\a")
-        sys.stdout.flush()
+        self.clear(0, 0, 0, 0)  # dummy assignments
 
 
 class URXVTImageFSDisplayer(URXVTImageDisplayer):