summaryrefslogtreecommitdiff
path: root/ttystatus/messager.py
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2011-01-30 19:07:14 +0000
committerLars Wirzenius <liw@liw.fi>2011-01-30 19:07:14 +0000
commit5ddae1fc138cdcc2974a5b67686f554ee7caa87f (patch)
tree3d07d9d273252bbe3469e4e863ccbe8bc8fec2b8 /ttystatus/messager.py
parentc70818c596b752d3e807736723a1cf64353ccbaf (diff)
downloadpython-ttystatus-5ddae1fc138cdcc2974a5b67686f554ee7caa87f.tar.gz
Implement enable and disable output.
Diffstat (limited to 'ttystatus/messager.py')
-rw-r--r--ttystatus/messager.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/ttystatus/messager.py b/ttystatus/messager.py
index c322590..21ea843 100644
--- a/ttystatus/messager.py
+++ b/ttystatus/messager.py
@@ -27,6 +27,7 @@ class Messager(object):
'''Write messages to the terminal.'''
def __init__(self, output=None, period=None):
+ self._enabled = True
self.output = output or sys.stderr
self._period = 1.0 if period is None else period
self._last_msg = '' # What did we write last?
@@ -72,7 +73,7 @@ class Messager(object):
def _raw_write(self, string):
'''Write raw data if output is terminal.'''
- if self.output.isatty():
+ if self._enabled and self.output.isatty():
try:
self.output.write(string)
except IOError: # pragma: no cover
@@ -128,3 +129,12 @@ class Messager(object):
'''Finalize output.'''
self._overwrite(self._cached_msg)
self._raw_write('\n')
+
+ def disable(self):
+ '''Disable all output.'''
+ self._enabled = False
+
+ def enable(self):
+ '''Enable output to happen.'''
+ self._enabled = True
+