summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJon Anderson <jon.david.anderson@gmail.com>2018-01-27 15:41:20 -0800
committerJon Anderson <jon.david.anderson@gmail.com>2018-01-27 15:41:20 -0800
commitddcc469fe636cb13b8b44824a18fc5deb24084e2 (patch)
treef41d8608d5418ada7db54369d400c59e12e0d45d
parent623e603481b2516e48c9949218e115968f42c37c (diff)
parent3249d125d36fccf1aee75da6682f5ca5bec64754 (diff)
downloadranger-ddcc469fe636cb13b8b44824a18fc5deb24084e2.tar.gz
Merge branch 'master' of github.com:chronzerg/ranger
-rw-r--r--.github/ISSUE_TEMPLATE.md59
-rw-r--r--.gitignore1
-rw-r--r--CONTRIBUTING.md7
-rw-r--r--doc/ranger.14
-rw-r--r--doc/ranger.pod4
-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
16 files changed, 170 insertions, 83 deletions
diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md
index b7baa192..468f0991 100644
--- a/.github/ISSUE_TEMPLATE.md
+++ b/.github/ISSUE_TEMPLATE.md
@@ -1,55 +1,38 @@
-<!-- Provide a descriptive summary of the issue in the title above -->
-<!-- First verify that the issue hasn't already been reported -->
-<!-- Also test if the latest release and master branch are affected too -->
-
-#### ISSUE TYPE
-<!-- Pick one and delete the rest -->
-- Bug report
-- Improvement/feature request
-
-#### RUNTIME ENVIRONMENT
-<!-- Details of your runtime environment -->
-<!-- Retrieve Python/ranger version and locale with `ranger -\-version` -->
+<!--
+    Thank you for contributing to ranger by opening this issue.
+    Please check through this list, so you can be as helpful as possible:
+
+    1. Was this issue already reported?  Please do a quick search.
+    2. Maybe the problem is solved in the current master branch already?
+       Simply clone ranger's git repository and run ./ranger.py to find out.
+    3. Provide all the relevant information, as outlined in this template.
+       Feel free to remove any sections you don't need.
+-->
+
+#### Runtime Environment
+<!-- Retrieve Python/ranger version and locale with `ranger --version` -->
 - Operating system and version: 
 - Terminal emulator and version: 
 - Python version: 
 - Ranger version/commit: 
 - Locale: 
 
-#### EXPECTED BEHAVIOR
-<!-- Bug: What should happen? -->
-<!-- Request: How should it work? -->
+#### Current Behavior
 
+#### Expected Behavior
 
-#### CURRENT BEHAVIOR
-<!-- Bug: How is it different from the expected behavior? -->
-<!-- Request: How does it change the current behavior? -->
+#### Context
+<!-- How has this issue affected you?  What are you trying to accomplish? -->
 
+#### Possible Solutions
 
-#### CONTEXT
-<!-- How has this issue affected you? -->
-<!-- What are you trying to accomplish? -->
-
-
-#### POSSIBLE SOLUTIONS
-<!-- Bug: How should it be fixed? -->
-<!-- Request: How should it be implemented? -->
-
-
-#### STEPS TO REPRODUCE<!-- For bugs -->
-<!-- List unambiguous steps to reproduce the bug -->
+#### Steps to reproduce
 1. 
 2. 
 3. 
-4. 
-5. 
 
-#### TRACEBACK<!-- For crashes -->
-<!-- Run ranger in debug mode -->
-<!-- Paste between quotes -->
+#### Traceback
+<!-- If ranger crashes, paste the traceback in the quotes below. -->
 ```
 
 ```
-
-#### IMAGES / VIDEOS<!-- Only if relevant -->
-<!-- Link or embed images and videos of screenshots, sketches etc. -->
diff --git a/.gitignore b/.gitignore
index 02a51413..88c75b90 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,6 +2,7 @@
 *.pyo
 
 *~
+*.orig
 
 /.cache
 /build
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index abf25300..29ae33a1 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -2,8 +2,11 @@
 
 ## Tips for bug reports
 
-* Always completely fill out the issue template that is automatically inserted
-  on issue creation.
+* Was this issue already reported?  Please do a quick search.
+* Maybe the problem is solved in the current master branch already?
+  Simply clone ranger with `git clone https://github.com/ranger/ranger` or
+  download the git version via https://github.com/ranger/ranger/archive/master.zip
+  and run `./ranger.py` directly to find out.
 * You can obtain much better error messages with `ranger --debug`, please post
   those in bug reports rather than the usual, single-line error message. Also
   check the log by using the default map `W` or by running the command `display_log`.
diff --git a/doc/ranger.1 b/doc/ranger.1
index 50b83bdf..bb7114a2 100644
--- a/doc/ranger.1
+++ b/doc/ranger.1
@@ -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/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 f11e0e83..b61974ac 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'
@@ -908,6 +917,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 e4740407..0bc9e96e 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
@@ -322,6 +321,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