summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorMark Rogalski <interesting.ones.are.already.taken@gmail.com>2016-05-16 21:10:16 +0200
committerMark Rogalski <interesting.ones.are.already.taken@gmail.com>2016-05-16 21:10:16 +0200
commit56134db6dc6b07711f0d892c15b0bd98567619ad (patch)
tree9ad4fdc1862229cd8865bac66744a86c2b504cb9
parentbb5846a689c956a24c44798d32c0c33ad1d97724 (diff)
downloadranger-56134db6dc6b07711f0d892c15b0bd98567619ad.tar.gz
Add relative line numbers
-rw-r--r--ranger/container/settings.py1
-rw-r--r--ranger/gui/widgets/browsercolumn.py20
2 files changed, 19 insertions, 2 deletions
diff --git a/ranger/container/settings.py b/ranger/container/settings.py
index 7b646744..be468c21 100644
--- a/ranger/container/settings.py
+++ b/ranger/container/settings.py
@@ -39,6 +39,7 @@ ALLOWED_SETTINGS = {
     'preview_images_method': str,
     'preview_max_size': int,
     'preview_script': (str, type(None)),
+    'relative_line_numbers': bool,
     'save_console_history': bool,
     'scroll_offset': int,
     'shorten_title': int,
diff --git a/ranger/gui/widgets/browsercolumn.py b/ranger/gui/widgets/browsercolumn.py
index 89e29a00..1dd4aef8 100644
--- a/ranger/gui/widgets/browsercolumn.py
+++ b/ranger/gui/widgets/browsercolumn.py
@@ -191,6 +191,15 @@ class BrowserColumn(Pager):
                 self.set_source(f)
             Pager.draw(self)
 
+    def _format_line_number(self, linum_format, i, selected_i):
+        line_number = i
+        if self.settings.relative_line_numbers:
+            line_number = abs(selected_i - i)
+            if line_number == 0:
+                line_number = selected_i
+
+        return linum_format.format(line_number)
+
     def _draw_directory(self):
         """Draw the contents of a directory"""
         if self.image:
@@ -282,6 +291,12 @@ class BrowserColumn(Pager):
                    self.settings.line_numbers)
 
             if key in drawn.display_data:
+                if self.main_column and self.settings.line_numbers:
+                    line_number_text = self._format_line_number(linum_format,
+                                                                i,
+                                                                selected_i)
+                    drawn.display_data[key][0][0] = line_number_text
+
                 self.execute_curses_batch(line, drawn.display_data[key])
                 self.color_reset()
                 continue
@@ -303,8 +318,9 @@ class BrowserColumn(Pager):
             # line number field
             if self.settings.line_numbers:
                 if self.main_column and space - linum_text_len > 2:
-                    line_number_text = linum_format.format(i)
-
+                    line_number_text = self._format_line_number(linum_format,
+                                                                i,
+                                                                selected_i)
                     predisplay_left.append([line_number_text, ["directory"]])
                     space -= linum_text_len