[PATCHv3,2/4] knotty.py: Correct the width of the progress bar for the real tasks

Message ID 20220308143233.19972-2-pkj@axis.com
State Accepted, archived
Commit a41f7792f17acdba8c7ea83b79e413ae6a49da68
Headers show
Series [PATCHv3,1/4] knotty.py: Improve the message while waiting for running tasks to finish | expand

Commit Message

Peter Kjellerstedt March 8, 2022, 2:32 p.m. UTC
From: Peter Kjellerstedt <peter.kjellerstedt@axis.com>

In commit 8055ec36 (knotty: Improve setscene task display) the setscene
tasks got their own line in the task output. However, the progress bar
code does not handle newlines in its widgets, so the length of the
setscene line was included when calculating how much space is available
for the progress bar of the running tasks, making it much too short.

Instead of trying to teach the progress bar code to handle newlines,
separate the output of the setscene tasks from the progress bar for the
real tasks.

Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>

PATCHv2: Corrected so that there are no changes to the output except
         that the progress bar now fills the width of the terminal as
PATCHv3: Extracted two minor code clean ups to a separate patch.

 bitbake/lib/bb/ui/knotty.py | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)


diff --git a/bitbake/lib/bb/ui/knotty.py b/bitbake/lib/bb/ui/knotty.py
index a520895da2..52e6eb96fe 100644
--- a/bitbake/lib/bb/ui/knotty.py
+++ b/bitbake/lib/bb/ui/knotty.py
@@ -278,22 +278,31 @@  class TerminalFilter(object):
                 content += ':'
+            scene_tasks = "%s of %s" % (self.helper.setscene_current, self.helper.setscene_total)
+            cur_tasks = "%s of %s" % (self.helper.tasknumber_current, self.helper.tasknumber_total)
+            content = ''
+            if not self.quiet:
+                msg = "Setscene tasks: %s" % scene_tasks
+                content += msg + "\n"
+                print(msg)
             if self.quiet:
-                content = "Running tasks (%s of %s, %s of %s)" % (self.helper.setscene_current, self.helper.setscene_total, self.helper.tasknumber_current, self.helper.tasknumber_total)
+                msg = "Running tasks (%s, %s)" % (scene_tasks, cur_tasks)
             elif not len(activetasks):
-                content = "Setscene tasks: %s of %s\nNo currently running tasks (%s of %s)" % (self.helper.setscene_current, self.helper.setscene_total, self.helper.tasknumber_current, self.helper.tasknumber_total)
+                msg = "No currently running tasks (%s)" % cur_tasks
-                content = "Setscene tasks: %s of %s\nCurrently %2s running tasks (%s of %s)" % (self.helper.setscene_current, self.helper.setscene_total, len(activetasks), self.helper.tasknumber_current, self.helper.tasknumber_total)
+                msg = "Currently %2s running tasks (%s)" % (len(activetasks), cur_tasks)
             maxtask = self.helper.tasknumber_total
             if not self.main_progress or self.main_progress.maxval != maxtask:
                 widgets = [' ', progressbar.Percentage(), ' ', progressbar.Bar()]
                 self.main_progress = BBProgress("Running tasks", maxtask, widgets=widgets, resize_handler=self.sigwinch_handle)
-            self.main_progress.setmessage(content)
+            self.main_progress.setmessage(msg)
             progress = self.helper.tasknumber_current - 1
             if progress < 0:
                 progress = 0
-            content = self.main_progress.update(progress)
+            content += self.main_progress.update(progress)
         lines = self.getlines(content)
         if self.quiet == 0: