Subject: [bug#69413] [PATCH v2] guix: scripts: pull: prettify channel listing during pull operation.

From: Dale Mellor <[email-masked]>
Date: Sat, 9 Mar 2024 18:22:23 +0000

From: Dale Mellor <[email-masked]>

  * guix/scripts/pull.scm: use pretty-print-table from utils

  * guix/utils.scm: give pretty-print-table optional argument to specify
                    output stream.
---
 guix/scripts/pull.scm | 24 +++++++++++++-----------
 guix/utils.scm        |  4 ++--
 2 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/guix/scripts/pull.scm b/guix/scripts/pull.scm
index 58d3cd7e83c..c5296cf80a1 100644
--- a/guix/scripts/pull.scm
+++ b/guix/scripts/pull.scm
@@ -882,17 +882,19 @@ (define (no-arguments arg _)
                            (N_ "Building from this channel:~%"
                                "Building from these channels:~%"
                                (length instances)))
-                   (for-each (lambda (instance)
-                               (let ((channel
-                                      (channel-instance-channel instance)))
-                                 (format (current-error-port)
-                                         "  ~10a~a\t~a~%"
-                                         (channel-name channel)
-                                         (channel-url channel)
-                                         (string-take
-                                          (channel-instance-commit instance)
-                                          7))))
-                             instances)
+                   (pretty-print-table
+                    (map-in-order (lambda (instance)
+                                    (let ((channel
+                                           (channel-instance-channel instance)))
+                                      (list (symbol->string (channel-name channel))
+                                            (channel-url channel)
+                                            (string-take
+                                             (channel-instance-commit instance)
+                                             7))))
+                                  instances)
+                    #:max-column-width 100   ;; URLs can be long.
+                    #:left-pad 2
+                    #:output (current-error-port))
                    (parameterize ((%guile-for-build
                                    (package-derivation
                                     store
diff --git a/guix/utils.scm b/guix/utils.scm
index 29ad09d9f72..39a34134457 100644
--- a/guix/utils.scm
+++ b/guix/utils.scm
@@ -1192,7 +1192,7 @@ (define* (string-closest trial tests #:key (threshold 3))
 ;;; Prettified output.
 ;;;
 
-(define* (pretty-print-table rows #:key (max-column-width 20) (left-pad 0))
+(define* (pretty-print-table rows #:key (max-column-width 20) (left-pad 0) (output #t))
   "Print ROWS in neat columns.  All rows should be lists of strings and each
 row should have the same length.  The columns are separated by a tab
 character, and aligned using spaces.  The maximum width of each column is
@@ -1211,7 +1211,7 @@ (define* (pretty-print-table rows #:key (max-column-width 20) (left-pad 0))
                               (map (cut min <> max-column-width)
                                    column-widths)))
          (fmt (string-append (string-join column-formats "\t") "\t~a")))
-    (for-each (cut format #t "~v_~?~%" left-pad fmt <>) rows)))
+    (for-each (cut format output "~v_~?~%" left-pad fmt <>) rows)))
 
 ;;; Local Variables:
 ;;; eval: (put 'call-with-progress-reporter 'scheme-indent-function 1)
-- 
2.41.0