(lispkit text-table)
Library (lispkit text-table)
provides an API for creating tables of textual content. The library supports column and cell-based text alignment, allows for multi-line rows, and supports different types of row separators.
Overview
A text table consists of one header row followed by regular text and separator rows. As part of the header row, it is possible to specify the text alignment of the header cell, the default text alignment of the corresponding column and a minimum and maximum size of the column (in terms of characters).
The following example shows how text tables are created:
A displayable string representation can be generated via procedure text-table->string
. This is what the result looks like:
API
Symbol representing the text-table
type. The type-for
procedure of library (lispkit type)
returns this symbol for all text table objects.
Returns #t
if obj is a text table object; returns #f
otherwise.
Returns #t
if obj is a valid text table header. A text table header is a proper list of header cells, one for each column of the text table. A header cell has one of the following forms:
"title", just specifying the column title.
("title" halign) where halign is an alignment specifier (i.e. either
left
,right
,center
) that declares how the title is aligned.("title" halign calign) where halign and calign are alignment specifiers. halign declares how the column title is aligned, calign declares how the content in the rest of the column is aligned by default.
("title" halign calign min) where halign and calign are alignment specifiers and min is the minimum size of the column.
("title" halign calign min max) where halign and calign are alignment specifiers and min is the minimum and max the maximum size of the column.
Returns #t
if obj is a valid text table row. A text table row is a proper list of row cells, one for each column of the text table. A row cell has one of the following forms:
"content", just specifying the content of the cell.
("content" align) where align is an alignment specifier (i.e. either
left
,right
,center
) that declares how the content in the row cell is aligned.
Returns a new text table with the given header row. headers is a valid text table header, sep is a separator between header and table rows (i.e. an object for which text-table-separator?
returns #t
) and edges specifies whether the table edges are round (round-edges
) or sharp (sharp-edges
).
Adds a new row to the given text table. row is a valid text table row, i.e. it is a proper list of row cells, one for each column of the text table. A row cell is either a string or a list with two elements, a string and an alignment specifier (i.e. either left
, right
, center
) which declares how the content in the row cell is aligned.
Adds a new row separator to the given table. sep is a separator, i.e. it is either space-sep
, line-sep
, double-line-sep
, bold-line-sep
, dashed-line-sep
, or bold-dashed-line-sep
. The default for sep is line-sep
.
Returns #t
if obj is a valid alignment specifier. Supported alignment specifiers are left
, right
, and center
.
Corresponds to one of the three supported alignment specifiers for text tables.
Returns #t
if obj is a valid text table edges specifier. Supported edges specifiers are no-edges
, round-edges
, and sharp-edges
.
Corresponds to one of the three supported edges specifiers for text tables.
Returns #t
if obj is a valid text table separator. Supported separators are no-sep
, space-sep
, line-sep
, double-line-sep
, bold-line-sep
, dashed-line-sep
, bold-dashed-line-sep
.
Corresponds to one of the seven supported text table separators.
Returns the given text table as a string that can be displayed. border is a boolean argument specifying whether a border is printed around the table.
Last updated