9.0.0.3
3 Table Representation
These modules contain the internal table representation, utilities to transform any list of lists into it and some queries on these internal structures for further use by the renderer.
3.1 Table Structs
| (require uni-table/private/table-structs) | |
| package: uni-table | |
This module contains all internal structs describing table of pre-rendered cells.
A flat-contract? matching values that can be converted to
table cells. All values are accepted. See table->table
for conversion mechanisms.
A flat-contract? matching a list of table-cell/c values.
A flat-contract? matching a list of table-row/c
rows. They do not need to be of identical length.
struct
(struct ut:cell (lines borders alignment) #:transparent) lines : sgr-lines? borders : borders? alignment : alignment?
Internal representation of table cell as used in this module.
Represents an empty table cell with no text or style attached.
Matches values that are used to represent table rows in this
module.
Currently this is equal to (listof ut:cell?).
Technically the same flat-contract? as
table-row? but with different name to distinguish between the
two.
Matches values that are used to represent table in this
module. The table rows must all have identical length.
Currently this equals to (listof table-row?) with
constraint on identical length of these rows.
struct
(struct ut:column (width) #:transparent) width : (or/c #f exact-nonnegative-integer?)
Contains information about particular ut:table column.
struct
(struct ut:table (rows columns) #:transparent) rows : (listof table-row?) columns : (listof ut:column?)
Contains the table rows (with cells) and information about columns.
3.2 Table Queries
| (require uni-table/private/table-query) | package: uni-table |
This module implements simple queries on internal tables structs.
Returns the width in characters of given cell.
Returns the number of character lines in given cell.
Returns the largest height of all cells in given row.
Returns the largest weight of all cells in given column.
Returns a list of column widths.
Returns list of row heights.
Returns the number of columns in given table.
3.3 Table Cell
| (require uni-table/private/table-cell) | package: uni-table |
This module handles direct manipulation of table-cell? properties.
Creates styled ut:cell?.
Merges given borders into given cell’s borders.
Overrides given alignment over cell’s alignment.
3.4 Transformations
| (require uni-table/private/table-transform) | |
| package: uni-table | |
This module implements transformations from table/c to a well-formed and pre-rendered table? instances.
procedure
(table-row-parse row required-len cell-borders columns-borders cell-align row-align columns-align cell-style-spec row-style-spec columns-style-specs) → table-row? row : table-row/c required-len : exact-nonnegative-integer? cell-borders : borders? columns-borders : (listof borders?) cell-align : alignment? row-align : alignment? columns-align : (listof alignment?) cell-style-spec : sgr-style-spec/c row-style-spec : sgr-style-spec/c columns-style-specs : (listof sgr-style-spec/c)
Ensures table row length by appending cells with given borders
specification at the end using extend-table-row while
converting cells to table-cell? values.
procedure
(table-parse tbl [ #:cell-borders cell-borders-spec #:row-borders rows-borders-spec #:column-borders columns-borders-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-borders table-borders #:column-widths column-widths-spec]) → ut:table? 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) = '() 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 : borders? = no-borders column-widths-spec : column-widths-spec/c = '()
Converts a table/c two-dimensional table into
table? extending row lengths as necessary.
Renders all cells of given table. Assumes it has already been
normalized by parse-table.
procedure
(table-transform tbl [ #:cell-borders cell-borders-spec #:row-borders rows-borders-spec #:column-borders columns-borders-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-borders table-borders #:column-widths column-widths-spec]) → ut:table? 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) = '() 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 : borders? = no-borders column-widths-spec : column-widths-spec/c = '()
Parses the table tbl using table-parse and
renders its cells using table-render.