about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorToon Nolten <toonn@toonn.io>2018-06-07 12:52:43 +0200
committerGitHub <noreply@github.com>2018-06-07 12:52:43 +0200
commite461aaf0cb12fe72338f6d0ec101718e1ff02e66 (patch)
tree104434b4b7ba96c457eaef54a38c3be4c5f35fb9
parent81e1070f91ddc139f1a6abdfda962da3b1bb4c60 (diff)
parent348d9b05b49737f2e5169168d8d18500247ff867 (diff)
downloadranger-e461aaf0cb12fe72338f6d0ec101718e1ff02e66.tar.gz
Merge pull request #1199 from esm7/master
Support for RTL languages (Hebrew, Arabic) in the display of file names
-rw-r--r--README.md1
-rw-r--r--doc/ranger.pod6
-rw-r--r--ranger/config/rc.conf4
-rw-r--r--ranger/container/settings.py1
-rw-r--r--ranger/gui/widgets/browsercolumn.py16
5 files changed, 26 insertions, 2 deletions
diff --git a/README.md b/README.md
index 8abb7265..e14bab46 100644
--- a/README.md
+++ b/README.md
@@ -68,6 +68,7 @@ Optional:
 * The python module `chardet`, in case of encoding detection problems
 * `sudo` to use the "run as root"-feature
 * `w3m` for the `w3mimgdisplay` program to preview images
+* `python-bidi` for correct display of RTL file names (Hebrew, Arabic)
 
 Optional, for enhanced file previews (with `scope.sh`):
 
diff --git a/doc/ranger.pod b/doc/ranger.pod
index 7da4478b..4471a153 100644
--- a/doc/ranger.pod
+++ b/doc/ranger.pod
@@ -987,6 +987,12 @@ Abbreviate $HOME with ~ in the titlebar (first line) of ranger?
 
 Use a unicode "..." character instead of "~" to mark cut-off filenames?
 
+=item bidi_support [bool]
+
+Try to properly display file names in RTL languages (Hebrew, Arabic) by using
+a BIDI algorithm to reverse the relevant parts of the text.
+Requires the python-bidi pip package.
+
 =item update_title [bool]
 
 Set a window title?
diff --git a/ranger/config/rc.conf b/ranger/config/rc.conf
index 58d6d243..1369bb27 100644
--- a/ranger/config/rc.conf
+++ b/ranger/config/rc.conf
@@ -106,6 +106,10 @@ set iterm2_font_height 11
 # Use a unicode "..." character to mark cut-off filenames?
 set unicode_ellipsis false
 
+# BIDI support - try to properly display file names in RTL languages (Hebrew, Arabic).
+# Requires the python-bidi pip package
+set bidi_support false
+
 # Show dotfiles in the bookmark preview box?
 set show_hidden_bookmarks true
 
diff --git a/ranger/container/settings.py b/ranger/container/settings.py
index 11097cec..d0ff2f5e 100644
--- a/ranger/container/settings.py
+++ b/ranger/container/settings.py
@@ -27,6 +27,7 @@ ALLOWED_SETTINGS = {
     'automatically_count_files': bool,
     'autosave_bookmarks': bool,
     'autoupdate_cumulative_size': bool,
+    'bidi_support': bool,
     'cd_bookmarks': bool,
     'cd_tab_case': str,
     'cd_tab_fuzzy': bool,
diff --git a/ranger/gui/widgets/browsercolumn.py b/ranger/gui/widgets/browsercolumn.py
index cf322409..f85e1646 100644
--- a/ranger/gui/widgets/browsercolumn.py
+++ b/ranger/gui/widgets/browsercolumn.py
@@ -10,6 +10,12 @@ import stat
 from time import time
 from os.path import splitext
 
+try:
+    from bidi.algorithm import get_display  # pylint: disable=import-error
+    HAVE_BIDI = True
+except ImportError:
+    HAVE_BIDI = False
+
 from ranger.ext.widestring import WideString
 from ranger.core import linemode
 
@@ -410,9 +416,15 @@ class BrowserColumn(Pager):  # pylint: disable=too-many-instance-attributes
     def _total_len(predisplay):
         return sum([len(WideString(s)) for s, _ in predisplay])
 
+    def _bidi_transpose(self, text):
+        if self.settings.bidi_support and HAVE_BIDI:
+            return get_display(text)
+        return text
+
     def _draw_text_display(self, text, space):
-        wtext = WideString(text)
-        wext = WideString(splitext(text)[1])
+        bidi_text = self._bidi_transpose(text)
+        wtext = WideString(bidi_text)
+        wext = WideString(splitext(bidi_text)[1])
         wellip = WideString(self.ellipsis[self.settings.unicode_ellipsis])
         if len(wtext) > space:
             wtext = wtext[:max(1, space - len(wext) - len(wellip))] + wellip + wext