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🔗ℹ
This module implements the actual rendering of two-dimensional table - a list
of lists - into final multi-line string.
| (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? |
Renders a single table-row? into a sgr-lines?
including optional vertical bars between cells - although without
preceeding and following horizontal bars.
(table->sgr-lines tbl border-style-spec) → sgr-lines?
|
| tbl : ut:table? |
| border-style-spec : sgr-style-spec/c |
Converts given table? into a sgr-lines? for
output to terminal.
| (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 = '() |
Prints given table/c two-dimensional table to
(current-output-port). It is possible to use ECMA-48 SGR
codes in the cells independently.
| (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 = '() |
Converts given table/c two-dimensional table to a
formatted string?. It is possible to use ECMA-48 SGR codes in
the cells independently.
4.2 Table Borders🔗ℹ
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.
(horizontal-cell-pair-has-bar? left right) → boolean?
|
| left : (or/c ut:cell? #f) |
| right : (or/c ut:cell? #f) |
Returns #t if there is some kind of border bar present
between the cells left and right. Border cells can
be checked by providing #f instead of the cell outside of the
table.
(horizontal-cell-pair->bar left right) → sgr-list?
|
| left : (or/c ut:cell? #f) |
| right : (or/c ut:cell? #f) |
Returns the character - actually a sgr-list? with
sgr-state? snapshot at the beginning - of border line between
left and right cells. Providing #f instead
of actual ut:cell? allows for easy checking of cells at
the table borders.
(table-row->column-bars row) → (listof boolean?)
|
| row : table-row? |
Returns a list? with boolean? values
representing existence of table border bar at given location. The
resulting list has always one value more than the number of cells in
the input table-row?.
(table->column-bars tbl) → (listof boolean?)
|
| tbl : table? |
Returns a list? with boolean? values
representing existence of table border bar at given location across
all rows of given table?.
(table-row->cell-bars row column-bars) → (listof sgr-list?)
|
| row : table-row? |
| column-bars : (listof boolean?) |
Produces a list of vertical bars between the cells of given row
based on given column-bars (the presence of border bars
around table columns). If no bar is to be emitted at particular
location, the sgr-list? created is empty.
(vertical-cell-pair-has-bar? upper lower) → boolean?
|
| upper : (or/c #f ut:cell?) |
| lower : (or/c #f ut:cell?) |
Returns #t if there is some kind of border bar present
between the cells upper and lower. Border cells can
be checked by providing #f instead of the cell outside of the
table.
(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?)) |
|
|
Returns #t if ther is a bar present between any cells of
the two rows given. Bars before the first and after the last row can
be checked by providing #f as the other row argument.
(table->row-bars tbl) → (listof boolean?)
|
| tbl : table? |
Returns a list? of boolean? values representing
the existence of horizontal bar requirement at the borders of all rows
of given table.
(vertical-cell-pair->bar upper lower width) → string?
|
| upper : (or/c ut:cell? #f) |
| lower : (or/c ut:cell? #f) |
| width : exact-nonnegative-integer? |
Creates a string? of given width containing
copies of a character representing the border between the two cells
given. The character is determined by straight-line-char in
'horizontal mode.
(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) |
Uses merge-line-weight on adjacent edges of given cells
to construct a junction? and passes the result to
junction->char to obtain the junction Unicode character.
The arguments represent cells in the following relative positions:
r0c0 | | | r0c1 |
---- | + | ---- |
r1c0 | | | r1c1 |
| (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?) |
Given two rows or #f in place of one of them, returns the
bar that should be displayed between them. Both the straight lines and
junctions are generated correctly.
4.3 SGR Formatting🔗ℹ
This module handles formatting blocks of texts parsed from CSI SGR
streams.
(sgr-list-width lst) → exact-nonnegative-integer?
|
| lst : sgr-list? |
Returns the width (in characters) of given
sgr-list?. Should be the same as summing lengths of all
string contained in the list.
(sgr-lines-width lines) → exact-nonnegative-integer?
|
| lines : sgr-lines? |
Returns the width in characters of given list of
sgr-list? lines.
(sgr-list-prefix lst width) → sgr-list?
|
| lst : sgr-list? |
| width : exact-nonnegative-integer? |
Returns sgr-list? which is a prefix of given
width of given lst.
| (sgr-list-split-at lst width) | | → | | |
|
| lst : sgr-list? |
| width : exact-nonnegative-integer? |
Splits given sgr-list? lst at position
width returning prefix and suffix sgr-list?s where
prefix is width characters long.
| (sgr-line-clip | | line | | | | | | | | width | | | | | | | [ | #:continuation continuation]) | | → | | sgr-lines? |
|
| line : sgr-list? |
| width : exact-nonnegative-integer? |
| continuation : sgr-list? = '() |
Converts single sgr-list? to a single-line
sgr-lines? containing at most width printable
characters from the source line.
| (sgr-line-wrap | | line | | | | | | | | width | | | | | | | [ | #:continuation continuation]) | | → | | sgr-lines? |
|
| line : sgr-list? |
| width : exact-nonnegative-integer? |
| continuation : sgr-list? = '() |
Converts single sgr-list? to a possibly multi-line
sgr-lines? where each line contains at most width
characters from the source line.
Introduces line-breaks as required whenever the next character
would make the line longer than width.
| (sgr-list-split-at-char lst char) | | → | | |
|
| lst : sgr-list? |
| char : char? |
Splits given sgr-list? into two delimited at first
occurence of given char.
(sgr-list-stretch-tab lst target-width) → sgr-list?
|
| lst : sgr-list? |
| target-width : exact-nonnegative-integer? |
Splits given sgr-list? at #\tab character and
inserts enough space characters between the prefix and suffix that
remain to create a sgr-list? of target-width width.
(sgr-list-split lst) → (listof sgr-list?)
|
| lst : sgr-list? |
Splits given sgr-list? lst at words’ boundaries
returning a list of sgr-list?s representing individual words.
| (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 |
Takes a list of sgr-list?s representing words and returns
a sgr-list? of at most wanted-width width created by
joining words from the beginning of the list. The other value returned
is a list of remaining words.
| (sgr-line-reflow | | line | | | | | | | | width | | | | | | | [ | #:continuation continuation]) | | → | | sgr-lines? |
|
| line : sgr-list? |
| width : exact-nonnegative-integer? |
| continuation : sgr-list? = '() |
Transforms given line into a possibly multi-line
sgr-lines? wher eeach line contains at most width
characters from the source line.
Line-breaks are introduced only at word boundaries.
| (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 |
Ensures given sgr-lines? are at least height
lines long (high), properly aligned based on given valign and
any sgr-list?s introduced are width characters
long. It also ensures the sgr-state? at the beginning of each
line matches the adjacent line SGR state as needed.
| (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? = '() |
Ensures that the width of all given lines is
exactly the width provided.
| (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 |
Ensures that all sgr-list? orig-lines have
exactly given width and the number of returned
sgr-list? lines is exactly height.