Table row to list of lines conversion.

This commit is contained in:
Dominik Pantůček 2023-03-22 17:26:26 +01:00
parent 595b26ac50
commit 56815f2b35

View file

@ -162,8 +162,8 @@
;; Table border styles in visual form ;; Table border styles in visual form
(define table-borders-lookup-source (define table-borders-lookup-source
'((ascii '((ascii
"/~,\\" "/=,\\"
"| ||" "] |["
">-+<" ">-+<"
"'~^`") "'~^`")
(unicode (unicode
@ -175,9 +175,27 @@
;; Compiled table borders for rendering ;; Compiled table borders for rendering
(define table-borders-lookup (define table-borders-lookup
(map (lambda (src) (map (lambda (src)
(cons (car src) (apply string-intersperse (cdr src)))) (cons (car src) (string-intersperse (cdr src) "")))
table-borders-lookup-source)) table-borders-lookup-source))
;; Accepts a table row - list of list of strings - and returns a list
;; of lines (list of strings).
(define (table-row->lines row left-border cell-separator right-border)
(if (null? row)
'()
(let yloop ((row row)
(res '()))
(if (null? (car row))
(reverse res)
(yloop (map cdr row)
(cons
(string-append left-border
(string-intersperse
(map car row)
cell-separator)
right-border)
res))))))
(define (table->string tbl . args) (define (table->string tbl . args)
(let ((table-border (get-keyword #:table-border args (lambda () #f))) (let ((table-border (get-keyword #:table-border args (lambda () #f)))
(cell-border (get-keyword #:cell-border args (lambda () #f))) (cell-border (get-keyword #:cell-border args (lambda () #f)))
@ -228,6 +246,9 @@
(("") ("b") ("z") ("x")))) (("") ("b") ("z") ("x"))))
'((("a") ("bb") ("ccc") (" ")) '((("a") ("bb") ("ccc") (" "))
((" ") ("b ") ("z ") ("x")))) ((" ") ("b ") ("z ") ("x"))))
(test-equal? table-row->lines
(table-row->lines '(("a ") ("bb") ("ccc") (" ")) "]" "|" "[")
'("]a |bb|ccc| ["))
)) ))
) )