[Git][reproducible-builds/diffoscope][master] 2 commits: Erase the progress bar line when diffoscope is interrupted
Chris Lamb
gitlab at salsa.debian.org
Sat Jul 7 12:26:06 CEST 2018
Chris Lamb pushed to branch master at Reproducible Builds / diffoscope
Commits:
3ee43e17 by Paul Wise at 2018-07-07T12:25:50+02:00
Erase the progress bar line when diffoscope is interrupted
Otherwise cruft is left on the terminal after exit.
- - - - -
dfb0c190 by Paul Wise at 2018-07-07T12:25:50+02:00
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.
Implements: https://bugs.debian.org/901758
Requires: Python 3.2 for shutil.get_terminal_size
- - - - -
2 changed files:
- diffoscope/main.py
- diffoscope/progress.py
Changes:
=====================================
diffoscope/main.py
=====================================
--- a/diffoscope/main.py
+++ b/diffoscope/main.py
@@ -459,6 +459,8 @@ def main(args=None):
post_parse(parsed_args)
sys.exit(run_diffoscope(parsed_args))
except KeyboardInterrupt:
+ if log_handler:
+ log_handler.progressbar.bar.erase_line()
logger.info('Keyboard Interrupt')
sys.exit(2)
except BrokenPipeError:
=====================================
diffoscope/progress.py
=====================================
--- a/diffoscope/progress.py
+++ b/diffoscope/progress.py
@@ -3,6 +3,7 @@
# diffoscope: in-depth comparison of files, archives, and directories
#
# Copyright © 2016 Chris Lamb <lamby at debian.org>
+# Copyright © 2018 Paul Wise <pabs at debian.org>
#
# 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 https://github.com/niltonvolpato/python-progressbar/pull/57 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
+ setupterm()
+ self.erase_to_eol = tigetstr('el')
+ else:
+ self.erase_to_eol = None
def _need_update(self):
return True
+ def erase_line(self):
+ if self.erase_to_eol:
+ self.fd.buffer.write(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)
+ else:
+ # Do not flush if nothing was written
+ return
+ self.fd.flush()
+
+ def finish(self):
+ self.finished = True
+ self.update(self.maxval)
+ # Clear the progress bar after completion
+ self.erase_line()
+ if self.signal_set:
+ signal.signal(signal.SIGWINCH, signal.SIG_DFL)
+
self.bar = OurProgressBar(widgets=(
' ',
progressbar.Bar(),
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/compare/9c0cfdf5a59808b6698eee99600b46cada3c762d...dfb0c190173dff953fe1481797486d0b3e09306e
--
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/compare/9c0cfdf5a59808b6698eee99600b46cada3c762d...dfb0c190173dff953fe1481797486d0b3e09306e
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.reproducible-builds.org/pipermail/rb-commits/attachments/20180707/cde46b82/attachment.html>
More information about the rb-commits
mailing list