Table column widths.
This commit is contained in:
parent
b919898057
commit
8c1db26931
2 changed files with 22 additions and 1 deletions
1
ansi.scm
1
ansi.scm
|
@ -36,6 +36,7 @@
|
||||||
a:default
|
a:default
|
||||||
a:muted
|
a:muted
|
||||||
a:highlight
|
a:highlight
|
||||||
|
ansi-string-length
|
||||||
ansi-tests!
|
ansi-tests!
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
22
table.scm
22
table.scm
|
@ -92,7 +92,23 @@
|
||||||
|
|
||||||
;; Returns the maximum width of each column of the table.
|
;; Returns the maximum width of each column of the table.
|
||||||
(define (table-column-widths tbl)
|
(define (table-column-widths tbl)
|
||||||
'())
|
(if (null? tbl)
|
||||||
|
'()
|
||||||
|
(let ((cws (map
|
||||||
|
(lambda (r)
|
||||||
|
(list->vector
|
||||||
|
(map
|
||||||
|
(lambda (c)
|
||||||
|
(apply max (map ansi-string-length c)))
|
||||||
|
r)))
|
||||||
|
tbl)))
|
||||||
|
(let loop ((ci (sub1 (vector-length (car cws))))
|
||||||
|
(rcws '()))
|
||||||
|
(if (>= ci 0)
|
||||||
|
(loop (sub1 ci)
|
||||||
|
(cons (apply max (map (lambda (r) (vector-ref r ci)) cws))
|
||||||
|
rcws))
|
||||||
|
rcws)))))
|
||||||
|
|
||||||
(define (table-row-normalize-cells row cwidths)
|
(define (table-row-normalize-cells row cwidths)
|
||||||
row)
|
row)
|
||||||
|
@ -140,6 +156,10 @@
|
||||||
(test-equal? table-normalize-row
|
(test-equal? table-normalize-row
|
||||||
(table-normalize-row '(("") ("a" "b")))
|
(table-normalize-row '(("") ("a" "b")))
|
||||||
'(("" "") ("a" "b")))
|
'(("" "") ("a" "b")))
|
||||||
|
(test-equal? table-column-widths
|
||||||
|
(table-column-widths
|
||||||
|
'((("x") ("y") ("zz") ("")) (("a") ("bcde") ("") ("")) (("123") ("2") ("3") ("4"))))
|
||||||
|
'(3 4 2 1))
|
||||||
))
|
))
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue