summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorjohn <john.luke.greco@gmail.com>2017-10-22 13:44:09 -0700
committerjohn <john.luke.greco@gmail.com>2017-10-22 14:21:17 -0700
commit538986719e81987d7a08aa083757f345fa9acaee (patch)
tree56309370d5c2bc64b17b4aeb2dbcd4fbea0fb847
parent5375eb89664764a3c17444367d0f561733ca3422 (diff)
downloadranger-538986719e81987d7a08aa083757f345fa9acaee.tar.gz
Add config opts for iTerm2 font size (for preview)
Add two config options "iterm2_font_width" and "iterm2_font_height" that
override the default values of _minimum_font_width and
_minimum_font_height in ITerm2ImageDisplayer.  The default values may
cause preview distortion if set too high (Issue #499) or result in the
preview being smaller than necessary if set too low.
-rw-r--r--doc/ranger.16
-rw-r--r--doc/ranger.pod4
-rw-r--r--doc/rifle.12
-rw-r--r--ranger/config/rc.conf8
-rw-r--r--ranger/container/settings.py2
-rw-r--r--ranger/ext/img_display.py6
6 files changed, 22 insertions, 6 deletions
diff --git a/doc/ranger.1 b/doc/ranger.1
index f96c7f20..cd00cd95 100644
--- a/doc/ranger.1
+++ b/doc/ranger.1
@@ -129,7 +129,7 @@
 .\" ========================================================================
 .\"
 .IX Title "RANGER 1"
-.TH RANGER 1 "ranger-1.9.0b5" "10/01/2017" "ranger manual"
+.TH RANGER 1 "ranger-1.9.0b5" "10/22/2017" "ranger manual"
 .\" For nroff, turn off justification.  Always turn off hyphenation; it makes
 .\" way too many mistakes in technical documents.
 .if n .ad l
@@ -296,6 +296,10 @@ ssh.
 .PP
 To enable this feature, set the option \f(CW\*(C`preview_images_method\*(C'\fR to iterm2.
 .PP
+This feature relies on the dimensions of the terminal's font.  By default, a
+width of 8 and height of 11 are used.  To use other values, set the options
+\&\f(CW\*(C`iterm2_font_width\*(C'\fR and \f(CW\*(C`iterm2_font_height\*(C'\fR to the desired values.
+.PP
 \fIurxvt\fR
 .IX Subsection "urxvt"
 .PP
diff --git a/doc/ranger.pod b/doc/ranger.pod
index 310ab1fd..43926f46 100644
--- a/doc/ranger.pod
+++ b/doc/ranger.pod
@@ -201,6 +201,10 @@ ssh.
 
 To enable this feature, set the option C<preview_images_method> to iterm2.
 
+This feature relies on the dimensions of the terminal's font.  By default, a
+width of 8 and height of 11 are used.  To use other values, set the options
+C<iterm2_font_width> and C<iterm2_font_height> to the desired values.
+
 =head3 urxvt
 
 This only works in urxvt compiled with pixbuf support. Does not work over ssh.
diff --git a/doc/rifle.1 b/doc/rifle.1
index 4d501df0..9d9e08f9 100644
--- a/doc/rifle.1
+++ b/doc/rifle.1
@@ -129,7 +129,7 @@
 .\" ========================================================================
 .\"
 .IX Title "RIFLE 1"
-.TH RIFLE 1 "rifle-1.9.0b5" "10/01/2017" "rifle manual"
+.TH RIFLE 1 "rifle-1.9.0b5" "10/22/2017" "rifle manual"
 .\" For nroff, turn off justification.  Always turn off hyphenation; it makes
 .\" way too many mistakes in technical documents.
 .if n .ad l
diff --git a/ranger/config/rc.conf b/ranger/config/rc.conf
index 9459a3d3..a306594a 100644
--- a/ranger/config/rc.conf
+++ b/ranger/config/rc.conf
@@ -80,6 +80,10 @@ set preview_images false
 #   (http://iterm2.com/images.html). This requires using iTerm2 compiled
 #   with image preview support.
 #
+#   This feature relies on the dimensions of the terminal's font.  By default, a
+#   width of 8 and height of 11 are used.  To use other values, set the options
+#   iterm2_font_width and iterm2_font_height to the desired values.
+#
 # * urxvt:
 #   Preview images in full color using urxvt image backgrounds. This
 #   requires using urxvt compiled with pixbuf support.
@@ -89,6 +93,10 @@ set preview_images false
 #   whole terminal window.
 set preview_images_method w3m
 
+# Default iTerm2 font size (see: preview_images_method: iterm2)
+set iterm2_font_width 8
+set iterm2_font_height 11
+
 # Use a unicode "..." character to mark cut-off filenames?
 set unicode_ellipsis false
 
diff --git a/ranger/container/settings.py b/ranger/container/settings.py
index bb902f9d..2f38a2b6 100644
--- a/ranger/container/settings.py
+++ b/ranger/container/settings.py
@@ -47,6 +47,8 @@ ALLOWED_SETTINGS = {
     'hidden_filter': str,
     'hostname_in_titlebar': bool,
     'idle_delay': int,
+    'iterm2_font_width': int,
+    'iterm2_font_height': int,
     'line_numbers': str,
     'max_console_history_size': (int, type(None)),
     'max_history_size': (int, type(None)),
diff --git a/ranger/ext/img_display.py b/ranger/ext/img_display.py
index c88b5a77..5bc1fbe5 100644
--- a/ranger/ext/img_display.py
+++ b/ranger/ext/img_display.py
@@ -205,8 +205,6 @@ class ITerm2ImageDisplayer(ImageDisplayer, FileManagerAware):
 
     Ranger must be running in iTerm2 for this to work.
     """
-    _minimum_font_width = 8
-    _minimum_font_height = 11
 
     def draw(self, path, start_x, start_y, width, height):
         curses.putp(curses.tigetstr("sc"))
@@ -246,8 +244,8 @@ class ITerm2ImageDisplayer(ImageDisplayer, FileManagerAware):
         return text
 
     def _fit_width(self, width, height, max_cols, max_rows):
-        max_width = self._minimum_font_width * max_cols
-        max_height = self._minimum_font_height * max_rows
+        max_width = self.fm.settings.iterm2_font_width * max_cols
+        max_height = self.fm.settings.iterm2_font_height * max_rows
         if height > max_height:
             if width > max_width:
                 width_scale = max_width / width