summaryrefslogtreecommitdiff
path: root/ttystatus/messager.py
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2011-01-30 19:17:45 +0000
committerLars Wirzenius <liw@liw.fi>2011-01-30 19:17:45 +0000
commit9da02197510faff59aed2ae41289c6be17853c7d (patch)
tree6a5dd4297c64244d8fef9615b49e51605ba30eb1 /ttystatus/messager.py
parent5ddae1fc138cdcc2974a5b67686f554ee7caa87f (diff)
downloadpython-ttystatus-9da02197510faff59aed2ae41289c6be17853c7d.tar.gz
Output to /dev/tty instead stderr.
Diffstat (limited to 'ttystatus/messager.py')
-rw-r--r--ttystatus/messager.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/ttystatus/messager.py b/ttystatus/messager.py
index 21ea843..5e698c0 100644
--- a/ttystatus/messager.py
+++ b/ttystatus/messager.py
@@ -28,13 +28,16 @@ class Messager(object):
def __init__(self, output=None, period=None):
self._enabled = True
- self.output = output or sys.stderr
+ self.output = output or self._open_tty()
self._period = 1.0 if period is None else period
self._last_msg = '' # What did we write last?
self._last_time = 0 # When did we write last?
self._cached_msg = '' # Last message from user, to write() method.
self.set_width(self._get_terminal_width()) # Width of terminal
signal.signal(signal.SIGWINCH, self._sigwinch_handler)
+
+ def _open_tty(self): # pragma: no cover
+ return open('/dev/tty', 'w')
def set_width(self, actual_width):
self.width = actual_width - 1
@@ -73,12 +76,13 @@ class Messager(object):
def _raw_write(self, string):
'''Write raw data if output is terminal.'''
- if self._enabled and self.output.isatty():
+ if self._enabled and self.output and self.output.isatty():
try:
self.output.write(string)
except IOError: # pragma: no cover
# Ignored on purpose.
- self.output.flush()
+ pass
+ self.output.flush()
def _overwrite(self, string):
'''Overwrite current message on terminal.'''