diff options
author | Lars Wirzenius <liw@liw.fi> | 2012-04-15 19:22:25 +0100 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2012-04-15 19:22:25 +0100 |
commit | 82d2b7b8950a43f2055353ad9259cad6506b142e (patch) | |
tree | d769974cd3dcc0985c54b4b3fa4762933fcc8180 /ttystatus | |
parent | 6204db8f52e77fd18dd681b65452ef2103dfa688 (diff) | |
download | python-ttystatus-82d2b7b8950a43f2055353ad9259cad6506b142e.tar.gz |
Limit rendered text to available width
Diffstat (limited to 'ttystatus')
-rw-r--r-- | ttystatus/status.py | 2 | ||||
-rw-r--r-- | ttystatus/status_tests.py | 9 |
2 files changed, 10 insertions, 1 deletions
diff --git a/ttystatus/status.py b/ttystatus/status.py index b0b93dd..b98fecd 100644 --- a/ttystatus/status.py +++ b/ttystatus/status.py @@ -91,7 +91,7 @@ class TerminalStatus(object): texts[i] = w.render(remaining) remaining -= len(texts[i]) - return ''.join(texts) + return (''.join(texts))[:self._m.width] def _write(self): '''Render and output current state of all widgets.''' diff --git a/ttystatus/status_tests.py b/ttystatus/status_tests.py index aa8c021..ab27ca9 100644 --- a/ttystatus/status_tests.py +++ b/ttystatus/status_tests.py @@ -138,3 +138,12 @@ class TerminalStatusTests(unittest.TestCase): text = self.ts._render() self.assertEqual(len(text), self.ts._m.width) + def test_renders_from_beginning_if_there_is_not_enough_space(self): + w1 = ttystatus.Literal('foo') + w2 = ttystatus.Literal('bar') + self.ts.add(w1) + self.ts.add(w2) + self.ts._m.width = 4 + text = self.ts._render() + self.assertEqual(text, 'foob') + |