summaryrefslogtreecommitdiff
path: root/ttystatus
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2015-10-10 11:57:02 +0300
committerLars Wirzenius <liw@liw.fi>2015-10-10 12:03:08 +0300
commit78a211f249d3a70c4c3322abe616cded5a7e085b (patch)
treec1798319e193df78a4afa8aa0276d767152b5304 /ttystatus
parent9b5ba7f23fe584f5807fea183070cee7594898e1 (diff)
downloadttystatus-78a211f249d3a70c4c3322abe616cded5a7e085b.tar.gz
Improve speed when output is disabled
There's no point in trying to render if output isn't happening. This brings benchmark time from about 26 seconds to 7.
Diffstat (limited to 'ttystatus')
-rw-r--r--ttystatus/messager.py4
-rw-r--r--ttystatus/status.py2
-rw-r--r--ttystatus/status_tests.py3
3 files changed, 8 insertions, 1 deletions
diff --git a/ttystatus/messager.py b/ttystatus/messager.py
index 8743561..00b05d1 100644
--- a/ttystatus/messager.py
+++ b/ttystatus/messager.py
@@ -60,6 +60,10 @@ class Messager(object):
'''Enable output to happen.'''
self._enabled = True
+ def is_enabled(self):
+ '''Is output enabled?'''
+ return self._enabled
+
def time_to_write(self):
'''Is it time to write now?'''
return self._now() - self._previous_write_at >= self._period
diff --git a/ttystatus/status.py b/ttystatus/status.py
index b4232d2..46e291f 100644
--- a/ttystatus/status.py
+++ b/ttystatus/status.py
@@ -92,7 +92,7 @@ class TerminalStatus(object):
for row in self._widget_rows:
for w in row:
w.update(self)
- if self._m.time_to_write():
+ if self._m.is_enabled() and self._m.time_to_write():
self._write()
def flush(self):
diff --git a/ttystatus/status_tests.py b/ttystatus/status_tests.py
index ecf91f9..0a96917 100644
--- a/ttystatus/status_tests.py
+++ b/ttystatus/status_tests.py
@@ -51,6 +51,9 @@ class DummyMessager(object):
def disable(self):
self.enabled = False
+ def is_enabled(self):
+ return self.enabled
+
class TerminalStatusTests(unittest.TestCase):