From 3374b0e723d6215846def1ec195f912de2019694 Mon Sep 17 00:00:00 2001 From: Wojciech Siewierski Date: Wed, 18 Mar 2015 18:12:15 +0100 Subject: 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. --- ranger/core/linemode.py | 16 ++++++++++------ ranger/gui/widgets/browsercolumn.py | 6 +++--- 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: -- cgit 1.4.1-2-gfad0