Design spec for morph::tui (include/morph/tui/, sources in src/tui/): the terminal renderer of the view tree
and the frontend that runs an application in a terminal. It renders what a terminal can of every widget of
../ui/backend_contract.md, passes that contract's conformance suite, and runs the
application on one thread through ../ui/frontend.md's seam. The screens are designed for
desktop and web; the terminal is best effort.
- Packaging
- The loop executor
- The frontend
- Widgets
- Layout
- Focus, dialogs and drawers
- Keys and chords
- Pointer and drag
- Field state
- The conformance probe
- Design decisions
- The spotlight
morph_tui (alias morph::tui) is a STATIC library built when MORPH_BUILD_TUI is on (default off). It links
morph and core-cpp's core::tui PUBLIC. With the option on, core-cpp is built with CORE_CPP_WITH_TUI ON and
CORE_CPP_WITH_IMAGES OFF, and libunicode 0.9.3 is found first, else fetched; a fetch runs libunicode's configure,
which downloads the Unicode database. Native builds only: core-cpp builds no core::tui under Emscripten, so the
option is ignored there.
Public headers: backend.hpp (tui::Backend), frontend.hpp (tui::Frontend, FrontendConfig, ShellFactory,
frontendOption, kInterruptExitCode) and loop_executor.hpp (tui::LoopExecutor). They name core::tui types
and no private src/tui/ type.
LoopExecutor : exec::IExecutor runs each posted task in a later turn of one core::net::EventLoop, with itself
current. The frontend's reactive runtime is owned by one, and every bridge handler an application makes takes it as
its callback executor, so replies, timers, sockets and input run on the thread that turns the loop. post may be
called from any thread; a task still queued when the executor is destroyed is dropped, and a task that throws is
logged. It is destroyed on the loop's thread, between turns or from one of its own tasks.
tui::Frontend is named "tui". frontendOption(config) makes it, usable when standard input is a terminal.
run(source):
- builds an
exec::IoLoop{IoLoopDriver::Caller}, aLoopExecutoron it, the terminal (the process's own unlessFrontendConfig::terminalnames one), acore::tui::Screen, aTuiRuntimeover the terminal's input (orFrontendConfig::input), and the session: theui::AppContext, its runtime, its scheduler and thetui::Backend; - runs the source through
ui::runApp: the shell is mounted byFrontendConfig::mountShell, which receives the backend with the context and the source's result; - pumps input until
AppContext::quit, Ctrl+C or SIGINT (exit code 130,kInterruptExitCode), or the end of input (exit code 0); - tears down in reverse: the shell, the source, the session, the input, the screen, the executor, the loop. The process's own terminal is restored.
mountShell must not be empty: run throws std::invalid_argument before the source is opened. The mouse mode is
FrontendConfig::mouse, MouseTracking::Drag by default, which drag-and-drop needs.
Between events: each input event is dispatched once, to the screen, with the loop executor current; the pump then
waits for a later turn, so the flush and the frame the event caused run before the next event is handled. Redraws
are coalesced to one per turn. A frame fits the roots to the screen, gives the focus to the first focusable widget
when nothing holds it, and draws; while a visible busy spins, a timer advances it. Tab and Shift+Tab move the
focus; Esc ends a drag wherever the focus is.
The width class (Backend::widthClass()) is the viewport's columns, classed by ui::widthClassOf, read when asked:
an 80-column terminal is medium. After dispatching a resize the session calls Backend::refreshWidthClass(), which
compares the class with the one last reported and calls the setOnWidthClass listener on a change, outside the draw,
so the re-render comes on the next turn; fit(), which runs inside the draw, never calls it.
Every ui::IViewBackend factory makes a widget whose view is a core::tui::Component it owns.
| Widget | Shows | Input |
|---|---|---|
| Text | one row per line, styled by role: a heading and a headline bold (a cell has one size), a section and an overline bold in the muted style as written (the terminal reads no theme token), muted, caption (the muted style: a cell has one size), label (the normal style), error and success in their theme styles; mono as normal text, since every cell is drawn in one fixed-pitch font. Spans draw run after run in the role's style, a strong run bold, a mono run as the others and a toned run in the tone's foreground; a run's line feed starts the next row, except in a table column whose wrap is false, which lays the runs on one row (a line feed reads as a space) and cuts the run the column ends in with an ellipsis. A text's tone is the text's foreground, with its role's boldness. A text is cut at its width and keeps no minimum |
|
width: the terminal does not wrap it, so it has no unbreakable segment to keep whole. A text's align places each laid-out line within the text's width by alignedOffset: plain lines by their own width, runs by the width of all the runs on their line (paintRuns measures each line first), and a required text's mark right after its line's end. A table or grid gives a text that has an alignment of its own its column's whole width, so the text places its lines |
— | |
| Button | [ label ] ([label] while small or square), a framework icon's glyph before the label (an icon-only button whose icon has no glyph draws its accessible name, so it is never an empty bracket), the caption in the list's selected-item style while selected (the brackets keep the button's style, so a selected push button is as wide as another); a list item label, unbracketed and padded to its slot's width, in the list's selected-item style while selected and the focus style while focused. An item with content holds it as a column, a cell in from its leading edge, paints its line style across every row and the content over it on that background, and takes Enter, Space and a click on any row |
Enter, Space, click |
| TextInput | core::tui::InputField; single-line, multiline or masked; a unit is drawn muted at the right edge before the field marks, and the editable width ends one cell before it; a prefix is drawn muted before the text, after the icon; an end-aligned field draws its text against the right edge while it fits; a prominent one draws its text bold; a multiline field shows each line as written, so setWrap(false) changes nothing; an unfocused, unmasked single-line field whose text is wider than its room is drawn from the start cut with an ellipsis, in the room before the marks (*, !, ~) so none is drawn over the ellipsis, and the probe text keeps the whole value; it builds no hover text, since the whole value is shown once the field is focused |
typing; Enter submits a single-line field after its commit, and a field without a submit handler commits and passes Enter on; the focus leaving after an edit commits |
| Checkbox | [x] label |
Space, click; Enter passes on |
| Select | radio: a row per option, (•) marking; dropdown: [label ▾] opening a list overlay; segmented: one row of the options, each padded by a space and joined by │, the marked one in the list's selected-item style |
Enter, Space, click; arrows in the list; Left and Right on a segmented one, and a click on a segment |
| Menu | one level of entries as a list, > on an entry with a submenu, the mark of a checkable one, its chord, its description muted; a separator a ─ row the cursor skips. Button style: [label ▾], or an icon-only trigger's glyph ([⋯] for more) or else its accessible name |
Right, Enter, Space or a click opens a submenu; Left or Backspace goes up; choosing a leaf shows the top again. Button style: Enter, Space, Down or a click opens the entries as a list overlay, which drills into submenus the same way; a choice, Esc or the focus leaving closes it and gives the focus back to the trigger |
| Stack, Slot | children along an axis (a percent width is that share of the stack's width, rounded down, within the child's bounds, and a content stack counts it at its natural width), a spacing step apart (a row of actions, an overlay's footer, an actionBar or a head's trail, keeps its step 2, one cell: the terminal reads no actions.gap; a horizontal forEach directly in an actionBar is part of the row and is one cell apart too; the head's trail, whose gap was one cell already, is unchanged), inset by the stack's padding mapped to cells as a panel's is, each axis by its own step ([2, 4] is 0 rows and 2 columns); from its first setSelected it reserves its first column for the selection's bar, inside its leading padding when that has a column and as one more column otherwise, and while selected draws ▌ down that column in the list's selected-item style; the column stays reserved while unselected so the content does not move; a scrollable slot whose content is taller than it (or whose stretching child's minHeight is) is a viewport over it that follows the focus, as Scroll is, and takes the focus itself while nothing inside can; a slot whose content fits is not a viewport and is no Tab stop. A tab page pads its own content inside the viewport by its tabs node's page inset (contentInsets), and the node lays each page over the whole area under its bar |
a scrolling slot: arrows, PageUp/PageDown, Home/End, wheel |
| Grid | equal columns, or columns sized by their tracks; cells row-major, spans; with a least column width the columns shown are clamp((width + gap) / (least + gap), 1, columns) cells, and the natural height is computed at the width the grid was last drawn at (paint records it and asks its container to lay out again when it changes), so a grid whose columns drop pushes its siblings down one frame after its width changes, one frame per level for nested grids, as a wrapping row does |
— |
| Spacer | nothing; stretches in a stack | — |
| Panel | a box with a title; a collapsible one folds to its title line | Enter, Space, click on the title |
| Scroll | a viewport that follows the focus | arrows, PageUp/PageDown, Home/End, wheel |
| Tabs | with an inset, the tabs start the step's columns in (step 4: 2 columns) and the pages are padded by its rows and columns, or by a page inset's when the node gives one; the strip's surface draws nothing new, as bar is not inverted. A one-row bar over the page slots, with no blank row under it (a terminal row costs more than the separation earns); a bar narrower than its labels draws whole labels from a first visible one, which painting moves so the highlighted label fits, with ‹ at the start and › at the end while labels are cut there; a hidden bar gives its row to the pages and takes no focus; the theme's tabs.paddingX and tabs.gap are not read, since a label is separated by cells already; moreLabel is stored and not drawn, since the markers already reach every tab |
Left, Right, click on a label; a click on ‹ or › selects the previous or next tab |
| Dialog | a centred box over everything; a description given as runs draws them on the description's row, as a text draws runs; its footer is the box's bottom row, its children against the right edge, one cell apart, and stays last when the content mounts again. As a sheet the box fills the viewport, its top row draws [dismissLabel] before the title, and its footer takes the box's last rows under content that fills the rest |
Esc dismisses; a press on a sheet's [dismissLabel] dismisses as Esc does. A head note is drawn muted on the title's row against its right end, followed by [dismissLabel] while the close control is on and the box is not a sheet; a press on it dismisses as Esc does. A footer note takes a row of its own at the bottom of the box, muted |
| Drawer | a box against its side, the screen's height; its footer as a dialog's | Esc dismisses |
| Busy | a spinner and its label while active | — |
| Table | a header (set apart by its role: the terminal reads no table colour, so color.table.header and color.table.headerRule are not read and no rule is drawn under it) and keyed rows, * on selected rows, > on the cursor; a row's marks (setRowMarks): an unmatched row's cells draw dim, and a busy row shows … and a locked one # in gutter cells of their own after * and >, the glyph and a gap so the ellipsis is not read as a cut, which the gutter gains with the first busy or locked row and keeps, so the columns do not move as rows come and go busy; the marks' tooltip, or without one "Saving this row" or "Locked by another user", is the row's hover text over its own tooltip; with a select column a five-cell gutter, [x] or [ ] per row in place of the *, under a header box [x], [-] or [ ] — a click on a row's box toggles the row as Ctrl+click does, and on the header box is Ctrl+A; a toned row's cells draw in the tone's style, keeping any inverse; the layout solver never squeezes a column below its header's width (a fixed column below its own width), and the columns past the table's edge are cut; a stretch column starts from its content and gives in the contract's four steps (layout::planColumns), in cells, with a 2-cell gutter and 1-cell gaps, a floor of min(header, 4) for a column that may shrink; the least width of a text cell in a wrapping column is its widest word and that of any other cell its natural width, so a text inside a container cell is never narrowed; a row's cells keep their own height and sit at its top, centre (rounded down) or bottom by their column's valign; a text cell cut at its column's width draws an ellipsis in its last cell, on each of its lines (spans too), because the terminal cannot wrap (a mono text outside a table, too); in a column that does not wrap (wrap: false) the spans share one line; a text, a badge, a check box or a push button is drawn at its natural width at its column's start, centre or end by the column's align, and the header's label with it; a text input keeps its text at the start, since core::tui::InputField has no alignment; each header of the sort chain is followed by its mark (ui::sortMarkText: ▲ or ▼, and its place with two or more keys, ▲2), and a sortable column's header keeps room for a one-key mark; a filterable column's header ends in its filter button, ▿, ▾ while setFiltered names it; groups (setColumnGroups) draw a line above the headers, each label over its visible places and ending in its own filter button; with menus the header line keeps its last two cells for a gap and ⋯, which opens the table's menu, so no column's header or filter button lies under it; a menu is a list below the header, as a button-style menu's is, and takes the keys; no drag or resize handle is drawn; a heading row is one cell across every column and their gaps, with nothing in its gutter, and widens no column; a hidden cell widens no column either; a spanning cell (setRowSpans) is drawn once, in its column over the lines of the rows it covers, placed down them by the column's valign (the centre rounded down), and every line of the span, covered rows' included, is drawn in the origin row's style (tone, selection, inverse), the rest of the covered rows in their own; TableImpl places a spanning cell itself, over the union of the covered rows' areas: a view is clipped to its parent's area, so the table lifts the cell's view out of its row into its own while the span holds (its tone, still its origin row's), and returns it when the span goes; the lifted cell is left out of the origin row's natural height and placement, and the table works out which cells span and which are covered from the rows' order at every frame, also before the layout that sizes it (a table holding spans is planned when the screen is fitted), so the frame that lifts a cell is already laid out with the shorter row; a table with no span does no such work; the covered cells widen no column, and when the span's text has more lines than the rows it covers have, the last covered row grows by the shortfall; the table scrolls by row, so with the origin row above the top and covered rows shown the cell is clipped at the table's top edge and placed again within the covered lines still shown, its text showing in the first of them; the cursor, * and [x] stay per row, and a click on a line in a spanning cell's column acts on its origin row, the hit-test taking the column's x as well as the line and covering the whole height of the rows the span covers, not only the lines its content is drawn on (a centred one-line cell leaves blank covered lines, and a click on one is a click on the span); a table over a TableSource (one the mount gives a horizontal-range handler; a long table over rows is told its realized window too, and is no source) draws what the mount realizes: it scrolls over every row of the view, one line each, and draws each realized row on the line of its view index (setRowIndex), a line whose row is not realized blank; each cell in the column setCellColumn gave it, a pooled cell nowhere; once the mount lays the columns out (setColumnWindow) the header and the cells show the window's columns only, at the mount's offsets and widths in cells (tableMeasure: a unit and a monospace character are a cell, a column's padding is its gap, which is the last cell of each, a content column starts at twelve and a shrink column goes down to four cells and its gap); the table reports its headers' and shown cells' natural and least widths, each with the gap, when one grew (setOnColumnMeasured), and the mount fits the stretch columns to the viewport by the contract's four steps, a viewport that is the table's width less the gutter and the menu's room, the pinned ones at the leading edge and the rest scrolling under them; it reports the columns, then the rows, in view before the next frame's layout when a frame found them changed (fit makes the reports, outside the drawing), and at once for the wheel; an Unloaded cell draws ··· and a Failed one ! in its column's alignment in place of its content, neither widening the column; the status line (setStatus), while shown, is the last line: the counts, the state, [Retry] while the state offers it, and the message at the trailing edge |
arrows, Space selects or toggles, Shift+Up and Shift+Down select a range from the anchor, Ctrl+A selects every row or clears them (Multiple), Enter activates; a click selects only its row, Ctrl+click toggles it and Shift+click selects a range where the emulator passes the modifier on (clickWith), and a plain double click activates; a click on a sortable column's header asks to sort by it, Shift with Shift held, and a click on a filter button presses it; a right click on a header opens its menu (WidgetBase::contextPress, the right button's press), and one on another header while a menu is open closes it and opens that header's; while a header can act (a column sorts, or the table has menus or moves columns), Up on the first row (the first view row over a source) focuses the header of the sort chain's first key, or the first visible column, and on it Left and Right move along the visible columns, Enter and Space sort, Shift+Enter and Shift+Space extend, Ctrl+Shift+Left and Ctrl+Shift+Right report a move one place over, Shift+F10 or the menu key opens its menu, and Down returns to the rows; Ctrl+C asks to copy (setOnCopy) and copyText writes an OSC 52 sequence to the terminal; the cursor passes over a heading row, a click on one does nothing, and Ctrl+A, a range and the header box leave it out; over a TableSource the arrows, Home, End, PageUp, PageDown, Ctrl+Home and Ctrl+End move the mount's focused cell (setOnFocusMove), which the view keeps in view, so Left and Right scroll sideways, and Space and Enter act on the focused row; Shift+Up and Shift+Down move it and, in Multiple mode, select from the anchor (the row last clicked or toggled, or the one the focus left) through setOnSelectRange, as a Shift-click does to the row clicked, and Ctrl+A and the header box select every row of the view through it (the mount refuses a range past maxRangeRows), so no range runs over the realized rows alone; a click does not move the mount's focused cell; a click on [Retry] calls setOnRetry's handler |
| DateTimeInput | YYYY-MM-DD[ HH:MM] in the display zone, or its pattern, as wide as the pattern writes, and a field too narrow for its text is cut with an ellipsis before the marks while it has no focus, as a text input is; the stepping keys work on the parsed instant |
typing; Up/Down step |
| Slider | [====|----] value |
Left, Right, Home, End, press and drag on the track |
| FilePicker | a path field, prompted Open: or Save: |
typing; Enter |
| Banner | its text in its tone (spans as a text's, on the one row, a strong run bold, a toned run in its tone's foreground), [ action ] (on a row of its own under the text for a stretched action), [x] when dismissible; under actionStyle link the action is drawn inside the sentence, underlined in the accent, at the run marked action or else after the text, and a click on those cells runs it |
Enter runs the action; Esc or Delete dismisses; a click on either |
| Badge | [text] in its tone, (text) when outlined, a framework icon's glyph before the text; a removable one [text ×], inverse while focused; in a table cell narrower than its natural width the caption is cut with an ellipsis so that the closing bracket stays in the last cell (setElided, set by the table); anywhere else a badge, and a stack or a panel that holds one, is raised to its natural width (contentMinimumWidth), whether sized fixed or percent, so the closing bracket is never cut |
a removable one: Delete, Backspace, Enter or Space while focused, or a click on the × where it is drawn (after an elided caption, too), removes it; a click elsewhere on it focuses it |
| Progress | [####......] 40% and the label; <=> when indeterminate |
— |
| Steps | a row per step: [ ] pending, [>] active, [x] done, [!] failed; the current one accented; unlabelled, the marks in one row joined by ─ that fills the width |
— |
| KeyValue | captions, then the values lined up after the widest, or after captionWidth cells when the node sets it: a caption and its colon longer than that column are cut with an ellipsis, since a cell row cannot wrap (the probe text keeps the whole caption); stacked, each pair two rows, the caption muted over its value, with no rule, since a rule would cost a row per pair and the muted caption already separates them. A toned value draws in its tone's style, bold; a value with spans draws them as a text's. Each pair is one row, so a caption is always on its value's line |
— |
| EmptyState | the title, the explanation, [ action ] |
Enter, click on the action |
| Chart | points and bars in cells, below; its summary, muted and wrapped, when smaller than 20 by 5 cells; content size 40 by 8 | — |
| Splitter | the panes and a handle between each two; without matching sizes a horizontal splitter places each pane by its width sizing (layout::distribute with content as a stretch of weight 1, a percent as a share of the whole width, handles included, and at least one cell), panes of equal weight sharing equally with the cells a division leaves over going to the last; every pane stays within its bounds, a drag included |
dragging a handle; the release reports every size |
| Collapsible | ▾ title (the title bold) with the header beside it, the body below while open |
Enter, Space, click on the title; the header stays live while closed |
| DropZone | a dashed frame around its children | a paste while it has the focus is a drop (see below) |
A chart in cells. The plot fills the widget below yLabel (its own row, when given) and above the points'
labels and the legend. A gutter at the left, at most 8 columns, holds the lines' labels when three or more label
the axis and the ticks' otherwise, right-aligned; with ticks, a line's label is written at the right end of its row,
over the line. A value lands on row round((yMax − y) / (yMax − yMin) × (rows − 1)) of the plot, a position on
column round((x − xMin) / (xMax − xMin) × (columns − 1)). A line is a row of ─ (solid), ╌ (dashed) or ┄
(dotted) in its tone's style, muted for neutral; two lines on one row draw the one of the more severe tone, and its
label. A point is its series' glyph, ●, ■, ▲ or ◆ in token order, in the series colour (color.chart.<n>'s
default as a true colour, since the terminal theme has no chart colours); a marked point is ✕ in its tone's style
with its note two cells after it when it fits; a clipped point is △ on the top row or ▽ on the bottom one. A
point is drawn over a line in the same cell, and of two points in one cell the marked one, else the later. Points
are not joined: a cell is about twice as tall as it is wide, and box characters between cells would draw slopes
that are not there. The points' labels take the row below the plot, each skipped when it would overlap the last one
drawn and the newest always drawn; the legend row (two or more series) is each glyph beside its label. At the
content height a value is placed to within a fraction of the range, so the summary carries what a reader must not
miss, and a document that needs the values shows a table too.
Bars in cells. A Bars series is a run of block characters per position, drawn before the lines and the points.
A group of n Bars series takes n × w columns, w = max(1, ⌊0.8 × barSlot ÷ (xMax − xMin) × (columns − 1) ÷ n⌋)
columns for each series, starting at columnOf(x) − ⌊n × w ÷ 2⌋, series in order from the left. A bar's tip is
c(v) = (rows − 1) × (v − yMin) ÷ (yMax − yMin) + ½ rows above the plot's bottom edge, which is the centre of the row
a tick or a line of value v is on, so a bar at a tick's value ends in that tick's row (a half-height cell, ▄). The
baseline b is 0 clamped into yMin..yMax; its boundary is the bottom edge when b is yMin, the top edge when
it is yMax, else the row boundary nearest c(b), halves upward. The height is round(8 × (c(v) − boundary))
eighths of a row, taken upward for v > b and downward for v < b whatever the rounded sign (the direction is the
sign of v − b), and at least 1 eighth: a nonzero distance from the baseline always shows, and v = b draws nothing.
A cell a bar covers entirely is █; its end cell is ▁ ▂ ▃ ▄ ▅ ▆ ▇ for 1 to 7 eighths covered, counted from the cell's
bottom edge for a bar growing up. A bar growing down covers a cell from its top edge: its end cell is the lower block
of the uncovered eighths with the style's inverse set, so the terminal's own colours fill the part the bar leaves
empty, not a guessed background. A bar is in its series' colour, a marked point's in its tone's style. A cross or
open triangle takes the cell just beyond the tip's cell when that is inside the plot, else the tip's cell (a clipped
bar's triangle is always in the tip's cell; a zero-extent clipped bar's is the cell next to the baseline). A note is
written two cells after the bar's last column on the marker's row when it fits. The reference lines leave the cells a
bar covers alone, their labels over the bars; where bars share a cell the one whose tip is nearer the baseline is in
front, the later series on a tie. The legend marks a Bars series █. The labels under the plot are centred under
the group. Series are told apart by their place in the group and the legend's order, as well as by colour.
A text input, select or date-time input whose caption is shown (setCaption(label, true)) draws it on its own row
above the control, one row taller; without it nothing changes. A radio select's rows, and a dropdown's list, keep
to the rows below the caption.
A terminal has no icon map and no assistive technology: icons, accessible names and roles are kept and not drawn,
and a widget draws on its surface, its own or else its nearest container's: sidebar and toolbar draw every cell
of the widget inverse, set after it paints so a child painting over its container stays inverse, and any other
surface draws as no surface does. A surface changes no size. A surface a screen asks the shell's top bar for (headSurface) is drawn as any other: darkHead is not inverted, so the console's compact top bar is plain cells. The test id is kept for the probe. The tooltip shows on hover.
Files dropped on a terminal. A terminal reports a file dragged onto it as its path pasted. A drop zone takes the
focus, and a paste while it has it is a drop: the text read as paths, separated by whitespace, each quoted with '
or ", or with spaces escaped by \, or as a file:// URI whose %XX escapes are decoded. The contract's rules
then apply: a file outside the accepted extensions, compared without case, or several files when one is taken,
refuse the drop whole.
A cell-based solver. A stack gives Fixed children their amount, Content children their natural extent, each clamped
into its bounds, and shares what is left among Stretch children by weight from zero (layout::distribute). A share
outside its child's bounds is held at the bound and the rest is shared again by weight among the others: each pass
clamps the open shares, holds the children raised to their minimum when the clamping added length, the children cut
to their maximum when it removed length, and every child when it changed nothing, at most one pass per Stretch
child. Three Stretch children of weight 1 in 90 cells, the first with a minimum of 50, get 50, 20 and 20. Minimums
beyond the length are taken from the last child first, down to each child's minimum, and then the stack overflows
and clips. A content-sized spacer counts as a Stretch child of weight 1 and no natural extent (stretchSizingOf).
A container's natural extent along its axis (stackNaturalSize, which a stack, a scroll, a slot, a panel, a collapsible, a footer, a tab list, an overlay and a drop zone call) is the other children's and
the gaps plus, for the Stretch children together, W * max(n / w) rounded up (W the sum of the weights, n a
child's requested extent): each share is then at least its child's natural, and one Stretch child asks for its own.
A splitter sums its panes' naturals (summedNaturalSize): their sizes are its own. A push button's minimum width is its natural width, as a badge's is; a list item has none. A grid places cells
row-major in equal columns, or in columns its tracks size: layout::planGrid gives each track to distribute as a
stack item, a content track's natural width its widest cell that spans only it. A wrapping row
(setWrap) fills lines with layout::planWrap: each child's basis is its natural extent, a Fixed child's amount, or a
Stretch child's minimum (no more than its natural extent when it has one), and a child starts a new line when its basis
and a gap do not fit after those on the line; each line is solved by distribute, a Stretch child's minimum there being
its basis, and a line with no Stretch child places its spare length by justify. A line is as
tall as its tallest child and lines are stepCells(gap, Vertical) apart, so step 1 is a column between children and no
row between lines. The row's natural height is its lines' at the width it was last drawn at: a change of width asks for
another frame. Several roots share the screen as a column, in the order they were made: each takes the
height it asks for, and the last shown one what is left; a single root takes the whole screen.
Across a stack's axis, a Content or Stretch child fills the stack's extent and a Fixed child gets its amount, clamped
into its bounds and then into the space there is (layout::crossExtent): in a column every content child is as wide
as the column, in a row as tall as the row, and one its maximum stops sits at the start. A grid cell, and the one child
of a panel, slot or scroll area, fills its width the same way, and a grid row is as tall as its tallest cell's
requested height clamped into that cell's bounds. A widget's requested size, which a container's natural size sums,
is its natural size clamped into its bounds.
Content that does not fit. The terminal cuts content at its container's edge. It neither reports it nor scrolls a page sideways: it has no diagnostics channel that does not draw over the screen, and a table's columns past its edge cannot be reached.
Bleed. A shown child whose layout says bleed takes the whole width of its container past the padding (bleedAreas): a column's, the inner edges of a panel's frame, a tabs node's, whatever the page inset; its place down the container is unchanged. The terminal clips a child to its parent's area, so a holder stack (setPassesBleed) is laid out by its container over the container's whole span, past the padding (bleedAreas widens it as it does a bleeding child), and pads its own children by the container's bleedColumns instead; its bleeding children then take the holder's whole width.
Alignment. Across the axis a child's alignSelf, else its stack's align, places it (slotOf): under start,
center or end a Content child takes its requested extent instead of the stack's (alignedExtent), every other
child its crossExtent, and one narrower than the space is offset to the start, the centre (rounded down) or the end
(alignedOffset). Along the axis, while no shown child is Stretch, solvedAreas places the spare length by
justify: before the first child, half of it for center and all of it for end; for between, spare / (shown − 1) cells added to every gap and the remainder one cell to each gap from the first. A grid places each cell in its row
the same way by the cell's alignSelf, else the grid's align; across its column the cell fills the width as
before, except that a track with align center or end places a cell drawn at its natural width
(placedAcrossColumn: a text, a badge, a check box, a push button) there, as a table column does.
Spacing. A gap or padding arrives as a spacing step, 0 to 5 (ui::spacingStep), and the container maps it to
cells by axis with layout::stepCells. A cell is about twice as tall as it is wide, so a step is about half as many
rows as columns:
| Step | 0 | 1 | 2 | 3 | 4 | 5 |
|---|---|---|---|---|---|---|
| Rows (vertical) | 0 | 0 | 0 | 1 | 1 | 2 |
| Columns (horizontal) | 0 | 1 | 1 | 2 | 2 | 3 |
A stack's gap is along its axis; a grid has a column gap and a row gap from the same step; a panel's padding is rows at its top and bottom and columns at its sides.
A dialog's or a drawer's box is an overlay shown while it is open and the user could see it. The box on top is modal:
Tab cycles inside it, and neither the pointer nor a key reaches anything behind it. Opening moves the focus inside;
closing hands it back to the widget that had it. Esc inside the open box closes it, and then calls onDismiss, as a
toolkit's dismissal does: an application that keeps it open opens it again. A description is drawn muted on the
first row inside the frame, under the title in the border, then a ─ rule row, and the content is laid out below,
two rows lower; it is one row, clipped at the frame's width like any terminal text, and the box's
accessibleDescription().
A key goes to the focused view and bubbles to its ancestors until one handles it, in the order every backend follows
(backend_contract.md, Chords). A widget's own chords come first: WidgetBase::dispatch,
a field's view and a list's view each try the widget's chords before its own handling of the key. Then the widget's
own handling, and a key it leaves bubbles on to the next ancestor, which tries its chords the same way. The innermost
widget declaring a chord therefore takes it, and a hidden or disabled widget, which takes no key, runs none. A handler
may destroy the widget, so a handled key returns at once; a text input that commits on Enter without submitting lets
the key bubble only while it is still alive.
A chord is modifiers (Ctrl or Control, Alt, Shift, Super, Meta or Cmd) joined by + to one character
or a named key (Enter, Tab, Escape, Space, Backspace, Delete, Insert, Home, End, PageUp,
PageDown, the arrows, F1–F12). Names and letters match without regard to case, the modifiers must be exactly
those pressed, and the lock keys are not modifiers. A capital letter without a reported Shift counts as Shift and
the letter, since a terminal speaking no keyboard protocol reports Shift+S as S.
Mouse reports are SGR, 1-based; a press handled by a widget makes it core::tui's pointer capture target, so the moves
and the release reach it wherever the pointer is. A widget with a drag key arms a drag on a press; the first move a
cell away starts it and shows a label; the drop target is the first widget from the one under the pointer outwards
that the user can reach and that accepts the key, outlined while the pointer is over it. The release drops the key
there. Esc ends a drag with no drop. A terminal without mouse reporting ignores drag and drop.
A field shows its state as marks at the right edge of its control's first row: * required, ! with errors, ~
stale; a field toned err or warn adds ! too, since the terminal draws no outline. Its description takes the
rows under the control, muted or in the tone's style, one per line and clipped at the field's width; the messages,
the description and a text input's unit are its accessibleDescription(), and its hover text follows the tooltip with them. A
captioned field draws its * after its caption instead, as * in the error style, and its caption's width
counts those two cells; a required text draws * after its last line's end, and its natural width counts them, so
in a row it is not drawn over the text's last characters (given less, it is drawn at the right edge). The
messages show on hover, after the tooltip. A read-only field takes the focus and moves its cursor and selection, but
any edit is undone and nothing is reported: no change, submit, commit, toggle or choice. A field draws no input
fill, so a read-only one reads as its text in place, in the normal text colour where a disabled one is muted.
tests/tui/test_tui_conformance.cpp runs every case of ui::testing::conformanceCases() on the terminal backend
with a probe that acts as a user does, through core::tui events dispatched to the screen:
- a click is a press and a release on the first cell the widget was drawn at; a widget never drawn has no cell, and is not clicked;
- typing selects all (Ctrl+Shift+A) and pastes the text, one edit, as a user pasting does;
- a drag is a press on the source, moves, and the release on the target;
- a dismissal is Esc; a table's selection is the cursor moved to each row and Space; a menu entry is a click on each level's row, after Backspace back to the top; files are their quoted paths pasted to the focused drop zone.
It reads back what the widgets show. Run with a probe that drops every input or misreads every text, the suite fails the cases that check them, so its passes say something about the terminal backend.
A page is 10 columns and 6 rows to 25.4 mm (ui::toCells rounds edges): A4 is 83 × 70 cells, drawn inside a one-cell
frame, so the footprint is the sheet plus two columns and rows, at most the container's width. It does not scale. A
viewport narrower than the sheet pans horizontally: the page takes the focus itself while nothing inside can and handles
Left, Right, Home and End, and otherwise follows the focused widget horizontally. A region clips its content and draws …
at the end of the last row of a clipped rectangle. See ui/document_page.md.
- Retained widgets over core::tui components. Each widget owns its view, and the containers lay their children
out in cells.
core::tuiholds raw pointers to components (children, focus, overlays, the pointer capture); a widget clears every one of them before it is destroyed. - One thread. The loop is caller-driven, so input, timers, sockets and bridge callbacks need no locks.
- The shell factory receives the backend.
ui::AppContextnames no renderer, since a frontend that generates its views has none to lend. A terminal renders through retained widgets, so its shell factory is given them. - Best effort. What a terminal cannot show (icons, pixel sizes, OS file drops) is kept or mapped to what it can.
createPopover makes a container that draws its children in flow, under the parent's other children, while it is open and
takes no room while it is closed: the terminal has no floating layer. It takes no focus; Escape is the widgets' own (the
search field handles it), so the popover never reports a dismissal. A button menu's trigger with a detail writes the
detail after the label, joined by a dot, on its one row; a menu entry with heading is drawn disabled.
SpotlightImpl shows a tour's card as a bordered box, an OverlayCore like a dialog's, placed under the target's drawn
rectangle, or over it when there is no room below, clamped inside the screen; with no target shown it is centred. The
rectangle is where the target was last drawn, which a frame only learns by drawing, so after a frame in which the
target appeared or moved the session fits and draws again, up to twice, until the box stands beside it
(Backend::spotlightMisplaced).
Nothing is dimmed: the ringed widget has the reverse video of every cell flipped (Context::spotlit), so one already drawn inverse, a focused
button or an entry on an inverted surface, is marked by losing it. The target is the first widget, in
creation order, whose stored test id matches and that is displayed and outside the card; the spotlight picks again
whenever a test id is set, a widget is made, destroyed, shown or hidden, and at every frame (Context::targetsChanged).
The box is modal and takes the focus when it opens, as a dialog's does, with three differences: the ringed widget still
takes presses and keys (passesThrough); on a waiting step (setTargetFocusable(true)) Tab reaches the ringed widget
after the card's widgets (tabTarget); and Esc is not the box's, the card declares it. Inside the box, a chord that a
container between the focused widget and the box declares is delivered before the focused widget's own key handling,
Enter and Space excepted (WidgetBase::spotlightChord). The ringed widget outside the box is the reverse: while it has
the focus it handles the key first, and the card's chords, on the spotlight or any container inside it, run only for a
key it ignored (WidgetBase::targetChord). A list it opened is a focused component of its own and takes Escape itself.