On this page:
3.1 Table Structs
table-cell/  c
table-row/  c
table/  c
ut:  cell
empty-table-cell
table-row?
table-column?
table?
ut:  column
ut:  table
3.2 Table Queries
get-ut:  cell-width
get-ut:  cell-height
table-row-height
table-column-width
table-columns-widths
table-rows-heights
table-columns-count
3.3 Table Cell
make-table-cell
ut:  cell-merge-borders
ut:  cell-merge-align
3.4 Transformations
table-row-parse
table-parse
table-prerender
table-transform
8.12

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.

procedure

(get-ut:cell-width cell)  exact-nonnegative-integer?

  cell : ut:cell?
Returns the width in characters of given cell.

procedure

(get-ut:cell-height cell)  exact-nonnegative-integer?

  cell : ut:cell?
Returns the number of character lines in given cell.

procedure

(table-row-height row)  exact-nonnegative-integer?

  row : table-row?
Returns the largest height of all cells in given row.

procedure

(table-column-width column)  exact-nonnegative-integer?

  column : table-column?
Returns the largest weight of all cells in given column.

procedure

(table-columns-widths tbl)

  (listof exact-nonnegative-integer?)
  tbl : table?
Returns a list of column widths.

procedure

(table-rows-heights tbl)  (listof exact-nonnegative-integer?)

  tbl : table?
Returns list of row heights.

procedure

(table-columns-count tbl)  exact-nonnegative-integer?

  tbl : table?
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.

procedure

(make-table-cell content    
  [#:borders borders-spec    
  #:align align-spec    
  #:style style-spec])  ut:cell?
  content : any/c
  borders-spec : borders-spec/c = '()
  align-spec : alignment-spec/c = '()
  style-spec : sgr-style-spec/c = '()
Creates styled ut:cell?.

procedure

(ut:cell-merge-borders cell borders)  ut:cell?

  cell : ut:cell?
  borders : borders?
Merges given borders into given cell’s borders.

procedure

(ut:cell-merge-align cell align)  ut:cell?

  cell : ut:cell?
  align : alignment?
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.

procedure

(table-prerender tbl)  ut:table?

  tbl : ut:table?
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.