summaryrefslogtreecommitdiff
path: root/guix/build/bournish.scm
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2017-05-13 15:41:57 +0200
committerLudovic Courtès <ludo@gnu.org>2017-05-13 16:52:11 +0200
commit1812205cf56011293cdd3c8d522e4154c8e617dd (patch)
tree949ff11f9e62fb0a087035f1e25877a03bc7bacf /guix/build/bournish.scm
parentc7d1b061f5e3fb33085e8dc06431517da5f4abfb (diff)
downloadguix-patches-1812205cf56011293cdd3c8d522e4154c8e617dd.tar
guix-patches-1812205cf56011293cdd3c8d522e4154c8e617dd.tar.gz
bournish: 'ls' adjusts the column width depending on the entries.
* guix/build/bournish.scm (display-tabulated): Remove #:columns and #:column-width parameters. Add #:terminal-width and #:column-gap. Compute COLUMN-WIDTH and COLUMNS.
Diffstat (limited to 'guix/build/bournish.scm')
-rw-r--r--guix/build/bournish.scm16
1 files changed, 12 insertions, 4 deletions
diff --git a/guix/build/bournish.scm b/guix/build/bournish.scm
index 7aa1f8ca00..247a687d80 100644
--- a/guix/build/bournish.scm
+++ b/guix/build/bournish.scm
@@ -48,11 +48,19 @@ refers to."
str))
(define* (display-tabulated lst
- #:key (columns 3)
- (column-width (/ 78 columns)))
- "Display the list of string LST in COLUMNS columns of COLUMN-WIDTH
-characters."
+ #:key
+ (terminal-width 80)
+ (column-gap 2))
+ "Display the list of string LST in as many columns as needed given
+TERMINAL-WIDTH. Use COLUMN-GAP spaces between two subsequent columns."
(define len (length lst))
+ (define column-width
+ ;; The width of a column. Assume all the columns have the same width
+ ;; (GNU ls is smarter than that.)
+ (+ column-gap (reduce max 0 (map string-length lst))))
+ (define columns
+ (max 1
+ (quotient terminal-width column-width)))
(define pad
(if (zero? (modulo len columns))
0