From a4b67e9255ac50750c8f82f6aee8ebc35f8ba2bd Mon Sep 17 00:00:00 2001
From: Steve Sprang
Date: Tue, 9 Jan 2018 14:20:12 -0800
Subject: [PATCH 3/3] ui: Improve output appearance when listing generations.
* guix/ui.scm (display-profile-content-diff): Use pretty-print-table to format output.
(display-profile-content): Likewise.
---
guix/ui.scm | 28 +++++++++++++++-------------
1 file changed, 15 insertions(+), 13 deletions(-)
diff --git a/guix/ui.scm b/guix/ui.scm
index 895179744..32f618f33 100644
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -1334,10 +1334,10 @@ DURATION-RELATION with the current time."
(define (equal-entry? first second)
(string= (manifest-entry-item first) (manifest-entry-item second)))
- (define (display-entry entry prefix)
+ (define (make-row entry prefix)
(match entry
(($ name version output location _)
- (format #t " ~a ~a\t~a\t~a\t~a~%" prefix name version output location))))
+ (list (format #f " ~a ~a" prefix name) version output location))))
(define (list-entries number)
(manifest-entries (profile-manifest (generation-file-name profile number))))
@@ -1348,8 +1348,8 @@ DURATION-RELATION with the current time."
equal-entry? (list-entries new) (list-entries old)))
(removed (lset-difference
equal-entry? (list-entries old) (list-entries new))))
- (for-each (cut display-entry <> "+") added)
- (for-each (cut display-entry <> "-") removed)
+ (pretty-print-table (append (map (cut make-row <> "+") added)
+ (map (cut make-row <> "-") removed)))
(newline)))
(display-diff profile gen1 gen2))
@@ -1357,15 +1357,17 @@ DURATION-RELATION with the current time."
(define (display-profile-content profile number)
"Display the packages in PROFILE, generation NUMBER, in a human-readable
way."
- (for-each (match-lambda
- (($ name version output location _)
- (format #t " ~a\t~a\t~a\t~a~%"
- name version output location)))
-
- ;; Show most recently installed packages last.
- (reverse
- (manifest-entries
- (profile-manifest (generation-file-name profile number))))))
+
+ (define entry->row
+ (match-lambda
+ (($ name version output location _)
+ (list (string-append " " name) version output location))))
+
+ (let* ((manifest (profile-manifest (generation-file-name profile number)))
+ (entries (manifest-entries manifest))
+ (rows (map entry->row entries)))
+ ;; Show most recently installed packages last.
+ (pretty-print-table (reverse rows))))
(define (display-generation-change previous current)
(format #t (G_ "switched from generation ~a to ~a~%") previous current))
--
2.15.1