Skip to content

Commit

Permalink
Only decorate stdout/stderr if status line enabled.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikepurvis committed Jun 15, 2021
1 parent 7a1d3d9 commit 34240e4
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions colcon_notification/event_handler/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,21 @@ def __init__(self): # noqa: D107
# pattern to match progress indicator in e.g. make
self._progress_pattern = re.compile(r'^\[( \d| \d\d|1\d\d)%\] ')

# decorate write methods for stdout / stderr
# to clear the last status line before other output
sys.stdout.write = self._write_and_last_clear_status_line(
sys.stdout.write)
sys.stdout.buffer.write = self._write_and_last_clear_status_line(
sys.stdout.buffer.write)
sys.stderr.write = self._write_and_last_clear_status_line(
sys.stderr.write)
sys.stderr.buffer.write = self._write_and_last_clear_status_line(
sys.stderr.buffer.write)
self._last_status_line_length = None

# register exit handle to ensure the last status line is cleared
atexit.register(self._clear_last_status_line)
if self.enabled:
# decorate write methods for stdout / stderr
# to clear the last status line before other output
sys.stdout.write = self._write_and_last_clear_status_line(
sys.stdout.write)
sys.stdout.buffer.write = self._write_and_last_clear_status_line(
sys.stdout.buffer.write)
sys.stderr.write = self._write_and_last_clear_status_line(
sys.stderr.write)
sys.stderr.buffer.write = self._write_and_last_clear_status_line(
sys.stderr.buffer.write)
self._last_status_line_length = None

# register exit handle to ensure the last status line is cleared
atexit.register(self._clear_last_status_line)

def _write_and_last_clear_status_line(self, func):
def wrapped_func(*args, **kwargs):
Expand Down

0 comments on commit 34240e4

Please sign in to comment.