Skip to contentSkip to conversation

progressbar/knotty: Allow mixing log messages and progress bars

PATCH Superseded Richard Purdie 1 participant 1 message Mar 24

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 progressbar/knotty: Allow mixing log messages and progress bars

If we try and print a log message in the middle of progress bar, the display can be corrupted. Add a clear() method to progress bars allowing them to be removed for the log message, then reprinted using update().

---
 lib/bb/ui/knotty.py            | 5 +++++
 lib/progressbar/progressbar.py | 3 +++
 2 files changed, 8 insertions(+)
lib/bb/ui/knotty.py +5 -0
index e4b7b83061e..06b654c4422 100644
@@ -791,7 +791,12 @@ def main(server, eventHandler, params, tf = TerminalFilter):
                         event.msg = taskinfo['title'] + ': ' + event.msg
                 if hasattr(event, 'fn') and event.levelno not in [bb.msg.BBLogFormatter.WARNONCE, bb.msg.BBLogFormatter.ERRORONCE]:
                     event.msg = event.fn + ': ' + event.msg
+                # Need to remove any progress bar, then add it back after we print this message
+                if parseprogress:
+                    parseprogress.clear()
                 logging.getLogger(event.name).handle(event)
+                if parseprogress:
+                    parseprogress.update(parseprogress.currval)
                 continue
 
             if isinstance(event, bb.build.TaskFailedSilent):
lib/progressbar/progressbar.py +3 -0
index a8e2dc09c91..1562774ba1a 100644
@@ -278,6 +278,9 @@ class ProgressBar(object):
         self.last_update_time = now
         return output
 
+    def clear(self):
+        self.fd.write(" " * self.term_width + '\r')
+        self.fd.flush()
 
     def start(self, update=True):
         """Starts measuring time, and prints the bar at 0%.