summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authorJon Anderson <jon.david.anderson@gmail.com>2018-01-21 12:05:25 -0800
committerGitHub <noreply@github.com>2018-01-21 12:05:25 -0800
commit3249d125d36fccf1aee75da6682f5ca5bec64754 (patch)
tree8b302aa1897a6be8a9fb8202c8d2d74609738d8f /ranger
parent43c71f7a938556337bad3ed2ad4b277e730fb969 (diff)
parentb1e08bf5b52746da2f0e5d9995e8dbc8c8505f62 (diff)
downloadranger-3249d125d36fccf1aee75da6682f5ca5bec64754.tar.gz
Merge branch 'master' into master
Diffstat (limited to 'ranger')
-rw-r--r--ranger/__init__.py1
-rwxr-xr-xranger/config/commands.py21
-rw-r--r--ranger/config/rc.conf8
-rw-r--r--ranger/config/rifle.conf50
-rw-r--r--ranger/container/file.py1
-rw-r--r--ranger/container/settings.py2
-rw-r--r--ranger/core/fm.py3
-rwxr-xr-xranger/data/scope.sh2
-rw-r--r--ranger/ext/img_display.py64
-rw-r--r--ranger/ext/vcs/vcs.py6
-rw-r--r--ranger/gui/widgets/console.py20
11 files changed, 135 insertions, 43 deletions
diff --git a/ranger/__init__.py b/ranger/__init__.py
index f3495197..a00b813a 100644
--- a/ranger/__init__.py
+++ b/ranger/__init__.py
@@ -29,7 +29,6 @@ DEFAULT_PAGER = 'less'
 USAGE = '%prog [options] [path]'
 VERSION = 'ranger-master {0}'.format(__version__)
 
-
 # These variables are ignored if the corresponding
 # XDG environment variable is non-empty and absolute
 CACHEDIR = os.path.expanduser('~/.cache/ranger')
diff --git a/ranger/config/commands.py b/ranger/config/commands.py
index 299f17c2..7d690b4a 100755
--- a/ranger/config/commands.py
+++ b/ranger/config/commands.py
@@ -445,11 +445,20 @@ class set_(Command):
             return sorted(self.firstpart + setting for setting in settings
                           if setting.startswith(name))
         if not value:
-            # Cycle through colorschemes when name, but no value is specified
-            if name == "colorscheme":
-                return sorted(self.firstpart + colorscheme for colorscheme
-                              in get_all_colorschemes(self.fm))
-            return self.firstpart + str(settings[name])
+            value_completers = {
+                "colorscheme":
+                # Cycle through colorschemes when name, but no value is specified
+                lambda: sorted(self.firstpart + colorscheme for colorscheme
+                               in get_all_colorschemes(self.fm)),
+
+                "column_ratios":
+                lambda: self.firstpart + ",".join(map(str, settings[name])),
+            }
+
+            def default_value_completer():
+                return self.firstpart + str(settings[name])
+
+            return value_completers.get(name, default_value_completer)()
         if bool in settings.types_of(name):
             if 'true'.startswith(value.lower()):
                 return self.firstpart + 'True'
@@ -891,6 +900,8 @@ class eval_(Command):
     resolve_macros = False
 
     def execute(self):
+        # The import is needed so eval() can access the ranger module
+        import ranger  # NOQA pylint: disable=unused-import,unused-variable
         if self.arg(1) == '-q':
             code = self.rest(2)
             quiet = True
diff --git a/ranger/config/rc.conf b/ranger/config/rc.conf
index d7f61550..6bb8f0d0 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/config/rifle.conf b/ranger/config/rifle.conf
index 8bd5f565..2c081479 100644
--- a/ranger/config/rifle.conf
+++ b/ranger/config/rifle.conf
@@ -54,30 +54,32 @@
 # Rarely installed browsers get higher priority; It is assumed that if you
 # install a rare browser, you probably use it.  Firefox/konqueror/w3m on the
 # other hand are often only installed as fallback browsers.
