A diagram block for the terminal renderers: a mermaid fence as rows of
styled text. The mermaid group lays the diagram out and names a style
for each run; this module turns the names into the theme's styles.
A source that gives no picture gives nil here, and the renderer draws the code block instead. That covers a diagram type the group does not draw, a source its parser refuses, and a diagram wider than the room.
A terminal cannot shrink a cell, so a diagram is tried in up to four forms before its source shows: as written, compact, and for a flowchart the same two in its other flow.
Where the terminal shows images, a row's strokes are a strip of pixels under the row's text. Each row carries its own strip. A row is then whole by itself, as a row of box characters is, and a pager that keeps a document as rows scrolls a diagram like text.
| Name | Signature |
|---|---|
| block | block(renderer, source, width, opts) -> rendered |
block(
renderer,source,width,opts) ->rendered
Draw a renderer's diagram fence as a block of text
Returns the picture's rows, each ended by a newline, or nil when the
source gives no picture; the renderer then draws the fence as a code
block. width is the columns the block may take and opts.indent the
blank columns before it; the theme's diagram.block_indent is added to
that. The picture stands bare, with no frame, placed in the room left by
the theme's diagram.align.
The renderer gives the theme, __state.tss, and its cfg: graphics,
hide_images, cell_w and cell_h.
Each run of a row is styled by the TSS element diagram.<style>, where
<style> is the name the mermaid group gave it. THEMES.md lists every
style, under "The diagram object".
Where cfg.graphics is set and cfg.hide_images is not, the strokes are
pixels. A row then opens with a Kitty graphics command that lays its
strip under the row, and the row's text is its labels. cfg.cell_w and
cfg.cell_h give a cell's size in pixels; without them a cell of 10 by
20 is taken, and the terminal fits the strip to the row's cells either
way. A part's fg inks its strokes, as RGB, and its fill, when the
theme gives one, fills its ground.
Elsewhere the strokes are box characters, in the same rows and columns.
opts.flat asks for them whatever cfg says.