summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorErez Shermer <erezshermer@gmail.com>2018-06-07 09:59:02 +0300
committerErez Shermer <erezshermer@gmail.com>2018-06-07 09:59:02 +0300
commitb77e033746fe9120f2083bf59164b9ff4c553aa1 (patch)
tree9c1134de57e0894a0ffe87758b5661bbe698d96d
parent4c9b2143d39d09fd286ec79419b00852b5d181ff (diff)
downloadranger-b77e033746fe9120f2083bf59164b9ff4c553aa1.tar.gz
Proper usage of the bidi setting
-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.py17
4 files changed, 26 insertions, 2 deletions
diff --git a/doc/ranger.pod b/doc/ranger.pod
index 8599a1a6..a4e782b3 100644
--- a/doc/ranger.pod
+++ b/doc/ranger.pod
@@ -968,6 +968,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 fe00c7c0..5a7a9a6d 100644
--- a/ranger/config/rc.conf
+++ b/ranger/config/rc.conf
@@ -101,6 +101,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 9f54f24d..9603401f 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 b3272cbc..b38595c1 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,16 @@ 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)
+        else:
+            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