From patchwork Sun Dec 11 18:00:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Julien Lepiller X-Patchwork-Id: 45175 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 525BB27BBEC; Sun, 11 Dec 2022 18:03:21 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 4A48C27BBEB for ; Sun, 11 Dec 2022 18:03:20 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p4QfJ-0004Uc-8h; Sun, 11 Dec 2022 13:03:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p4QfH-0004UO-4W for guix-patches@gnu.org; Sun, 11 Dec 2022 13:03:03 -0500 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p4QfG-00043Y-Ko for guix-patches@gnu.org; Sun, 11 Dec 2022 13:03:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1p4QfG-0001HF-2X for guix-patches@gnu.org; Sun, 11 Dec 2022 13:03:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#59975] [PATCH] guix: Show better progress bars. Resent-From: Julien Lepiller Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 11 Dec 2022 18:03:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 59975 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 59975@debbugs.gnu.org X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.16707817344893 (code B ref -1); Sun, 11 Dec 2022 18:03:01 +0000 Received: (at submit) by debbugs.gnu.org; 11 Dec 2022 18:02:14 +0000 Received: from localhost ([127.0.0.1]:47413 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p4QeT-0001Gr-KQ for submit@debbugs.gnu.org; Sun, 11 Dec 2022 13:02:13 -0500 Received: from lists.gnu.org ([209.51.188.17]:57262) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p4QeR-0001Gl-Je for submit@debbugs.gnu.org; Sun, 11 Dec 2022 13:02:12 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p4QeR-0004OT-8f for guix-patches@gnu.org; Sun, 11 Dec 2022 13:02:11 -0500 Received: from lepiller.eu ([2a00:5884:8208::1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p4QeP-0003lg-Jh for guix-patches@gnu.org; Sun, 11 Dec 2022 13:02:11 -0500 Received: from lepiller.eu (localhost [127.0.0.1]) by lepiller.eu (OpenSMTPD) with ESMTP id a16ba8fc for ; Sun, 11 Dec 2022 18:01:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=lepiller.eu; h=date:from :to:subject:message-id:mime-version:content-type; s=dkim; bh=O7f m0eXsaBMEtvC7PQ/S7BlIeHHlH28YtZ06hGe8ec0=; b=Yxu8ZBMp+9GdicLJ9ni PhZSnhJdF1MGm6dliFsWUkrbp2ZiV48ZWCFpOUYCg/av1fylwKJ/RdLsMCpwqNpC wC2XioiJff/QZ3XLhUSEKPujBpyXsFl2UjF4KEuZ8jzO5vvFrBMKvNkVR5YhGSeZ 5YHel3zdT8/nIVWiYLSXJU37txvQ70euBLj8LPN212GfHYzVrZ8Va4lAQWtGkjVr l4qCyg7/Sq85UVEJBY5WkNNpG8h8GhJcwws0ZUgD6mNqfvH/MguSWXPQbOiWBkss IqF/fyxqznipzwuNSoHhxpgaXsxwmSFfPZkuS/vMxDtblIBAVQHdLGsE/EGlHxM4 pQw== Received: by lepiller.eu (OpenSMTPD) with ESMTPSA id 067294c0 (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO) for ; Sun, 11 Dec 2022 18:01:02 +0000 (UTC) Date: Sun, 11 Dec 2022 19:00:59 +0100 From: Julien Lepiller Message-ID: <20221211190059.51c44520@sybil.lepiller.eu> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.30; x86_64-pc-linux-gnu) MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:5884:8208::1; envelope-from=julien@lepiller.eu; helo=lepiller.eu X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches Hi Guix! The attached patch is a small improvement on our progress bars. Instead of our cute ASCII art: 1.2MiB/s 00:04 [### ] 18.5% We get something a little more smooth: 1.1MiB/s 00:04 ▕███ ▏ 17.1% 1.2MiB/s 00:05 ▕███▋ ▏ 20.7% Using unicode characters that can represent 1/8 of a character width. I used port-encoding to detect when the output supports unicode, but maybe there's something more dedicated to figuring that out? When the port encoding is not UTF-8, we fall back to the ASCII version. Thoughts? From c428c80fd628797ae80029a0a22678ef55c68d6c Mon Sep 17 00:00:00 2001 From: Julien Lepiller Date: Sun, 11 Dec 2022 18:51:13 +0100 Subject: [PATCH] guix: Show better progress bars. * guix/progress.scm (progress-bar): When supported, use unicode variant. --- guix/progress.scm | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/guix/progress.scm b/guix/progress.scm index 4f8e98edc0..527bf72839 100644 --- a/guix/progress.scm +++ b/guix/progress.scm @@ -166,16 +166,45 @@ (define current-terminal-columns ;; Number of columns of the terminal. (make-parameter 80)) +(define-record-type* + progress-bar-style make-progress-bar-style progress-bar-style? + (start progress-bar-style-start + (default #\x2595)) + (stop progress-bar-style-stop + (default #\x258f)) + (filled progress-bar-style-filled + (default #\x2588)) + (steps progress-bar-style-steps + (default '(#\x258F #\x258E #\x258D #\x258C #\x258B #\x258A #\x2589)))) + +(define unicode-bar-style (progress-bar-style)) +(define ascii-bar-style + (progress-bar-style + (start #\[) + (stop #\]) + (filled #\#) + (steps '()))) + (define* (progress-bar % #:optional (bar-width 20)) "Return % as a string representing an ASCII-art progress bar. The total width of the bar is BAR-WIDTH." - (let* ((bar-width (max 3 (- bar-width 2))) - (fraction (/ % 100)) - (filled (inexact->exact (floor (* fraction bar-width)))) - (empty (- bar-width filled))) - (format #f "[~a~a]" - (make-string filled #\#) - (make-string empty #\space)))) + (let* ((bar-style (if (equal? (port-encoding (current-output-port)) "UTF-8") + unicode-bar-style + ascii-bar-style)) + (bar-width (max 3 (- bar-width 2))) + (intermediates (+ (length (progress-bar-style-steps bar-style)) 1)) + (step (inexact->exact (floor (/ (* % bar-width intermediates) 100)))) + (filled (quotient step intermediates)) + (intermediate + (list-ref (cons #f (progress-bar-style-steps bar-style)) + (modulo step intermediates))) + (empty (- bar-width filled (if intermediate 1 0)))) + (format #f "~a~a~a~a~a" + (string (progress-bar-style-start bar-style)) + (make-string filled (progress-bar-style-filled bar-style)) + (if intermediate (string intermediate) "") + (make-string empty #\space) + (string (progress-bar-style-stop bar-style))))) (define (erase-current-line port) "Write an ANSI erase-current-line sequence to PORT to erase the whole line and -- 2.38.1