Commit dfb0c190 authored by Paul Wise's avatar Paul Wise Committed by Chris Lamb

Clear the progress bar after completion. (Closes: #901758)

Handle terminals that do not support erasing the line by
filling the terminal with spaces.

Ignore output devices that are not terminals.

Requires: Python 3.2 for shutil.get_terminal_size
parent 3ee43e17
Pipeline #12565 failed with stage
in 11 minutes and 32 seconds
......@@ -3,6 +3,7 @@
# diffoscope: in-depth comparison of files, archives, and directories
# Copyright © 2016 Chris Lamb <>
# Copyright © 2018 Paul Wise <>
# diffoscope is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......@@ -20,6 +21,7 @@
import os
import sys
import json
import signal
import logging
logger = logging.getLogger(__name__)
......@@ -215,10 +217,38 @@ class ProgressBar(object):
# Remove after is fixed.
kwargs.setdefault('fd', sys.stderr)
super().__init__(*args, **kwargs)
# Terminal handling after parent init since that sets self.fd
if self.fd.isatty():
from curses import tigetstr, setupterm
self.erase_to_eol = tigetstr('el')
self.erase_to_eol = None
def _need_update(self):
return True
def erase_line(self):
if self.erase_to_eol:
elif self.fd.isatty():
from shutil import get_terminal_size
width = get_terminal_size().columns
print(end='\r', file=self.fd)
print(' ' * width, end='', file=self.fd)
# Do not flush if nothing was written
def finish(self):
self.finished = True
# Clear the progress bar after completion
if self.signal_set:
signal.signal(signal.SIGWINCH, signal.SIG_DFL) = OurProgressBar(widgets=(
' ',
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment