Table column widths.

This commit is contained in:
Dominik Pantůček 2023-03-22 15:38:24 +01:00
parent b919898057
commit 8c1db26931
2 changed files with 22 additions and 1 deletions

View file

@ -92,7 +92,23 @@
;; Returns the maximum width of each column of the table.
(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)
row)
@ -140,6 +156,10 @@
(test-equal? table-normalize-row
(table-normalize-row '(("") ("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))
))
)