summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2012-04-15 19:22:25 +0100
committerLars Wirzenius <liw@liw.fi>2012-04-15 19:22:25 +0100
commit82d2b7b8950a43f2055353ad9259cad6506b142e (patch)
treed769974cd3dcc0985c54b4b3fa4762933fcc8180
parent6204db8f52e77fd18dd681b65452ef2103dfa688 (diff)
downloadpython-ttystatus-82d2b7b8950a43f2055353ad9259cad6506b142e.tar.gz
Limit rendered text to available width
-rw-r--r--ttystatus/status.py2
-rw-r--r--ttystatus/status_tests.py9
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')
+