From patchwork Mon Nov 24 13:49:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 760 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1763992205; bh=31vJyaYIJ5U98sWceV7hIQi5vt4qj4qx1e9V7kjtEBI=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=nghwyEy2oHHXX7ONJYdHiXbuCBqcsQdxAMcAVxe5VSaMjDbXvqoQwClUhO5bZ4jP7 8FE+uzRq+1/zvXzoN7lrM4DlYAZCk5szH7MgaFrJSo5vydZAeMt995gZSnTjorRQNK aX2NLvgQ8UPcNtRWDAMBIdL9pUGW577NurTGqNh54FeQxPH8iSMEIC+u4ItMSv0rdo LsrT3reUqnNAMKq3smj7ijtu7Exa/dNoJHjqZpt37/NAUARt9roJGj6YSiJqdeF0cR Tiz4sG1uTNvsEgo5pq9drciWzxO1rxcZg1BK9P1IeKdRrQQLV59RlyY/byZqFXLsoA g2Lxe8uTbTWVQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id C4E686874E for ; Mon, 24 Nov 2025 06:50:05 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id 3LngKyGw4u4I for ; Mon, 24 Nov 2025 06:50:05 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1763992203; bh=31vJyaYIJ5U98sWceV7hIQi5vt4qj4qx1e9V7kjtEBI=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=dKLsLbj7RNKsBHvU6z877IxIw/3jCQ/9i6g8AEkukbhXyUl/HYHzNOBbz5c+tIZjB vHpWOF7PARe+riKKy8S17F3wi293+nenwKLSEqf/NpwKkJwfAtatuAmIAElrsjwXWX 3f8XIMoF1o1xsy7CkSXCXEyFsM6edQNdIQtpNw1KMrIwAehIJcPqFew1Hqo5MWXX9g Y2viMQoKTHGS0630zGN0la0w3L6KdZS2vsMwO83fMNyqyfsJkgSnBP5aTY9xzZ44sW MlUGVCdyz/Cd0pkdecRHB8ZxDxmWJvxXE/ndvLmd4qEO9RYxK0/MYJRGv23j7BriPt HoR8wH4zJQoKw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id BAC0C6873C for ; Mon, 24 Nov 2025 06:50:03 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1763992202; bh=hhBPzIXBXZOkyDbRTmJD+2hKK+2ZJ8MPgYPEqnk+TcE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p0yeUKQUn8rITIk9k2o5oi1MQMCGdqocPAGOYqtSZapsR45e4HRgXpdTwDAoQiXTZ v1Btkt1q5zpCMxCBxIpou1svc7xtd/F0CIK95snc50z7vr1BE5eJ22LyJG/LGhpCLp MFJzF+g2l+rL92mdDAsOD32k6lvoLUCrGWRvcBknz8jaNUX+dSmKvUkK9c2MWtqVmD 963x0itoeu5MkoIB099Rh7zGD7QwmFjAdctpIknUoq7fpg742V+ds2b9dALS8mZGDN hlbxNeT3mlllr4u05Xb4mGo/gEHn5EwiavMf2UOPnwW4xgL9ofAAjSaPz6uI0atdUY GETGFtSand+9g== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 170F168688; Mon, 24 Nov 2025 06:50:02 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id DK_2vagWTUd6; Mon, 24 Nov 2025 06:50:02 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1763992201; bh=peOFa5QTsHhL2EG5awPVqdd7k9qgQHGiEsHAOG3ASwU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CFMuT6ZGxZBijCd6cXbFiSb0HW2w3r6Q/5IUlW4DTzfboxPpVen4I4FBDOnB63Cgt tve7j5Hv+eSyk7Grn1/1KCGpEyye0Uw8iZqTNu8W0NDs86iaAsHKZUMQ5h8Ucm3Azg wTSzAjKCP53mIn+71+M8AeTyOBCqefYuCKwNIYf05Uv7Ffbexog5OMbeW2ZOem00t/ gKG19xscTnjPou5/BSaIqEnVjRpWzktS2/9nryB9kxk9gArj9Wbh884Nc4LuORSyE1 xx2+88cZ2VnfjhP1ekukA8XRJRPMPPXNTCgDQgnZDKRmTZrFjtOf5t1zwgphZrDcRo v7ndjlMNDhOjw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 6BE8A6873F; Mon, 24 Nov 2025 06:50:01 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Mon, 24 Nov 2025 06:49:13 -0700 Message-ID: <20251124134932.1991031-3-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251124134932.1991031-1-sjg@u-boot.org> References: <20251124134932.1991031-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: HLFZYMWKJYJBKHPAPS33IYPDXJCIGERL X-Message-ID-Hash: HLFZYMWKJYJBKHPAPS33IYPDXJCIGERL X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 2/9] u_boot_pylib: Use terminal.tprint() for output in tout List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Refactor tout.py to use terminal.tprint() instead of direct print() calls. This provides better control over output formatting and supports the new stderr parameter. It also reduces code duplication. Co-developed-by: Claude Signed-off-by: Simon Glass --- tools/u_boot_pylib/tout.py | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/tools/u_boot_pylib/tout.py b/tools/u_boot_pylib/tout.py index ca72108d6bc..137b55edfd0 100644 --- a/tools/u_boot_pylib/tout.py +++ b/tools/u_boot_pylib/tout.py @@ -11,8 +11,6 @@ from u_boot_pylib import terminal # Output verbosity levels that we support FATAL, ERROR, WARNING, NOTICE, INFO, DETAIL, DEBUG = range(7) -in_progress = False - """ This class handles output of progress and other useful information to the user. It provides for simple verbosity level control and can @@ -46,11 +44,8 @@ def user_is_present(): def clear_progress(): """Clear any active progress message on the terminal.""" - global in_progress - if verbose > ERROR and stdout_is_tty and in_progress: - _stdout.write('\r%s\r' % (" " * len (_progress))) - _stdout.flush() - in_progress = False + if verbose > ERROR and stdout_is_tty: + terminal.print_clear() def progress(msg, warning=False, trailer='...'): """Display progress information. @@ -58,17 +53,14 @@ def progress(msg, warning=False, trailer='...'): Args: msg: Message to display. warning: True if this is a warning.""" - global in_progress clear_progress() if verbose > ERROR: _progress = msg + trailer if stdout_is_tty: col = _color.YELLOW if warning else _color.GREEN - _stdout.write('\r' + _color.build(col, _progress)) - _stdout.flush() - in_progress = True + terminal.tprint('\r' + _progress, newline=False, colour=col, col=_color) else: - _stdout.write(_progress + '\n') + terminal.tprint(_progress) def _output(level, msg, color=None): """Output a message to the terminal. @@ -81,12 +73,10 @@ def _output(level, msg, color=None): """ if verbose >= level: clear_progress() - if color: - msg = _color.build(color, msg) - if level < NOTICE: - print(msg, file=sys.stderr) + if level <= WARNING: + terminal.tprint(msg, colour=color, col=_color, stderr=True) else: - print(msg) + terminal.tprint(msg, colour=color, col=_color) if level == FATAL: sys.exit(1)