From b99ac07ef0eeb232d45965216472cfdea1ff5b56 Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Thu, 27 Feb 2020 21:39:04 +0100 Subject: [PATCH] [core/decorators] Add more tests --- core/decorators.py | 16 ++++++++-------- core/output.py | 1 + tests/core/test_decorators.py | 18 ++++++++++++++++++ 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/core/decorators.py b/core/decorators.py index 9480de1..98b2ed9 100644 --- a/core/decorators.py +++ b/core/decorators.py @@ -13,21 +13,21 @@ def scrollable(func): bounce = util.format.asbool(module.parameter('scrolling.bounce', True)) scroll_speed = util.format.asint(module.parameter('scrolling.speed', 1)) - start = widget.get('scrolling.start', -1) - direction = widget.get('scrolling.direction', 'right') - start += scroll_speed if direction == 'right' else -(scroll_speed) + start = widget.get('scrolling.start', 0) - if width + start > len(text) + (scroll_speed - 1): + if start + width > len(text): if bounce: widget.set('scrolling.direction', 'left') + start -= scroll_speed*2 else: start = 0 - elif start <= 0: + elif start < 0: if bounce: widget.set('scrolling.direction', 'right') - else: - start = len(text) - widget.set('scrolling.start', start) + direction = widget.get('scrolling.direction', 'right') + if direction == 'left': + scroll_speed = -scroll_speed + widget.set('scrolling.start', start + scroll_speed) text = text[start:width+start] return text diff --git a/core/output.py b/core/output.py index 0aa2c38..3d47678 100644 --- a/core/output.py +++ b/core/output.py @@ -80,6 +80,7 @@ class i3(object): 'full_text': self.__decorate(module, widget, text), 'color': self._theme.fg(widget), 'background': self._theme.bg(widget), + 'min_width': widget.get('theme.minwidth'), }) return [attr] diff --git a/tests/core/test_decorators.py b/tests/core/test_decorators.py index 37c9759..ddbce8a 100644 --- a/tests/core/test_decorators.py +++ b/tests/core/test_decorators.py @@ -36,4 +36,22 @@ class config(unittest.TestCase): self.assertGreater(len(self.module.text), self.width) self.assertEqual(self.module.text[:self.width], self.module.get(self.widget)) + def test_bounce(self): + self.module.text = 'abcd' + self.module.set('width', 2) + self.assertEqual('ab', self.module.get(self.widget)) + self.assertEqual('bc', self.module.get(self.widget)) + self.assertEqual('cd', self.module.get(self.widget)) + self.assertEqual('bc', self.module.get(self.widget)) + self.assertEqual('ab', self.module.get(self.widget)) + + def test_nobounce(self): + self.module.set('scrolling.bounce', False) + self.module.text = 'abcd' + self.module.set('width', 2) + self.assertEqual('ab', self.module.get(self.widget)) + self.assertEqual('bc', self.module.get(self.widget)) + self.assertEqual('cd', self.module.get(self.widget)) + self.assertEqual('ab', self.module.get(self.widget)) + # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4