On this page:
2.1 Specification syntax
spec-head-template/  c
spec-head-template-of
spec-template/  c
spec-template-of
spec-head/  c
split-spec
expand-head-spec
extend-head-spec
expand-spec
2.2 SGR Styles
sgr-color-name/  c
sgr-rgb/  c
sgr-color/  c
sgr-style-flag/  c
sgr-intensity/  c
sgr-underline/  c
sgr-style-spec/  c
parse-sgr-color
parse-sgr-style
2.3 Alignment
halign-spec/  c
valign-spec/  c
alignment-spec/  c
halign/  c
valign/  c
overflow-spec/  c
overflow/  c
alignment
empty-alignment
parse-alignment-spec
merge-alignments
column-widths-spec/  c
2.4 Cell Borders
borders
no-borders
merge-borders-overlay
borders-spec/  c
borders-spec->borders
invert-borders
8.12

2 Styles🔗ℹ

All style categories share the same syntax and semantics of how they are applied to the table cells. Currently there are three priority levels where each successive level overrides whatever was set up in the previous levels. The levels - from least important to most important - are:

Support for setting style of individual cells will be added in some future release!

The row settings therefore override everything else.

For borders, there is one special setting #:table-border which affects the outside borders of bordering cells of the table. The same effect can be achieved with style templates, but it is a convenient feature to be able to specify the table frame directly.

The style categories are:

Of course, any SGR sequences within the content of the cell (even at the very beginning of it) override anything specified in the styles passed to print-table. The specified SGR style is just a #:initial-state for any SGR processing procedures used.

2.1 Specification syntax🔗ℹ

 (require uni-table/private/spec-syntax) package: uni-table

Minimalistic syntax to allow easy specification of fixed or variable repetitions in style, alignment, or border specifications - both for rows and columns. The specification language contains three types of tokens:

Without actual style specifications, the syntax can be expanded directly:

