On Sat, 2018-07-07 at 07:45 +0100, Chris Lamb wrote: > I wasn't aware that was a possibility.
Yeah, different terminals have different capabilities. Most modern ones of course can erase to EOL though. > If you mean via --text=filename then the progress bar does not > appear there. I was thinking diffoscope &> output shell redirection. > In that case, please could you provide a merge request? I'm not interested in touching gitlab, patches attached. -- bye, pabs https://wiki.debian.org/PaulWise
From 9fa755c81033148cc1a5a49bc4d2fe865ec6e0c8 Mon Sep 17 00:00:00 2001 From: Paul Wise <p...@debian.org> Date: Sat, 7 Jul 2018 16:13:35 +0800 Subject: [PATCH 1/3] Do not delete the current terminal line for every progress bar update The progress bar already overwrites the entire line so erasing it before that serves no purpose. The erasure was also causing the progress bar to flicker. --- diffoscope/progress.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/diffoscope/progress.py b/diffoscope/progress.py index e60188c..a584ef7 100644 --- a/diffoscope/progress.py +++ b/diffoscope/progress.py @@ -32,9 +32,6 @@ class ProgressLoggingHandler(logging.StreamHandler): def emit(self, record): try: - # Delete the current line (i.e. the progress bar) - self.stream.write("\r\033[K") - self.flush() super().emit(record) if not self.progressbar.bar.finished: self.progressbar.bar.update() -- 2.18.0
From f386b5e3dc5a5ebbc0dc06720b56f8af33ea7c20 Mon Sep 17 00:00:00 2001 From: Paul Wise <p...@debian.org> Date: Sat, 7 Jul 2018 16:31:24 +0800 Subject: [PATCH 2/3] 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 --- diffoscope/progress.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/diffoscope/progress.py b/diffoscope/progress.py index a584ef7..215bb23 100644 --- 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 <la...@debian.org> +# Copyright © 2018 Paul Wise <p...@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__) @@ -212,10 +214,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(), -- 2.18.0
From ae7c7acc52bc45a452555dd16932fc21419426f8 Mon Sep 17 00:00:00 2001 From: Paul Wise <p...@debian.org> Date: Sat, 7 Jul 2018 17:22:19 +0800 Subject: [PATCH 3/3] Erase the progress bar line when diffoscope is interrupted Otherwise cruft is left on the terminal after exit. --- diffoscope/main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/diffoscope/main.py b/diffoscope/main.py index 375cdc2..e2fb945 100644 --- 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: -- 2.18.0
signature.asc
Description: This is a digitally signed message part