From 396be80da12390a5127939662c903350112df8ea Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Mon, 21 May 2012 10:59:31 +0300 Subject: Add TerminalStatus.flush method --- NEWS | 5 +++++ ttystatus/status.py | 9 +++++++++ ttystatus/status_tests.py | 8 ++++++++ 3 files changed, 22 insertions(+) diff --git a/NEWS b/NEWS index d9b8504..8d1d805 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,11 @@ NEWS file for ttystatus ======================= +Version 0.19, released UNRELEASED +--------------------------------- + +* Added a `TerminalStatus.flush` method, to allow forcing an update. + Version 0.18, released 2012-05-08 --------------------------------- diff --git a/ttystatus/status.py b/ttystatus/status.py index b98fecd..82457b2 100644 --- a/ttystatus/status.py +++ b/ttystatus/status.py @@ -73,6 +73,15 @@ class TerminalStatus(object): w.update(self) if self._m.time_to_write(): self._write() + + def flush(self): + '''Force an update of current state to the screen. + + This happens even if it is not yet time to output the screen. + + ''' + + self._write() def _render(self): '''Render current state of all widgets.''' diff --git a/ttystatus/status_tests.py b/ttystatus/status_tests.py index ef8959a..daba040 100644 --- a/ttystatus/status_tests.py +++ b/ttystatus/status_tests.py @@ -113,6 +113,14 @@ class TerminalStatusTests(unittest.TestCase): def test_has_finish_method(self): self.assertEqual(self.ts.finish(), None) + def test_flushes(self): + self.ts._m.time_to_write = lambda: False + self.ts.format('%String(foo)') + self.ts['foo'] = 'foo' + self.assertEqual(self.ts._m.written.getvalue(), '') + self.ts.flush() + self.assertEqual(self.ts._m.written.getvalue(), 'foo') + def test_disable_calls_messager_disable(self): self.ts.disable() self.assertFalse(self.ts._m.enabled) -- cgit v1.2.1