From 4b3b9e594faf539d96814bfca605405dce7d8086 Mon Sep 17 00:00:00 2001 From: Abdo Roig-Maranges Date: Thu, 21 Mar 2013 13:24:36 +0100 Subject: Fix Issue #80 that crashed ranger when resized too small This fixes Issue #80 and cleans up the code a bit so this particular fragment is more readable. --- ranger/gui/widgets/browsercolumn.py | 48 +++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/ranger/gui/widgets/browsercolumn.py b/ranger/gui/widgets/browsercolumn.py index a4ba7eea..d705e6ba 100644 --- a/ranger/gui/widgets/browsercolumn.py +++ b/ranger/gui/widgets/browsercolumn.py @@ -265,27 +265,33 @@ class BrowserColumn(Pager): # colorscheme, to compute the curses attribute. predisplay_left = [] predisplay_right = [] - - predisplay_left += self._draw_tagged_display(tagged, tagged_marker) - predisplay_right += self._draw_vcsstring_display(drawn) - space = self.wid - self._total_len(predisplay_left) - \ - self._total_len(predisplay_right) - - # If not enough space - if space <= 2: - del predisplay_right[:] - del predisplay_left[:] - + space = self.wid + + # selection mark + tagmark = self._draw_tagged_display(tagged, tagged_marker) + tagmarklen = self._total_len(tagmark) + if space - tagmarklen > 2: + predisplay_left += tagmark + space -= tagmarklen + + # vcs data + vcsstring = self._draw_vcsstring_display(drawn) + vcsstringlen = self._total_len(vcsstring) + if space - vcsstringlen > 2: + predisplay_right += vcsstring + space -= vcsstringlen + + # info string infostring = self._draw_infostring_display(drawn, space) - space -= self._total_len(infostring) - - predisplay_left += self._draw_text_display(text, space) - space = self.wid - self._total_len(predisplay_left) - \ - self._total_len(predisplay_right) + infostringlen = self._total_len(infostring) + if space - infostringlen > 2: + predisplay_right = infostring + predisplay_right + space -= infostringlen - predisplay_right = infostring + predisplay_right - space = self.wid - self._total_len(predisplay_left) - \ - self._total_len(predisplay_right) + textstring = self._draw_text_display(text, space) + textstringlen = self._total_len(textstring) + predisplay_left += textstring + space -= textstringlen if space > 0: predisplay_left.append([' ' * space, []]) @@ -314,9 +320,9 @@ class BrowserColumn(Pager): def _draw_text_display(self, text, space): wtext = WideString(text) + wellip = WideString(self.ellipsis[self.settings.unicode_ellipsis]) if len(wtext) > space: - wtext = wtext[:max(0, space - 1)] + \ - self.ellipsis[self.settings.unicode_ellipsis] + wtext = wtext[:max(0, space - len(wellip))] + wellip return [[str(wtext), []]] -- cgit 1.4.1-2-gfad0