Allow generating table as list of strings.

This commit is contained in:
Dominik Pantůček 2023-04-17 22:37:19 +02:00
parent 3739a8d1b0
commit c69b545aa1

View file

@ -29,6 +29,7 @@
table table
( (
*table-border-style* *table-border-style*
table->list
table->string table->string
table-tests! table-tests!
) )
@ -270,8 +271,8 @@
(if cb (sref 2) "") (if cb (sref 2) "")
(if tb (sref 3) ""))) (if tb (sref 3) "")))
;; Converts given table to a string suitable for printing. ;; Converts given table to a list of strings suitable for printing.
(define (table->string tbl . args) (define (table->list tbl . args)
(let ((table (table-prepare tbl))) (let ((table (table-prepare tbl)))
(if (or (null? tbl) (if (or (null? tbl)
(null? (car tbl))) (null? (car tbl)))
@ -315,9 +316,7 @@
3) 3)
res) res)
res))) res)))
(string-intersperse (flatten (reverse res0)))
(flatten (reverse res0))
"\n"))
(let* ((res0 (let* ((res0
(if (or (and row-border (if (or (and row-border
(> idx 0)) (> idx 0))
@ -341,6 +340,12 @@
res1 res1
(add1 idx))))))))) (add1 idx)))))))))
;; Converts into single string
(define (table->string . args)
(string-intersperse
(apply table->list args)
"\n"))
;; Performs module self-tests ;; Performs module self-tests
(define (table-tests!) (define (table-tests!)
(run-tests (run-tests