about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorWojciech Siewierski <wojciech.siewierski@onet.pl>2015-03-18 18:12:15 +0100
committerhut <hut@lepus.uberspace.de>2015-03-18 19:30:46 +0100
commit3374b0e723d6215846def1ec195f912de2019694 (patch)
treeecf3cf056a49449b88c68a4d1cdcc89919d0d3c8
parent33e173fdf5840f3cd808d073eb35be22638b9ff8 (diff)
downloadranger-3374b0e723d6215846def1ec195f912de2019694.tar.gz
core.linemode: API refactoring + better documentation
The custom linemode may leave out the infostring or explicitly raise
NotImplementedError to use the default implementation which previously
was only available to the "filename" linemode.
-rw-r--r--ranger/core/linemode.py16
-rw-r--r--ranger/gui/widgets/browsercolumn.py6
2 files changed, 13 insertions, 9 deletions
diff --git a/ranger/core/linemode.py b/ranger/core/linemode.py
index c394bc15..166829cf 100644
--- a/ranger/core/linemode.py
+++ b/ranger/core/linemode.py
@@ -29,9 +29,17 @@ class LinemodeBase(object):
         """The left-aligned part of the line."""
         raise NotImplementedError
 
-    @abstractmethod
     def infostring(self, file, metadata):
-        """The right-aligned part of the line."""
+        """The right-aligned part of the line.
+
+        If `NotImplementedError' is raised (e.g. this method is just
+        not implemented in the actual linemode), the caller should
+        provide its own implementation, which in this case means
+        displaying the hardlink count of the directories. Useful
+        because only the caller (BrowserColumn) possesses the data
+        necessary to display that information.
+
+        """
         raise NotImplementedError
 
 
@@ -41,10 +49,6 @@ class DefaultLinemode(LinemodeBase):
     def filetitle(self, file, metadata):
         return file.relative_path
 
-    def infostring(self, file, metadata):
-        # Should never be called for this linemode, implemented in BrowserColumn
-        raise NotImplementedError
-
 
 class TitleLinemode(LinemodeBase):
     name = "metatitle"
diff --git a/ranger/gui/widgets/browsercolumn.py b/ranger/gui/widgets/browsercolumn.py
index 2e9bf7a2..0340b565 100644
--- a/ranger/gui/widgets/browsercolumn.py
+++ b/ranger/gui/widgets/browsercolumn.py
@@ -301,13 +301,13 @@ class BrowserColumn(Pager):
             # info string
             infostring = []
             infostringlen = 0
-            if current_linemode.name == "filename":
-                infostring = self._draw_infostring_display(drawn, space)
-            else:
+            try:
                 infostringdata = current_linemode.infostring(drawn, metadata)
                 if infostringdata:
                     infostring.append([" " + infostringdata + " ",
                                        ["infostring"]])
+            except NotImplementedError:
+                infostring = self._draw_infostring_display(drawn, space)
             if infostring:
                 infostringlen = self._total_len(infostring)
                 if space - infostringlen > 2: