On Sat, 2018-07-07 at 11:26 +0100, Chris Lamb wrote:

> Thanks, applied.

Attached a couple more patches.

-- 
bye,
pabs

https://wiki.debian.org/PaulWise
From 2c95bd3ec8e17c54fc2f8a1c4a1735d17df7ab55 Mon Sep 17 00:00:00 2001
From: Paul Wise <p...@debian.org>
Date: Sat, 7 Jul 2018 16:31:24 +0800
Subject: [PATCH 1/2] Use the ProgressBar's idea of the terminal width instead

More likely to overwrite the correct number of characters.

Fixes: commit dfb0c190173dff953fe1481797486d0b3e09306e
---
 diffoscope/progress.py | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/diffoscope/progress.py b/diffoscope/progress.py
index 286f9d9..5edfe84 100644
--- a/diffoscope/progress.py
+++ b/diffoscope/progress.py
@@ -232,10 +232,8 @@ class ProgressBar(object):
                 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)
+                    print(' ' * self.term_width, end='', file=self.fd)
                 else:
                     # Do not flush if nothing was written
                     return
-- 
2.18.0

From ed9cfc95bce9fc08aa5d0ac0d2ad1b709e9cb108 Mon Sep 17 00:00:00 2001
From: Paul Wise <p...@debian.org>
Date: Sat, 7 Jul 2018 16:13:35 +0800
Subject: [PATCH 2/2] 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
and wasn't portable to different types of terminals.
---
 diffoscope/progress.py | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/diffoscope/progress.py b/diffoscope/progress.py
index 5edfe84..c0e140c 100644
--- a/diffoscope/progress.py
+++ b/diffoscope/progress.py
@@ -34,9 +34,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

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to