all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [bug#30053] [PATCH 1/3] Improve appearance of tabular output.
@ 2018-01-09 22:34 Steve Sprang
  2018-01-09 22:37 ` [bug#30053] [PATCH 2/3] " Steve Sprang
                   ` (2 more replies)
  0 siblings, 3 replies; 23+ messages in thread
From: Steve Sprang @ 2018-01-09 22:34 UTC (permalink / raw)
  To: 30053

[-- Attachment #1: Type: text/plain, Size: 354 bytes --]

I noticed when listing installed or available packages that the output
is often pretty jumbled up because columns in each row have an
inconsistent width.

This series of patches adds a new procedure for printing tabular data
(pretty-print-table) and modifies the code for --list-installed,
--list-available, and --list-generations to utilize it.

-Steve

[-- Attachment #2: 0001-utils-Add-a-procedure-for-pretty-printing-tabular-da.patch --]
[-- Type: text/x-patch, Size: 1724 bytes --]

From 09a6bbb1a8d5d2855cdee06b5937dc3e95b2f401 Mon Sep 17 00:00:00 2001
From: Steve Sprang <scs@stevesprang.com>
Date: Tue, 9 Jan 2018 14:00:11 -0800
Subject: [PATCH 1/3] utils: Add a procedure for pretty printing tabular data.

* guix/utils.scm (pretty-print-table): New procedure.
---
 guix/utils.scm | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/guix/utils.scm b/guix/utils.scm
index 92e45de61..cf1d88d21 100644
--- a/guix/utils.scm
+++ b/guix/utils.scm
@@ -46,7 +46,9 @@
   #:use-module ((ice-9 iconv) #:prefix iconv:)
   #:use-module (system foreign)
   #:re-export (memoize)         ; for backwards compatibility
-  #:export (strip-keyword-arguments
+  #:export (pretty-print-table
+
+            strip-keyword-arguments
             default-keyword-arguments
             substitute-keyword-arguments
             ensure-keyword-arguments
@@ -299,6 +301,24 @@ This procedure returns #t on success."
             #t))))))
 
 \f
+;;;
+;;; Prettified output.
+;;;
+
+(define (pretty-print-table rows)
+  "Print ROWS in neat columns.  All rows should be lists of strings and each
+row should have the same length."
+  (let* ((num-cols   (if (null? rows) 0 (length (car rows))))
+         (col-widths (fold (lambda (row maximums)
+                             (map max (map string-length row) maximums))
+                           ;; Initial max width is 0 for each column.
+                           (make-list num-cols 0)
+                           rows))
+         (col-fmts   (map (cut format #f "~~~da" <>) col-widths))
+         (fmt        (string-join col-fmts "~/")))
+    (map (cut format #t "~?~%" fmt <>) rows)))
+
+\f
 ;;;
 ;;; Keyword arguments.
 ;;;
-- 
2.15.1


^ permalink raw reply related	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2021-07-21 21:44 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-09 22:34 [bug#30053] [PATCH 1/3] Improve appearance of tabular output Steve Sprang
2018-01-09 22:37 ` [bug#30053] [PATCH 2/3] " Steve Sprang
2018-01-09 22:37 ` [bug#30053] [PATCH 3/3] " Steve Sprang
2018-01-11 21:32 ` [bug#30053] [PATCH 1/3] " Ludovic Courtès
2018-01-11 23:32   ` Steve Sprang
2018-01-12 13:28     ` Roel Janssen
2018-01-13 19:59       ` Steve Sprang
2018-01-16 14:16         ` Ludovic Courtès
2018-01-16 23:56           ` Steve Sprang
2021-07-15  5:39           ` Maxim Cournoyer
2021-07-15 17:36             ` [bug#30053] [PATCH 1/3 v2] " Maxim Cournoyer
2021-07-15 20:15               ` bug#30053: [PATCH 1/3] " Maxim Cournoyer
2021-07-21 16:56               ` [bug#30053] " Ludovic Courtès
2021-07-21 21:43                 ` Maxim Cournoyer
2021-07-15 22:05             ` Sarah Morgensen via Guix-patches via
2021-07-16  1:25               ` Maxim Cournoyer
2018-01-12 14:56   ` Danny Milosavljevic
2018-01-12 15:26     ` Leo Famulari
2018-01-12 15:50       ` bug#30087: "guix package -A" hangs with attached package set Danny Milosavljevic
2020-12-03  0:10         ` zimoun
2020-12-22 16:12           ` zimoun
2021-01-11 12:29             ` zimoun
2018-01-13 13:47       ` [bug#30053] [PATCH 1/3] Improve appearance of tabular output Ludovic Courtès

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

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.