diff options
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | doc/ranger.pod | 6 | ||||
-rw-r--r-- | ranger/config/rc.conf | 4 | ||||
-rw-r--r-- | ranger/container/settings.py | 1 | ||||
-rw-r--r-- | ranger/gui/widgets/browsercolumn.py | 16 |
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 |