Expand description
Core library for Monospace, a toolkit for drawing diagrams with ASCII characters.
This crate is where all domain logic lives: parsing a diagram description, computing a layout on
a character grid, and rendering that grid as text. The first slice of it exists — stamping cells
into a Buffer and render-ing them to text — with an input format, layout and everything
above the buffer still to come.
The crate deliberately carries no dependency on any terminal, command-line or user-interface
concern, so that the same code can later back an interactive application and a WebAssembly
build. That constraint is checked on every commit by compiling this crate for
wasm32-unknown-unknown.
Structs§
- BoxShape
- A box: a position, a size and a stroke, with a fill as an option.
- Buffer
- A window of cells, and a record of which shape decided each of them.
- Connector
- A connector: two endpoints and a stroke.
- Endpoint
- Where a connector ends: a position, the direction it leaves in, and a terminal. See The initial
set and What a terminal writes in
docs/model.md. - Figure
Layer - A sink, a stamp mode and who is stamping, bound together at construction.
- Footprint
- The rectangle a drawing reaches: the smallest and largest coordinates stamped into it.
- Footprint
Sink - A
StampSinkthat measures the stamps passing through it and hands each one on. - Glyph
- What a cell renders to: one extended grapheme cluster, never a control character.
- Glyph
Catalog - Every glyph rule in play. Answering a key is one lookup; nothing about a catalog says which set a rule came from.
- Glyph
Key - The four sides of a glyph rule: a stroke name on each side, or nothing.
- Line
- A line: a position, a length, an orientation and a stroke. It names no glyph of its own — an
end is one arm in the line’s stroke, not a chosen glyph, because an end has to say where the
stroke stops and what may join it there, which an arm does and a literal cannot: a literal
composes as a cell with four
Closedarms, so nothing connects into it and two lines meeting at a shared end could never make the corner they make. - Offset
- A position inside one window, counted from its top-left corner.
- Pos
- An absolute position in the plane a buffer occupies.
- ShapeId
- A shape’s identity: the ordinal a figure is drawn under, and what a buffer records beside each cell that figure decided.
- Size
- The size of a window or a rendered area, in cells.
- Stroke
- The name of a stroke. A stroke has no attributes of its own: it exists only because a cell or a glyph rule mentions it.
- Stroke
Cell - A base stroke, always present, and four arms — one per side.
- Symbol
Cell - A symbol and the style it is drawn in: the value a cell holds and the key its rule is filed under.
- Symbol
Style Name - The name of the style a symbol is drawn in —
solid,outline,arrow. - Text
- A block of text: its lines, each a run of literal glyphs. No position and no stroke.
- Text
Shape - The block, its area’s top-left at
at, each line centred inarea. - Window
- A rectangle in the plane: where it starts and how large it is.
Enums§
- Arm
- What a cell has on one of its four sides.
- Cell
- A cell: either a base stroke with four arms, one chosen glyph, or a named symbol rendered
through the catalog. The three kinds are mutually exclusive — no cell is two and none is
neither — per The cell in
docs/model.md. - Direction
- A way to move across the plane: up, right, down or left.
- Orientation
- Whether a run of cells lies along a row or a column.
- Stamp
Mode - Which side of an already-defined cell decides when a stamp lands on it. See Stamping in
docs/model.md. - Symbol
- A symbol a cell can name: a direction an arrow points in, or a shape a terminal stands on.
- Terminal
- What an endpoint contributes to the cell at its own position. A caller builds a variant as a literal, and reads one back by matching this public field.
Traits§
- Cell
Reader - What a caller reads a cell through: one position, answered from the store behind it.
- Owner
Reader - What a caller reads an owner through: one position, answered from the record behind it.
- Shape
- A value describing a figure.
- Stamp
Sink - What a stamp is handed to: one write operation and no reader.
- Surface
- One write operation and no reader. What a shape draws into.
Functions§
- render
- Renders the rectangle of
windowfromsourceto a string of exactlywindow.size.heightlines, each exactlywindow.size.widthglyphs wide and ending in\n, the last line included. A glyph may be more than one character, so the line is the same rectangle without being the same character count.