diff --git a/table.scm b/table.scm index 6436753..7405352 100644 --- a/table.scm +++ b/table.scm @@ -227,14 +227,23 @@ ;; Converts given table to a string suitable for printing. (define (table->string tbl . args) - (let ((table-border (get-keyword #:table-border args (lambda () #f))) - (cell-border (get-keyword #:cell-border args (lambda () #f))) - (border-style (get-keyword #:border-style args (lambda () 'ascii))) - (table (table-prepare tbl))) + (let* ((table-border (get-keyword #:table-border args (lambda () #f))) + (cell-border (get-keyword #:cell-border args (lambda () #f))) + (border-style (get-keyword #:border-style args (lambda () 'ascii))) + (table (table-prepare tbl)) + (stylepair (assq border-style table-borders-lookup)) + (stylevec (if stylepair + (cdr stylepair) + (cdar table-borders-lookup))) + (cell-borders (if cell-border + (map (lambda (idx) + (vector-ref stylevec idx)) + '(4 6 7)) + '("" "" "")))) (string-intersperse (flatten (map (lambda (row) - (table-row->lines row "]" "|" "[")) + (apply table-row->lines row cell-borders)) table)) "\n"))) @@ -300,3 +309,41 @@ '(("a" "bb" "ccc" "") ("" "b" "z" "x")))) (print (table-row-delimiter/styled '(1 2 3 1) (cdr (assq 'unicode table-borders-lookup)) 3)) + +(print "************") +(print + (table->string + '(("a" "bb" "ccc" "") + ("" "b" "z" "x")) + #:table-border #f + #:cell-border #f + )) + +(print "************") +(print + (table->string + '(("a" "bb" "ccc" "") + ("" "b" "z" "x")) + #:table-border #f + #:cell-border #t + #:border-style 'unicode + )) + +(print "************") +(print + (table->string + '(("a" "bb" "ccc" "") + ("" "b" "z" "x")) + #:table-border #t + #:cell-border #f + )) + +(print "************") +(print + (table->string + '(("a" "bb" "ccc" "") + ("" "b" "z" "x")) + #:table-border #t + #:cell-border #t + #:border-style 'unicode + ))