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!
cell #:cell- keywords, affects all cells in the table,
column #:column- and #:col- keywords, affects given columns,
row #:row- keywords, affects particular rows.
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:
SGR style - terminal output attributes like color, intensity etc.,
alignment - both vertical and horizontal alignment of text within the cell,
border - cell borders for all its sides, thickness, line style and such.
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:
style specification token - any list?,
exact-positive-integer? numbers before any specificaton token,
the ellipsis ... after any token means the last token should be repeated if the whole specification needs to be extended to longer length than its head and tail expand to. Only one token of this type can be present.
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.
either the element is a list?,
or the element is exact-nonnegative-integer? and the following element is a list?
procedure
c : flat-contract?
value
procedure
c : flat-contract?
value
procedure
(split-spec spec) →
spec-head-template/c spec-head-template/c spec : spec-template/c
procedure
(expand-head-spec spec) → spec-head/c
spec : spec-head-template/c
procedure
(extend-head-spec spec target-length) → spec-head/c
spec : spec-head/c target-length : exact-integer?
procedure
(expand-spec spec target-length) → (listof list?)
spec : spec-template/c target-length : exact-nonnegative-integer?
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› | ::= | |
|
| | | color name accepted by sgr-color-name/c |
|
| | | ( exact-nonnegative-integer? from #x000000 to #xffffff ) |
|
| | | |
| ‹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)
value
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 |
value
For example, full red can be represented as: '(255 0 0)
Alternative notation is one 24-bit value:
value
value
'italic
'blink
'reverse-video
'crossed-out, 'strike-through
value
'bold
'half-bright
value
'underline, 'singly-underlined, 'underlined, 'single-underline
'doubly-underlined, 'double-underline
value
procedure
(parse-sgr-color spec) →
(or/c (integer-in 0 255) sgr-rgb?) spec : sgr-color/c
procedure
(parse-sgr-style spec) → sgr-state?
spec : sgr-style-spec/c
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:
#f - like 'left but can be overridden,
'left,
'center, and
'right.
Their meaning is self-explanatory. Valid vertical alignments are:
#f - like 'top but can be overridden,
'top,
'middle, and
'bottom.
Overflow settings are:
'clip - clip to cell width,
'wrap - wrap character by character to multiple lines of cell width, and
'reflow - wrap to multiple lines of cell width re-flowing the text word by word.
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.
value
value
value
value
value
value
value
struct
(struct alignment (horizontal vertical overflow continuation) #:transparent) horizontal : halign/c vertical : valign/c overflow : overflow/c continuation : sgr-list?
value
procedure
(parse-alignment-spec spec) → alignment?
spec : alignment-spec/c
procedure
(merge-alignments orig over) → alignment?
orig : alignment? over : alignment?
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?
value
procedure
(merge-borders-overlay orig over) → borders?
orig : borders? over : borders?
value
procedure
(borders-spec->borders spec) → borders?
spec : borders-spec/c
procedure
(invert-borders b) → borders?
b : borders?