diff options
author | toonn <toonn@toonn.io> | 2022-05-27 00:02:48 +0200 |
---|---|---|
committer | toonn <toonn@toonn.io> | 2022-05-27 00:33:44 +0200 |
commit | 14ec178db8291cf14b5cff933f82e9de75092e90 (patch) | |
tree | cb247a0297d2b56a5cdaac60a54ed1684ee0e12f | |
parent | 3461f24de6d816aa4eab5de4ed6a019f80a61b41 (diff) | |
download | ranger-14ec178db8291cf14b5cff933f82e9de75092e90.tar.gz |
browsercolumn: Refactor linum_text_len
The calculation isn't difficult but the lines were long and there's several branches involved. Giving `len(str())` a name and introducing names for intermediate results should make it easier to comprehend
-rw-r--r-- | ranger/gui/widgets/browsercolumn.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/ranger/gui/widgets/browsercolumn.py b/ranger/gui/widgets/browsercolumn.py index c65bf018..425edf7f 100644 --- a/ranger/gui/widgets/browsercolumn.py +++ b/ranger/gui/widgets/browsercolumn.py @@ -277,14 +277,20 @@ class BrowserColumn(Pager): # pylint: disable=too-many-instance-attributes # Set the size of the linum text field to the number of digits in the # visible files in directory. + def nr_of_digits(number): + return len(str(number)) + scroll_end = self.scroll_begin + self.hei - 1 + distance_to_top = selected_i - self.scroll_begin + distance_to_bottom = scroll_end - selected_i + if self.settings.line_numbers.lower() == "relative": - linum_text_len = len(str(max(selected_i - self.scroll_begin, - scroll_end - selected_i))) + linum_text_len = nr_of_digits(max(distance_to_top, + distance_to_bottom)) if not self.settings.relative_current_zero: - linum_text_len = max(len(str(selected_i)), linum_text_len) + linum_text_len = max(nr_of_digits(selected_i), linum_text_len) else: - linum_text_len = len(str(scroll_end)) + linum_text_len = nr_of_digits(scroll_end) linum_format = "{0:>" + str(linum_text_len) + "}" for line in range(self.hei): |