summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorEmanuel Guevel <guevel.emanuel@gmail.com>2013-02-03 15:35:17 +0100
committerEmanuel Guevel <guevel.emanuel@gmail.com>2013-02-03 15:35:17 +0100
commit72cfaec1e2d28d87f6de9b0ba76a36fbd62a82ef (patch)
treec790defb0b71e736d355f85b00b036410ce6995a
parentb4eb9dbeea3fb98c8a7b4795aa52b164580d52eb (diff)
downloadranger-72cfaec1e2d28d87f6de9b0ba76a36fbd62a82ef.tar.gz
Image preview: clear images without full redraw
-rw-r--r--ranger/ext/img_display.py14
-rw-r--r--ranger/gui/widgets/pager.py6
2 files changed, 18 insertions, 2 deletions
diff --git a/ranger/ext/img_display.py b/ranger/ext/img_display.py
index 2db7d0e7..b56c7729 100644
--- a/ranger/ext/img_display.py
+++ b/ranger/ext/img_display.py
@@ -78,3 +78,17 @@ def draw(path, start_x, start_y, max_width, max_height):
 			h = height,
 			filename = path)
 	_w3mimgdisplay(cmd)
+
+def clear(start_x, start_y, width, height):
+	"""
+	Clear a part of terminal display.
+	"""
+	fontw, fonth = _get_font_dimensions()
+
+	cmd = "6;{x};{y};{w};{h}\n4;\n3;".format(
+			x = start_x * fontw,
+			y = start_y * fonth,
+			w = width * fontw,
+			h = height * fonth)
+
+	_w3mimgdisplay(cmd)
diff --git a/ranger/gui/widgets/pager.py b/ranger/gui/widgets/pager.py
index 141ed8a9..6ebde5a9 100644
--- a/ranger/gui/widgets/pager.py
+++ b/ranger/gui/widgets/pager.py
@@ -39,11 +39,13 @@ class Pager(Widget):
 
 	def clear_image(self):
 		if self.need_clear_image:
-			self.win.clear()
-			self.win.refresh()
+			img_display.clear(self.x, self.y, self.wid, self.hei)
 			self.need_clear_image = False
 
 	def close(self):
+		if self.image:
+			self.need_clear_image = True
+			self.clear_image()
 		if self.source and self.source_is_stream:
 			self.source.close()