diff options
author | Lars Wirzenius <liw@liw.fi> | 2011-08-29 18:34:38 +0100 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2011-08-29 18:34:38 +0100 |
commit | f241b0d86e1bb4bb81ab118ef0ec3baed6afbf0c (patch) | |
tree | 84aa482fdcab9cf36ad4c1f5e4b17f4b9e9bd92b | |
parent | 283cb2fd81cf442e59dd41af17795f666b1f2f45 (diff) | |
download | python-ttystatus-f241b0d86e1bb4bb81ab118ef0ec3baed6afbf0c.tar.gz |
Add a way to print error messages to stderr.
-rw-r--r-- | example.py | 2 | ||||
-rw-r--r-- | ttystatus/messager.py | 6 | ||||
-rw-r--r-- | ttystatus/status.py | 8 |
3 files changed, 12 insertions, 4 deletions
@@ -60,6 +60,8 @@ def main(): if os.path.islink(pathname): ts['symlink'] = pathname ts.notify('Symlink! %s' % pathname) + elif 'error' in pathname: + ts.error('Error in pathname: %s' % pathname) ts['done'] += 1 ts.finish() diff --git a/ttystatus/messager.py b/ttystatus/messager.py index 7237ea0..6085132 100644 --- a/ttystatus/messager.py +++ b/ttystatus/messager.py @@ -116,7 +116,7 @@ class Messager(object): '''Remove current message from terminal.''' self._overwrite('') - def notify(self, string): + def notify(self, string, f): '''Show a notification message string to the user. Notifications are meant for error messages and other things @@ -133,8 +133,8 @@ class Messager(object): old = self._last_msg self.clear() try: - sys.stdout.write('%s\n' % string) - sys.stdout.flush() + f.write('%s\n' % string) + f.flush() except IOError: # pragma: no cover # We ignore these. No point in crashing if terminal is bad. pass diff --git a/ttystatus/status.py b/ttystatus/status.py index 63bf438..b5d743a 100644 --- a/ttystatus/status.py +++ b/ttystatus/status.py @@ -14,6 +14,8 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. +import sys + import ttystatus @@ -80,7 +82,11 @@ class TerminalStatus(object): def notify(self, msg): '''Show a message.''' - self._m.notify(msg) + self._m.notify(msg, sys.stdout) + + def error(self, msg): + '''Write an error message.''' + self._m.notify(msg, sys.stderr) def finish(self): '''Finish status display.''' |