-ext x?html?, has surf,           X, flag f = surf -- file://"$1"
-ext x?html?, has vimprobable,    X, flag f = vimprobable -- "$@"
-ext x?html?, has vimprobable2,   X, flag f = vimprobable2 -- "$@"
-ext x?html?, has qutebrowser,    X, flag f = qutebrowser -- "$@"
-ext x?html?, has dwb,            X, flag f = dwb -- "$@"
-ext x?html?, has jumanji,        X, flag f = jumanji -- "$@"
-ext x?html?, has luakit,         X, flag f = luakit -- "$@"
-ext x?html?, has uzbl,           X, flag f = uzbl -- "$@"
-ext x?html?, has uzbl-tabbed,    X, flag f = uzbl-tabbed -- "$@"
-ext x?html?, has uzbl-browser,   X, flag f = uzbl-browser -- "$@"
-ext x?html?, has uzbl-core,      X, flag f = uzbl-core -- "$@"
-ext x?html?, has midori,         X, flag f = midori -- "$@"
-ext x?html?, has chromium,       X, flag f = chromium -- "$@"
-ext x?html?, has opera,          X, flag f = opera -- "$@"
-ext x?html?, has firefox,        X, flag f = firefox -- "$@"
-ext x?html?, has seamonkey,      X, flag f = seamonkey -- "$@"
-ext x?html?, has iceweasel,      X, flag f = iceweasel -- "$@"
-ext x?html?, has epiphany,       X, flag f = epiphany -- "$@"
-ext x?html?, has konqueror,      X, flag f = konqueror -- "$@"
-ext x?html?, has elinks,          terminal = elinks "$@"
-ext x?html?, has links2,          terminal = links2 "$@"
-ext x?html?, has links,           terminal = links "$@"
-ext x?html?, has lynx,            terminal = lynx -- "$@"
-ext x?html?, has w3m,             terminal = w3m "$@"
+ext x?html?, has surf,             X, flag f = surf -- file://"$1"
+ext x?html?, has vimprobable,      X, flag f = vimprobable -- "$@"
+ext x?html?, has vimprobable2,     X, flag f = vimprobable2 -- "$@"
+ext x?html?, has qutebrowser,      X, flag f = qutebrowser -- "$@"
+ext x?html?, has dwb,              X, flag f = dwb -- "$@"
+ext x?html?, has jumanji,          X, flag f = jumanji -- "$@"
+ext x?html?, has luakit,           X, flag f = luakit -- "$@"
+ext x?html?, has uzbl,             X, flag f = uzbl -- "$@"
+ext x?html?, has uzbl-tabbed,      X, flag f = uzbl-tabbed -- "$@"
+ext x?html?, has uzbl-browser,     X, flag f = uzbl-browser -- "$@"
+ext x?html?, has uzbl-core,        X, flag f = uzbl-core -- "$@"
+ext x?html?, has midori,           X, flag f = midori -- "$@"
+ext x?html?, has chromium-browser, X, flag f = chromium-browser -- "$@"
+ext x?html?, has chromium,         X, flag f = chromium -- "$@"
+ext x?html?, has google-chrome,    X, flag f = google-chrome -- "$@"
+ext x?html?, has opera,            X, flag f = opera -- "$@"
+ext x?html?, has firefox,          X, flag f = firefox -- "$@"
+ext x?html?, has seamonkey,        X, flag f = seamonkey -- "$@"
+ext x?html?, has iceweasel,        X, flag f = iceweasel -- "$@"
+ext x?html?, has epiphany,         X, flag f = epiphany -- "$@"
+ext x?html?, has konqueror,        X, flag f = konqueror -- "$@"
+ext x?html?, has elinks,            terminal = elinks "$@"
+ext x?html?, has links2,            terminal = links2 "$@"
+ext x?html?, has links,             terminal = links "$@"
+ext x?html?, has lynx,              terminal = lynx -- "$@"
+ext x?html?, has w3m,               terminal = w3m "$@"
 
 #-------------------------------------------
 # Misc
