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.
This commit is contained in:
parent
c7d1b061f5
commit
1812205cf5
|
@ -48,11 +48,19 @@ refers to."
|
||||||
str))
|
str))
|
||||||
|
|
||||||
(define* (display-tabulated lst
|
(define* (display-tabulated lst
|
||||||
#:key (columns 3)
|
#:key
|
||||||
(column-width (/ 78 columns)))
|
(terminal-width 80)
|
||||||
"Display the list of string LST in COLUMNS columns of COLUMN-WIDTH
|
(column-gap 2))
|
||||||
characters."
|
"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 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
|
(define pad
|
||||||
(if (zero? (modulo len columns))
|
(if (zero? (modulo len columns))
|
||||||
0
|
0
|
||||||
|
|
Loading…
Reference in New Issue