Subject: Re: bug#59975: [PATCH] guix: Show better progress bars.

From: Ludovic Courtès <[email-masked]>
Date: Fri, 13 Jan 2023 18:07:42 +0100

Hello!

Julien Lepiller <[email-masked]> skribis:

> 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.

Woow, fancy!  Love it!!  Too bad I was too late to have it under the
Newtonmas tree. 🎄

> 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.

One question: how likely is it that people won’t have a font with those
glyphs to display it correctly?

It would be good to check in xterm, Linux console with some default
font, and GNOME/Xfce terminals with defaults.

(Works for me in xterm and in Emacs, FWIW.)

>>>From c428c80fd628797ae80029a0a22678ef55c68d6c Mon Sep 17 00:00:00 2001
> From: Julien Lepiller <[email-masked]>
> 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.

Please describe all the changes.

> +(define-record-type* <progress-bar-style>
> +  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))

How about just dropping the ‘default’ bits and being explicit here?

> +  (let* ((bar-style (if (equal? (port-encoding (current-output-port)) "UTF-8")
> +                        unicode-bar-style
> +                        ascii-bar-style))

In theory you want to check for Unicode-capable, not UTF-8-encoded.

There are ways to do that (see ‘right-arrow’ in (guix ui)), but it’s
more expensive and trickier, so what you’re doing here is good enough
IMO (I actually did that in (guix scripts weather) too).

> +         (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"

s/format/simple-format/ for slightly better performance.

Otherwise LGTM, thanks!

Ludo’.