From 57d78a5f4030846bf78829b3f2916f4543e1874f Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 3 Jun 2017 17:22:57 +0300 Subject: Add: TerminalStatus.hide method --- example.py | 3 +++ ttystatus/status.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/example.py b/example.py index 5814fbc..eb1439b 100644 --- a/example.py +++ b/example.py @@ -57,6 +57,9 @@ def main(): if os.path.islink(pathname): ts['symlink'] = pathname ts.notify('Symlink! %s' % pathname) + ts.hide() + sys.stdout.write('THIS IS STDOUT!\n') + ts.flush() elif 'error' in pathname: ts.error('Error in pathname: %s' % pathname) ts['done'] += 1 diff --git a/ttystatus/status.py b/ttystatus/status.py index 77f0b18..a5c40d1 100644 --- a/ttystatus/status.py +++ b/ttystatus/status.py @@ -118,7 +118,21 @@ class TerminalStatus(object): if self._m.enabled and self._m.time_to_write(): self._write() + def hide(self): # pragma: no cover + '''Hide current progress report. + + Use .flush() to make it visible again. Hiding is useful if you + want to write things to stdout/stderr that might get mixed + with progress output. The .notify() and .error() methods get + disabled if progress reporting gets disabled, but .hide() + doesn't. + + ''' + + self._m.clear() + 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. -- cgit v1.2.1