All of lore.kernel.org
 help / color / mirror / Atom feed
From: git@cookiesoft.de
To: bitbake-devel@lists.openembedded.org
Cc: Marcel Hellwig <git@cookiesoft.de>
Subject: [PATCH] knotty: add OSC 9;4 sequence for progress display
Date: Mon,  5 Oct 2026 10:36:22 +0200	[thread overview]
Message-ID: <20261005083628.1451356-1-git@cookiesoft.de> (raw)

From: Marcel Hellwig <git@cookiesoft.de>

OSC 9;4[0] allows the terminal emulator to display a progress bar.
This is helpful for the long-running tasks in both Bitbake and Devtool.

The most prominent supporters are Windows Terminal and KDE's Konsole.
Terminals that do not support the sequence simply ignore it, so no
special treament is required.

[0]: https://learn.microsoft.com/en-us/windows/terminal/tutorials/progress-bar-sequences

Signed-off-by: Marcel Hellwig <git@cookiesoft.de>
---
 bitbake/lib/bb/ui/knotty.py | 58 +++++++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)

diff --git a/bitbake/lib/bb/ui/knotty.py b/bitbake/lib/bb/ui/knotty.py
index 5198e93d8d..b7388f2948 100644
--- a/bitbake/lib/bb/ui/knotty.py
+++ b/bitbake/lib/bb/ui/knotty.py
@@ -119,6 +119,58 @@ class InteractConsoleLogFilter(logging.Filter):
         self.tf.clearFooter()
         return True
 
+class Osc94FilterNotifier(logging.Filter):
+    def __init__(self, tf):
+        self.tf = tf
+
+    def filter(self, record):
+        if record.levelno == bb.msg.BBLogFormatter.ERROR:
+            self.tf.osc94.error()
+        elif record.levelno == bb.msg.BBLogFormatter.WARNING:
+            self.tf.osc94.warning()
+
+        return True
+
+class Osc94(object):
+    REMOVE = 0
+    SET = 1
+    ERROR = 2
+    INDETERMINATE = 3
+    WARNING = 4
+
+    def __init__(self, fd = None):
+        self.fd = fd
+        self._warning = False
+        self._error = False
+
+    def _write(self, what, argument = None):
+        if self.fd is not None:
+            argument = "" if argument is None else argument
+            self.fd.write(f"\x1b]9;4;{what};{argument}\x07")
+            self.fd.flush()
+
+    def clear(self):
+        self._write(self.REMOVE)
+
+    def indeterminate(self):
+        self._write(self.INDETERMINATE)
+
+    def error(self):
+        self._error = True
+
+    def warning(self):
+        self._warning = True
+
+    def progress(self, value):
+        value = int(min(max(value, 0), 100))
+        if self._error:
+            self._write(self.ERROR, value)
+        elif self._warning:
+            self._write(self.WARNING, value)
+        else:
+            self._write(self.SET, value)
+
+
 class TerminalFilter(object):
     rows = 25
     columns = 80
@@ -160,6 +212,7 @@ class TerminalFilter(object):
         self.lastpids = []
         self.lasttime = None
         self.quiet = quiet
+        self.osc94 = Osc94(sys.stdout)
 
         if not self.interactive:
             return
@@ -203,8 +256,10 @@ class TerminalFilter(object):
 
         for h in handlers:
             h.addFilter(InteractConsoleLogFilter(self))
+            h.addFilter(Osc94FilterNotifier(self))
 
         self.main_progress = None
+        self.osc94.indeterminate()
 
     def clearFooter(self):
         if self.footer_present:
@@ -274,6 +329,7 @@ class TerminalFilter(object):
                 tasks.append(msg)
 
         if self.main.shutdown:
+            self.osc94.indeterminate()
             content = pluralise("Waiting for %s running task to finish",
                                 "Waiting for %s running tasks to finish", len(activetasks))
             if not self.quiet:
@@ -303,6 +359,7 @@ class TerminalFilter(object):
             self.main_progress.setmessage(msg)
             progress = max(0, self.helper.tasknumber_current - 1)
             content += self.main_progress.update(progress)
+            self.osc94.progress(self.main_progress.percent)
             print('')
         lines = self.getlines(content)
         if not self.quiet:
@@ -335,6 +392,7 @@ class TerminalFilter(object):
         return lines
 
     def finish(self):
+        self.osc94.clear()
         if self.stdinbackup:
             fd = sys.stdin.fileno()
             self.termios.tcsetattr(fd, self.termios.TCSADRAIN, self.stdinbackup)
-- 
2.53.0



             reply	other threads:[~2026-10-05  8:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-05  8:36 git [this message]
2026-10-05 14:31 ` [PATCH] knotty: add OSC 9;4 sequence for progress display Paul Barker
2026-10-05 19:39   ` [bitbake-devel] " Marcel Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261005083628.1451356-1-git@cookiesoft.de \
    --to=git@cookiesoft.de \
    --cc=bitbake-devel@lists.openembedded.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.