> (expand-spec '(2 (heavy) (light dashed) ... (light) (heavy)) 8)

'((heavy) (heavy) (light dashed) (light dashed) (light dashed) (light dashed) (light) (heavy))

> (expand-spec '((light)) 8)

'((light) (light) (light) (light) (light) (light) (light) (light))

These expansions are used by table-transform to make the rows’ and the columns’ style specifications of the same length as the number of rows and columns in transformed table.

Matches a list with the following criteria:

Example: '(2 (heavy) (light))
Returns a contract matching a list based on the same criteria as spec-head-template/c where the list? is replaced with more specialized contract c.
Matches a list that starts with spec-head-template/c and optionally contains '... somewhere after which another spec-head-template/c can be matched.

Example: '(2 (heavy) (light) ... (dashed) 3 (dashed heavy))

procedure

(spec-template-of c)  flat-contract?

  c : flat-contract?
Returns a contract matching a list based on the same criteria as spec-template/c where the list? is replaced with more specialized contract c.
Just a list of lists. Generated by expanding spec-head-template/c.
Splits spec-template/c into the head and tail parts.

procedure

(expand-head-spec spec)  spec-head/c

  spec : spec-head-template/c
Expands all the repetitions in the spec according to given counts.

Example: '(2 (heavy) (light)) expands to '((heavy) (heavy) (light))

procedure

(extend-head-spec spec target-length)  spec-head/c

  spec : spec-head/c
  target-length : exact-integer?
Extends given spec-head/c to target-length length by repeating the last element. If spec is already long enough, it is returned as-is.

procedure

(expand-spec spec target-length)  (listof list?)

  spec : spec-template/c
  target-length : exact-nonnegative-integer?
Expands given spec spec-template/c by expanding its head and tail spec-head-template/c parts and then extending the head part to meet the target-length minimal length criteria.

2.2 SGR Styles🔗ℹ

 (require uni-table/private/sgr-style) package: uni-table

This module implements a very small domain-specific language (DSL) for ECMA-48 SGR state notation. Full specification can be found in the source of sgr-style-spec/c, which is a recursive flat-contract? implementing the following DSL:

 

style

 ::= 

spec ...

 

spec

 ::= 

ground

 

  |  

color

 

  |  

flag

 

  |  

intensity

 

  |  

underline

 

ground

 ::= 

#:background color

 

  |  

#:bg color

 

  |  

#:foreground color

 

  |  

#:fg color

 

color

 ::= 

byte?

 

  |  

color name accepted by sgr-color-name/c

 

  |  

( exact-nonnegative-integer? from #x000000 to #xffffff )

 

  |  

( byte? byte? byte? )

 

flag

 ::= 

italic

 

  |  

blink

 

  |  

reverse-video

 

  |  

crossed-out

 

  |  

strike-through

 

intensity

 ::= 

bold

 

  |  

half-bright

 

underline

 ::= 

underline

 

  |  

singly-underlined

 

  |  

underlined

 

  |  

single-underline

 

  |  

doubly-underlined

 

  |  

double-underline

Usage examples:

; Red foreground, blue background, underlined italic font
(red italic #:background blue underline)
 
; RGB-specified red foreground, bold crossed-out font
(bold (255 0 0) strike-through)
 
; Bright yellow foreground, red background, doubly-underlined characters
(#:background red #:foreground bryellow doubly-underlined)

Matches ECMA-48 color names including bright versions from both naming conventions. Standard colors:

Standard Colors

Bright Colors

Alternative Bright Names

'black

'brightblack

'brblack

'red

'brightred

'brred

'green

'brightgreen

'brgreen

'yellow

'brightyellow

'bryellow

'blue

'brightblue

'brblue

'magenta

'brightmagenta

'brmagenta

'cyan

'brightcyan

'brcyan

'white

'brightwhite

'brwhite

There is also support for CGA color names in capitalized/CamelCase form: 'Black, 'Blue, 'Green, 'Cyan, 'Red, 'Magenta, 'Brown, 'LightGray, 'LightGrey, 'DarkGray, 'DarkGrey, 'LightBlue, 'LightGreen, 'LightCyan, 'LightRed, 'LightMagenta, 'Yellow, 'White.
Matches a RGB value represented as list?. Two forms are available. The first one represents the RGB triplet as a list of three exact-integer? values from 0 to 255.

For example, full red can be represented as: '(255 0 0)

Alternative notation is one 24-bit value:

The same full red can also be written as: '(#xFF0000).
Matches either sgr-color-name/c, sgr-rgb/c, or any number (integer-in 0 255) for direct representation of basic 8 or extended 16 or 256 indexed colors.
Matches any of the valid style flags:

Multiple symbols indicate multiple alternative names for given flag.
Matches valid intensity specification:

  • 'bold

  • 'half-bright

Matches any of the valid underline specifications:

Multiple symbols indicate multiple alternative names for given underline style.
Matches SGR style specification. This contract describes the whole mini-DSL for SGR state notation.

procedure

(parse-sgr-color spec)  
(or/c (integer-in 0 255)
      sgr-rgb?)
  spec : sgr-color/c
Parses the specification spec and returns sgr-state?-compatible color representation.

procedure

(parse-sgr-style spec)  sgr-state?

  spec : sgr-style-spec/c
Parses given ECMA-48 SGR state specification which allows using this specification as border style or table-cell? initial sgr-state?.

2.3 Alignment🔗ℹ

 (require uni-table/private/cell-align) package: uni-table

This module handles both vertical and horizontal alignment. The cell alignment can be specified as a list? of symbols which represent valid vertical and horizontal alignments or overflow settings. Only the last symbol for each property is taken into account. In addition to these symbols a list containing a single string? will be used as line continuation for line clipping, wrapping and reflow.

Valid horizontal alignments are:

Their meaning is self-explanatory. Valid vertical alignments are:

Overflow settings are:

When applying these to cells, they are parsed (for cells, rows and columns) using parse-alignment-spec and merged in the usual priority like all style specifications using merge-alignments.

Matches valid horizontal alignment specification: 'left, 'center, or 'right.
Valid vertical alignment specification: 'top, 'middle, 'bottom.
A list of alignment specifications.
Valid horizontal alignment or #f.
Valid vertical alignment or #f.
Matches valid overflow behavior: 'wrap, 'reflow, or 'clip.
Matches valid overflow behavior like overflow-spec/c or #f - which behaves like 'wrap when actually used.,

struct

(struct alignment (horizontal vertical overflow continuation)
    #:transparent)
  horizontal : halign/c
  vertical : valign/c
  overflow : overflow/c
  continuation : sgr-list?
Represents alignment in both directions and how the text should (not) overflow.
Empty alignment struct.

procedure

(parse-alignment-spec spec)  alignment?

  spec : alignment-spec/c
Parses cell alignment specification retaining only the last valid specifications for given attribute.

procedure

(merge-alignments orig over)  alignment?

  orig : alignment?
  over : alignment?
Merges two alignments, overriding the settings in orig for non-#f values in over.
Matches spec-template-of a single-item list of exact-nonnegative-ingerer? or empty list meaning dynamic column width. This is used in Transformations to specify fixed column widths.

2.4 Cell Borders🔗ℹ

 (require uni-table/private/cell-border) package: uni-table

This module implements notation for border lines decorating rectangular areas like cells, rows, columns or whole tables. It contains both parsing human-readable borders’ specifications and procedures for merging adjacent and overlaying inherited borders.

The border specification is as follows:

 

style

 ::= 

spec ...

 

spec

 ::= 

side

 

  |  

style

 

side

 ::= 

name style

 

  |  

name ( style ... )

 

name

 ::= 

top

 

  |  

left

 

  |  

right

 

  |  

bottom

 

style

 ::= 

thickness

 

  |  

type

 

thickness

 ::= 

light

 

  |  

heavy

 

type

 ::= 

solid

 

  |  

dashed

These specifications can be parsed into actual borders? struct using borders-spec->borders. The usual merging of cell, column and row borders into final cell borders is done using the merge-borders-overlay procedure.

struct

(struct borders (top left right bottom)
    #:transparent)
  top : line-style?
  left : line-style?
  right : line-style?
  bottom : line-style?
Represents all four border lines of a rectangular area on the screen.
Borders specification without any border lines drawn.

procedure

(merge-borders-overlay orig over)  borders?

  orig : borders?
  over : borders?
Overlays two border specifications. The result is the same as if drawn at the same time.

Merging is performed with merge-line-style in #:relaxed mode.
A flat-contract? matching borders specification. It recognizes line-style-spec/c and the border sides: 'top, 'left, 'right, and 'bottom.

procedure

(borders-spec->borders spec)  borders?

  spec : borders-spec/c
Converts borders specification into actual borders? struct.

procedure

(invert-borders b)  borders?

  b : borders?
Swaps both horizontally and vertically the oposite borders. Left becomes right, top becomes bottom and vice versa.