diff --git a/ranger/container/file.py b/ranger/container/file.py
index 83942671..6450cfe6 100644
--- a/ranger/container/file.py
+++ b/ranger/container/file.py
@@ -48,7 +48,6 @@ class File(FileSystemObject):
     preview_data = None
     preview_known = False
     preview_loading = False
-    linemode = "filename"
     _firstbytes = None
 
     @property
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/core/fm.py b/ranger/core/fm.py
index 591edecc..c55a3922 100644
--- a/ranger/core/fm.py
+++ b/ranger/core/fm.py
@@ -23,6 +23,7 @@ from ranger.gui.ui import UI
 from ranger.container.bookmarks import Bookmarks
 from ranger.core.runner import Runner
 from ranger.ext.img_display import (W3MImageDisplayer, ITerm2ImageDisplayer,
+                                    TerminologyImageDisplayer,
                                     URXVTImageDisplayer, URXVTImageFSDisplayer, ImageDisplayer)
 from ranger.core.metadata import MetadataManager
 from ranger.ext.rifle import Rifle
@@ -227,6 +228,8 @@ class FM(Actions,  # pylint: disable=too-many-instance-attributes
             return W3MImageDisplayer()
         elif self.settings.preview_images_method == "iterm2":
             return ITerm2ImageDisplayer()
+        elif self.settings.preview_images_method == "terminology":
+            return TerminologyImageDisplayer()
         elif self.settings.preview_images_method == "urxvt":
             return URXVTImageDisplayer()
         elif self.settings.preview_images_method == "urxvt-full":
diff --git a/ranger/data/scope.sh b/ranger/data/scope.sh
index 560e27da..35021129 100755
--- a/ranger/data/scope.sh
+++ b/ranger/data/scope.sh
@@ -142,7 +142,7 @@ handle_mime() {
                 local highlight_format='ansi'
             fi
             highlight --replace-tabs="${HIGHLIGHT_TABWIDTH}" --out-format="${highlight_format}" \
-                --style="${HIGHLIGHT_STYLE}" -- "${FILE_PATH}" && exit 5
+                --style="${HIGHLIGHT_STYLE}" --force -- "${FILE_PATH}" && exit 5
             # pygmentize -f "${pygmentize_format}" -O "style=${PYGMENTIZE_STYLE}" -- "${FILE_PATH}" && exit 5
             exit 2;;
 
diff --git a/ranger/ext/img_display.py b/ranger/ext/img_display.py
index c55d835e..01c739d3 100644
--- a/ranger/ext/img_display.py
+++ b/ranger/ext/img_display.py
@@ -32,6 +32,7 @@ W3MIMGDISPLAY_PATHS = [
     '/usr/libexec/w3m/w3mimgdisplay',
     '/usr/lib64/w3m/w3mimgdisplay',
     '/usr/libexec64/w3m/w3mimgdisplay',
+    '/usr/local/libexec/w3m/w3mimgdisplay',
 ]
 
 
@@ -207,8 +208,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"))
@@ -248,8 +247,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
@@ -315,6 +314,63 @@ class ITerm2ImageDisplayer(ImageDisplayer, FileManagerAware):
         return width, height
 
 
+class TerminologyImageDisplayer(ImageDisplayer, FileManagerAware):
+    """Implementation of ImageDisplayer using terminology image display support
+    (https://github.com/billiob/terminology).
+
+    Ranger must be running in terminology for this to work.
+    Doesn't work with TMUX :/
+    """
+
+    def __init__(self):
+        self.display_protocol = "\033"
+        self.close_protocol = "\000"
+
+    def draw(self, path, start_x, start_y, width, height):
+        # Save cursor
+        curses.putp(curses.tigetstr("sc"))
+
+        y = start_y
+        # Move to drawing zone
+        self._move_to(start_x, y)
+
+        # Write intent
+        sys.stdout.write("%s}ic#%d;%d;%s%s" % (
+            self.display_protocol,
+            width, height,
+            path,
+            self.close_protocol))
+
+        # Write Replacement commands ('#')
+        for _ in range(0, height):
+            sys.stdout.write("%s}ib%s%s%s}ie%s" % (
+                self.display_protocol,
+                self.close_protocol,
+                "#" * width,
+                self.display_protocol,
+                self.close_protocol))
+            y = y + 1
+            self._move_to(start_x, y)
+
+        # Restore cursor
+        curses.putp(curses.tigetstr("rc"))
+
+        sys.stdout.flush()
+
+    @staticmethod
+    def _move_to(x, y):
+        # curses.move(y, x)
+        tparm = curses.tparm(curses.tigetstr("cup"), y, x)
+        if sys.version_info[0] < 3:
+            sys.stdout.write(tparm)
+        else:
+            sys.stdout.buffer.write(tparm)  # pylint: disable=no-member
+
+    def clear(self, start_x, start_y, width, height):
+        self.fm.ui.win.redrawwin()
+        self.fm.ui.win.refresh()
+
+
 class URXVTImageDisplayer(ImageDisplayer, FileManagerAware):
     """Implementation of ImageDisplayer working by setting the urxvt
     background image "under" the preview pane.
diff --git a/ranger/ext/vcs/vcs.py b/ranger/ext/vcs/vcs.py
index 1d0edff4..e2838f8d 100644
--- a/ranger/ext/vcs/vcs.py
+++ b/ranger/ext/vcs/vcs.py
@@ -112,7 +112,11 @@ class Vcs(object):  # pylint: disable=too-many-instance-attributes
     def _run(self, args, path=None,  # pylint: disable=too-many-arguments
              catchout=True, retbytes=False, rstrip_newline=True):
         """Run a command"""
-        cmd = [self.repotype] + args
+        if self.repotype == 'hg':
+            # use "chg", a faster built-in client
+            cmd = ['chg'] + args
+        else:
+            cmd = [self.repotype] + args
         if path is None:
             path = self.path
 
diff --git a/ranger/gui/widgets/console.py b/ranger/gui/widgets/console.py
index 6bcf20e9..13201e34 100644
--- a/ranger/gui/widgets/console.py
+++ b/ranger/gui/widgets/console.py
@@ -87,6 +87,15 @@ class Console(Widget):  # pylint: disable=too-many-instance-attributes,too-many-
                 fobj.close()
         Widget.destroy(self)
 
+    def _calculate_offset(self):
+        wid = self.wid - 2
+        whalf = wid // 2
+        if self.pos < whalf or len(self.line) < wid:
+            return 0
+        if self.pos > len(self.line) - (wid - whalf):
+            return len(self.line) - wid
+        return self.pos - whalf
+
     def draw(self):
         self.win.erase()
         if self.question_queue:
@@ -97,11 +106,9 @@ class Console(Widget):  # pylint: disable=too-many-instance-attributes,too-many-
 
         self.addstr(0, 0, self.prompt)
         line = WideString(self.line)
-        overflow = -self.wid + len(self.prompt) + len(line) + 1
-        if overflow > 0:
-            self.addstr(0, len(self.prompt), str(line[overflow:]))
-        else:
-            self.addstr(0, len(self.prompt), self.line)
+        if line:
+            x = self._calculate_offset()
+            self.addstr(0, len(self.prompt), str(line[x:]))
 
     def finalize(self):
         move = self.fm.ui.win.move
@@ -112,7 +119,8 @@ class Console(Widget):  # pylint: disable=too-many-instance-attributes,too-many-
                 pass
         else:
             try:
-                pos = uwid(self.line[0:self.pos]) + len(self.prompt)
+                x = self._calculate_offset()
+                pos = uwid(self.line[x:self.pos]) + len(self.prompt)
                 move(self.y, self.x + min(self.wid - 1, pos))
             except curses.error:
                 pass