summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authortoonn <toonn@toonn.io>2018-10-03 19:06:17 +0200
committertoonn <toonn@toonn.io>2019-11-06 20:14:17 +0100
commita9aa71cfd91cb33cc9968e936e37df43b76daf6d (patch)
tree4b659528f0bf6d854ea5fc732509b31d2ab0a019 /ranger
parentdab04350b2a3d55e762b0a2f855c5faf4ca61d61 (diff)
downloadranger-a9aa71cfd91cb33cc9968e936e37df43b76daf6d.tar.gz
Add a setting to wrap plain text previews
Fixes #1304
Diffstat (limited to 'ranger')
-rw-r--r--ranger/config/rc.conf3
-rw-r--r--ranger/container/settings.py1
-rw-r--r--ranger/gui/widgets/pager.py16
3 files changed, 15 insertions, 5 deletions
diff --git a/ranger/config/rc.conf b/ranger/config/rc.conf
index e557d4de..c3e0f299 100644
--- a/ranger/config/rc.conf
+++ b/ranger/config/rc.conf
@@ -147,6 +147,9 @@ set preview_files true
 set preview_directories true
 set collapse_preview true
 
+# Wrap long lines in plain text previews?
+set wrap_plaintext_previews false
+
 # Save the console history on exit?
 set save_console_history true
 
diff --git a/ranger/container/settings.py b/ranger/container/settings.py
index 6fc2da5e..7549325a 100644
--- a/ranger/container/settings.py
+++ b/ranger/container/settings.py
@@ -98,6 +98,7 @@ ALLOWED_SETTINGS = {
     'viewmode': str,
     'w3m_delay': float,
     'w3m_offset': int,
+    'wrap_plaintext_previews': bool,
     'wrap_scroll': bool,
     'xterm_alt_key': bool,
 }
diff --git a/ranger/gui/widgets/pager.py b/ranger/gui/widgets/pager.py
index c1aa2765..fd0e7887 100644
--- a/ranger/gui/widgets/pager.py
+++ b/ranger/gui/widgets/pager.py
@@ -246,11 +246,17 @@ class Pager(Widget):  # pylint: disable=too-many-instance-attributes
         while True:
             try:
                 line = self._get_line(i).expandtabs(4)
-                if self.markup == 'ansi':
-                    line = ansi.char_slice(line, startx, self.wid) + ansi.reset
-                else:
-                    line = line[startx:self.wid + startx]
-                yield line.rstrip().replace('\r\n', '\n')
+                for part in ((0,) if not
+                        self.fm.settings.wrap_plaintext_previews else
+                        range(max(1, ((len(line) - 1) // self.wid) + 1))):
+                    shift = part * self.wid
+                    if self.markup == 'ansi':
+                        line_bit = ansi.char_slice(line, startx + shift,
+                                self.wid + shift) + ansi.reset
+                    else:
+                        line_bit = line[startx + shift
+                                        :self.wid + startx + shift]
+                    yield line_bit.rstrip().replace('\r\n', '\n')
             except IndexError:
                 return
             i += 1