4 Rendering
These modules handle the table contents and its borders rendering. They use the table transformations to prepare the pre-rendered cells and then output the cells interleaved with Unicode borders as required.
4.1 Table Rendering
(require uni-table/private/table-render) | |
package: uni-table |
This module implements the actual rendering of two-dimensional table - a list of lists - into final multi-line string.
procedure
(table-row->sgr-lines row-cells column-bars border-sgr-state) → sgr-lines? row-cells : table-row? column-bars : (listof boolean?) border-sgr-state : sgr-state?
procedure
(table->sgr-lines tbl border-style-spec) → sgr-lines?
tbl : ut:table? border-style-spec : sgr-style-spec/c
procedure
(print-table tbl [ #:cell-borders cell-borders-spec #:row-borders rows-borders-spec #:column-borders columns-borders-spec #:border-style border-style-spec #:cell-align cell-align-spec #:row-align row-align-spec #:column-align column-align-spec #:cell-style cell-style-spec #:row-style row-style-spec #:column-style column-style-spec #:table-border table-borders-spec #:suppress-newline suppress-newline #:column-widths column-widths-spec]) → void? tbl : table/c cell-borders-spec : borders-spec/c = '() rows-borders-spec : (spec-template-of borders-spec/c) = '() columns-borders-spec : (spec-template-of borders-spec/c) = '() border-style-spec : sgr-style-spec/c = '() cell-align-spec : alignment-spec/c = '() row-align-spec : (spec-template-of alignment-spec/c) = '() column-align-spec : (spec-template-of alignment-spec/c) = '() cell-style-spec : sgr-style-spec/c = '() row-style-spec : (spec-template-of sgr-style-spec/c) = '() column-style-spec : (spec-template-of sgr-style-spec/c) = '() table-borders-spec : borders-spec/c = '() suppress-newline : boolean? = #t column-widths-spec : column-widths-spec/c = '()
procedure
(table->string tbl [ #:cell-borders cell-borders-spec #:row-borders rows-borders-spec #:column-borders columns-borders-spec #:border-style border-style-spec #:cell-align cell-align-spec #:row-align row-align-spec #:column-align column-align-spec #:cell-style cell-style-spec #:row-style row-style-spec #:column-style column-style-spec #:table-border table-borders-spec #:column-widths column-widths-spec]) → string? tbl : table/c cell-borders-spec : borders-spec/c = '() rows-borders-spec : (spec-template-of borders-spec/c) = '() columns-borders-spec : (spec-template-of borders-spec/c) = '() border-style-spec : sgr-style-spec/c = '() cell-align-spec : alignment-spec/c = '() row-align-spec : (spec-template-of alignment-spec/c) = '() column-align-spec : (spec-template-of alignment-spec/c) = '() cell-style-spec : sgr-style-spec/c = '() row-style-spec : (spec-template-of sgr-style-spec/c) = '() column-style-spec : (spec-template-of sgr-style-spec/c) = '() table-borders-spec : borders-spec/c = '() column-widths-spec : column-widths-spec/c = '()
4.2 Table Borders
(require uni-table/private/table-borders) | |
package: uni-table |
This module implements rendering border bars between individual cells in a row and between rows as well. It handles line style and weight merging and when to include space for the border or make cells immediately adjacent.
procedure
(horizontal-cell-pair-has-bar? left right) → boolean?
left : (or/c ut:cell? #f) right : (or/c ut:cell? #f)
procedure
(horizontal-cell-pair->bar left right) → sgr-list?
left : (or/c ut:cell? #f) right : (or/c ut:cell? #f)
procedure
(table-row->column-bars row) → (listof boolean?)
row : table-row?
procedure
(table->column-bars tbl) → (listof boolean?)
tbl : table?
procedure
(table-row->cell-bars row column-bars) → (listof sgr-list?)
row : table-row? column-bars : (listof boolean?)
procedure
(vertical-cell-pair-has-bar? upper lower) → boolean?
upper : (or/c #f ut:cell?) lower : (or/c #f ut:cell?)
procedure
(table-rows-pair->row-bars upper lower) → boolean?
upper : (or/c #f table-row?)
lower :
(if (false? upper) table-row? (or/c #f table-row?))
procedure
(table->row-bars tbl) → (listof boolean?)
tbl : table?
procedure
(vertical-cell-pair->bar upper lower width) → string?
upper : (or/c ut:cell? #f) lower : (or/c ut:cell? #f) width : exact-nonnegative-integer?
procedure
(cell-quad->junction r0c0 r0c1 r1c0 r1c1) → string?
r0c0 : (or/c ut:cell? #f) r0c1 : (or/c ut:cell? #f) r1c0 : (or/c ut:cell? #f) r1c1 : (or/c ut:cell? #f)
The arguments represent cells in the following relative positions:
r0c0
|
r0c1
----
+
----
r1c0
|
r1c1
procedure
(table-rows-pair->bar upper lower column-widths column-bars) → sgr-list? upper : (or/c #f table-row?)
lower :
(if (false? upper) table-row? (or/c #f table-row?)) column-widths : (listof exact-nonnegative-integer?) column-bars : (listof boolean?)
4.3 SGR Formatting
This module handles formatting blocks of texts parsed from CSI SGR streams.
(require uni-table/private/sgr-format) | package: uni-table |
procedure
lst : sgr-list?
procedure
(sgr-lines-width lines) → exact-nonnegative-integer?
lines : sgr-lines?
procedure
(sgr-list-prefix lst width) → sgr-list?
lst : sgr-list? width : exact-nonnegative-integer?
procedure
(sgr-list-split-at lst width) →
sgr-list? sgr-list? lst : sgr-list? width : exact-nonnegative-integer?
procedure
(sgr-line-clip line width [ #:continuation continuation]) → sgr-lines? line : sgr-list? width : exact-nonnegative-integer? continuation : sgr-list? = '()
procedure
(sgr-line-wrap line width [ #:continuation continuation]) → sgr-lines? line : sgr-list? width : exact-nonnegative-integer? continuation : sgr-list? = '()
procedure
(sgr-list-split-at-char lst char) →
sgr-list? sgr-list? lst : sgr-list? char : char?
procedure
(sgr-list-stretch-tab lst target-width) → sgr-list?
lst : sgr-list? target-width : exact-nonnegative-integer?
procedure
(sgr-list-split lst) → (listof sgr-list?)
lst : sgr-list?
procedure
(sgr-list-words-take-width words wanted-width [ #:split-lone split-lone])
→
sgr-list? (listof sgr-list?) words : (listof sgr-list?) wanted-width : exact-nonnegative-integer? split-lone : boolean? = #f
procedure
(sgr-line-reflow line width [ #:continuation continuation]) → sgr-lines? line : sgr-list? width : exact-nonnegative-integer? continuation : sgr-list? = '()
procedure
(sgr-lines-fill-block-vertical lines [ #:width width #:height height #:vertical-align valign #:compact do-compact]) → sgr-lines? lines : sgr-lines? width : (or/c #f exact-nonnegative-integer?) = #f height : (or/c #f exact-nonnegative-integer?) = #f valign : valign/c = #f do-compact : boolean? = #f
procedure
(sgr-lines-fill-block-horizontal lines [ #:width width #:horizontal-align halign #:overflow overflow #:compact do-compact #:continuation continuation]) → sgr-lines? lines : sgr-lines? width : (or/c #f exact-nonnegative-integer?) = #f halign : halign/c = #f overflow : overflow/c = 'wrap do-compact : boolean? = #t continuation : sgr-list? = '()
procedure
(sgr-lines-fill-block orig-lines [ #:width width #:height height #:horizontal-align horiz-align #:vertical-align vert-align #:overflow overflow]) → sgr-lines? orig-lines : sgr-lines? width : (or/c #f exact-nonnegative-integer?) = #f height : (or/c #f exact-nonnegative-integer?) = #f horiz-align : halign/c = #f vert-align : valign/c = #f overflow : overflow/c = 'wrap