The .tui language
How a Tuimark document is structured, the closed set of tags, common attributes, text, screens and modals, and document versions.
A .tui file is a strict subset of XML that describes what is on the screen: containers, text, and widgets, with their data bindings and the names of the actions they fire. It holds no logic. How things look lives in TCSS, the data in JSON, and what actions do in the host program.
A document
<tui theme="auto" mouse="mouse_enabled">
<style src="theme.tcss"/>
<style>
#title { bold: true; }
</style>
<keymap>
<bind keys="q,ctrl+c" action="quit"/>
</keymap>
<screen id="main" focus="#query">
<!-- containers, text and widgets -->
<modal id="confirm" open="confirm_open">…</modal>
</screen>
<screen id="logs">…</screen>
</tui><tui>is the root. It needs noversion(see versions).themeisdark(the default),light, orauto.mouseturns mouse input on; see the mouse.<style>loads a stylesheet withsrc(relative to the document), or holds one inline. Several are fine; they apply in order.<keymap>holds the<bind>rows: which keys fire which actions. See Keymap, actions and focus.<screen>is a full terminal surface. A document can have several; exactly one is active, the first by default, and the host switches withSet("@screen", "logs").focus="#id"picks the node focused when the screen appears.<modal>is a layer over its screen. Modals come last in their screen (L004otherwise).
XML rules
Tuimark reads well-formed XML and nothing fancier:
- UTF-8, one root, lowercase tag and attribute names, values in double quotes.
- Comments are fine. No namespaces, DTDs, or processing instructions, and no entities beyond
< > & " '. - A document that is not well-formed is
V005;tuimark fmtrefuses it and every other command reports it.
Control characters and ANSI escapes are removed from bound data before it is painted, so data can never repaint the terminal; in the document's own text they are an error (V007).
Versions
You don't write a version. A <tui> without version is the current language: everything in these guides and in the reference is available to it. Tools that need a number for it use 4 (the current member of tuimark catalog, "version": "0.4" in tuimark ir), but there is no version="4": like any value other than 1, 2, or 3 it is V003, and the document is read as version="1".
A document that writes version="1", "2", or "3" is pinned to the meaning it had in tuimark 0.4.1, defaults included, and its dumps do not change. Two kinds of thing are only in the current language.
New vocabulary. A pinned document that uses it gets a diagnostic that ends in (requires a <tui> without version), and the construct does nothing:
- the tags
checkboxandselect, the attributesingleonlistandtable, andindeterminateonprogress(see widgets); {path}in a<button>'s label and body (see bindings);- the tags
include,fragment,template, anduse(composition, below).
Changed behavior. A pinned document is not diagnosed here; it simply keeps the old behavior, and writes by hand what the current language does for you:
- the defaults: layout and the built-in sheet with its focus look;
- the key and focus rules:
esccloses a modal, a modal traps the keymap, andtabsis focusable; ctrl+i,ctrl+j, andctrl+min a keymap areV003in the current language, because a terminal delivers them astabandenter. A pinned document still accepts them, and they never match there either.
The current language also reports L008 and L009, two layout warnings about content a dump shows as gone:
L008: a text cut without an ellipsis;L009: a node that cuts a child on an axis it does not scroll.
The dump marks the node with clipped. When a cut is intended, write wrap: nowrap or overflow: hidden and the warning goes away.
The pinned versions keep the vocabulary they had:
version="1"is the original vocabulary. Its meaning, and its dumps, never change.version="2"accepts everythingversion="1"does, with the same meaning, plus the 0.2 additions: the tagstable,column,tabs,tab,sparkline, andhints;eachon containers; multi-select;class:NAME;theme="auto";@media (theme: …);layout: grid; scrollbars;bar: eighths; the built-inmove-*,check-*, andswitch-toactions; the mouse; andwhenmatching over the focus chain.version="3"isversion="2"plusL008/L009and the 0.3 additions, all additive:row-gapandcolumn-gap;wrap: truncate-startandtruncate-middle;<column priority="N">;<sparkline scale="NAME">;{path}in a<tab>'slabelandshort;<scroll stick="bottom">;<modal focus="#id">; and<keymap when="SEL">. Several<keymap>elements work in every version. See layout, widgets, keymap, actions and focus, and the Go API for each in its usual place, and the tags, CSS properties, and diagnostics reference for the exact rules.
In a version="1" document each 0.2 addition is still recognized, and reported with a message that ends in (requires version="2"); in a version="1" or version="2" one, each 0.3 addition ends in (requires version="3"). Removing the attribute gives the document the whole language. A .tcss file has no version of its own: it is checked against the document that loads it.
The tags
The vocabulary is closed: an unknown tag is V001, not a new widget. The tags reference lists every attribute each tag takes.
| Role | Tag | What it is |
|---|---|---|
| Document | tui | the root |
style | a stylesheet, from src or inline | |
keymap, bind | global keys and one key row | |
screen | a terminal surface; one is active | |
| Layout | col, row | vertical and horizontal flex containers |
box | a generic container, a column by default | |
scroll | a clipping viewport that scrolls its content (axis="y|x|both") | |
spacer | an empty item that takes the free space | |
tabs, tab | a strip of tab labels over the active tab (version 2) | |
| Content | text | text, with {path} interpolation |
rule | a one-cell separator line (axis="x|y") | |
sparkline | a bar chart of a numeric array (version 2) | |
hints | key hints generated from the keymap (version 2) | |
| Interactive | list, item | a focusable list with a cursor; item is its row |
input | a single-line text field | |
checkbox | a toggle with a label (current language) | |
select | one choice from a dropdown list (current language) | |
button | a focusable action | |
progress | a 0–100 bar, or a spinner with indeterminate | |
table, column | rows of an array in columns, with a cursor (version 2) | |
| Overlay | modal | a layer above the screen that traps focus |
| Composition | include, fragment | a file placed into the document, and the root of that file (current language) |
template, use | a reusable piece of markup and the places it is stamped (current language; see below) |
Widgets shows each interactive tag with a rendered example.
Common attributes
Most tags share these:
| Attribute | Meaning |
|---|---|
id | a unique name (V004 on a duplicate). Required on focusable widgets: list, input, button, modal, and in version 2 table, tabs, tab, and in the current language checkbox and select (V012) |
class | space-separated class names for TCSS selectors |
title | text painted on the node's top border, when it has one; may interpolate {path} |
if | path or !path: the node exists only while it is truthy |
hidden, disabled | true, false, path, or !path |
focusable | true lets any node take focus |
on:click, on:focus, … | the name of an action to fire; see actions |
class:NAME | adds class NAME while a path is truthy (version 2); see bindings |
style | inline TCSS declarations; an escape hatch, prefer classes |
width, height, gap, pad, border | presentational shortcuts for the same CSS properties; any stylesheet rule beats them |
An attribute a tag does not take is V002.
Text
<text> holds a template: literal text with any number of {path} interpolations.
<text>{done} of {total} tasks</text>
<text wrap="wrap">{ticket.body}</text>- A
<text>has no element children (V013). - Each line of the body is trimmed, and blank lines at the start and end are dropped, so indentation in the source never reaches the screen. Interior spaces are kept:
mail {folder}keeps its two spaces. For spacing around text, usegap,padding, ormarginon a container. wrapisnowrap(the default: the line is cut at the edge),wrap(word-wrap to the width), ortruncate(cut with…at the end); inversion="3", alsotruncate-start(…at the start, keeping the end of the line — useful for a path) andtruncate-middle(…in the middle, keeping both ends). Without aversion,pre-wrapkeeps every space and line break and wraps at the width: use it for code and diffs.- Width is measured in terminal columns by grapheme cluster: CJK and emoji take two columns, combining accents take none, and a cluster is never split.
Rich text with runs
A <text> paints styled pieces of text when it has runs instead of a body. The host builds the pieces, from markdown for instance, and the document only styles them:
<text id="reply" runs="msg.runs" style="wrap: wrap"/>.code { color: cyan; bold: true; }
text > span.i { italic: true; }{"msg": {"runs": ["Use ", {"text": "go build", "class": "code"}, " and then check the ",
{"text": "go.mod", "class": "code i"}, " file"]}}runsis a path, resolved likebind(througheachandwithaliases, then the data). Its value is an array of runs, a string (one run), ornull(no run). A run is a string, or an object with a stringtextand an optionalclass, a string of class names separated by spaces. Other members are ignored.- Each run is styled as a
span, a child of its text that only the stylesheet sees:span,.code,span.code,text > span, and#reply > span.codeare all selectors that reach it. A span setscolor,background,bold,dim,italic,underline, andreverse; whatever a rule does not set on it is the text's own, and any other property is accepted and ignored. You never write<span>yourself (V001). - The runs are joined into one text, and
wrap,truncate,pre-wrap, andcontent-alignact on that text, so a word that crosses two runs stays one word in two styles. - A run's text is data:
{…}in it is never read, an escape sequence is removed, each tab becomes four spaces, and any other control character but a line feed is removed. A line feed starts a new line. - A
<text runs>takes no body text (V013). A missing path isB003, and a value of the wrong shape isB013, a warning that names the first bad run;tuimark validateneeds--datato check them.tuimark inspect --at X,Yon a cell a run painted adds arunmember with the run's index, text, classes, and style.
<button> takes its label from label or from its body; title and placeholder are templates too, and in the current language so is a button's label or body (label="Save ({plan})"). See bindings for how paths resolve.
Screens and modals
A document with several screens shows one at a time. Only the active screen and its open modals are laid out; the host switches with Set("@screen", "id"), and in version 2 a keymap row can do it with action="switch-to" to="#id".
A modal is open while its open attribute is truthy: true, false, a path, or !path (never {path}). bind on a modal is a shorthand for the same thing; if both are present, open wins. An open modal:
- is laid out above its screen, centered, with a single border by default. Unsized, it is as big as its content in the current language, and 80% × 80% of the screen in a document that writes
version; - traps focus:
tabcycles inside it, and a focus request for a node outside it does nothing; - fires
on:openwhen it opens andon:closewhen it closes, andon:escapewhenescis pressed. In the current languageescon a modal withouton:escapecloses it; - gives focus back to where it was when it closes.
Composing a document from files
Past a screen or two, one file gets long. In the current language an <include src="…"/> places the contents of another file where it stands, so a document can be split by the pieces a person would name: the header, the footer, the keymap.
The included file is a fragment: its root is <fragment>, and the children of that root are what the include inserts. The src is a path relative to the file that writes the include.
<tui>
<style src="theme.tcss"/>
<include src="parts/keys.tui"/>
<screen id="main">
<include src="parts/header.tui"/>
<list id="tasks" each="tasks as t" key="t.id" bind="selected">
<item><text>{t.title}</text></item>
</list>
<include src="parts/footer.tui"/>
</screen>
</tui>
The document then renders as if the fragments' elements were written in place. The styles, the data, and the ids are shared, so #title in header.tui is the same #title a stylesheet or a to="#title" sees:
Tasks
────────────────────────────────────────
write the docs
ship it
q quit n new
- Where an include can stand. Under
<tui>(thekeys.tuiabove), in a<screen>, inside a container, or inside a<keymap>for a fragment of<bind>rows. A fragment may hold several elements, and may include other fragments. - Nothing is global. The fragment carries no attributes of its own (any attribute on a
<fragment>,versionincluded, isV002), and a<fragment>anywhere but the root of an included file isV001. - A fragment checked on its own is checked alone.
tuimark validate parts/header.tuichecks that one file, with its own elements and attributes, and printsok (fragment checked on its own). The<include>elements inside it are checked for their attributes, but no file they name is read, so a broken include is reported when you validate the document that places it. A fragment is not a document:dumpon one reportsV005, "check it through the document that includes it".
$ tuimark validate parts/header.tui
ok (fragment checked on its own)
What can go wrong with an include, all reported where the include stands:
| Code | When |
|---|---|
V006 | the include is a cycle, is outside the file system a LoadFS host gave the document, or cannot be read |
V020 | the file is a stylesheet (use <style src>), or its root is not <fragment> (a whole <tui> document is not a fragment) |
V021 | the expansions would pass the limits: 100000 elements, 16 MiB of placed source, or 256 levels of nesting |
An include that fails inserts nothing, and the rest of the document is still checked. A cycle names the files in the loop:
$ tuimark validate app.tui
error V006 b.tui:3:3 /screen/include include src="a.tui" is an include cycle: app.tui → a.tui → b.tui → a.tui
The limit is there to stop an include that fans out into a tree of includes from filling the memory: it counts what the includes insert, and the first one that would go over inserts nothing and stops later ones from expanding.
<template> and <use> go one step further than a file: a <template id="…"> directly under <tui> or <screen> holds a piece of markup, and each <use template="…" with="path as alias"/> stamps a copy of it, with the data bound to an alias and its ids scoped to the use. A template can also take literal text as props (props="title", <use title="CPU"/>, {$title}) and one <slot/> that receives the content written between <use> and </use>. That is for a piece that repeats, such as a group of fields or a panel. Templates and composition walks through them, with the scoped ids, the diagnostics, and the tools that show what a copy produced; the attributes are in the tags reference.
What is not in the language
On purpose, and permanently:
- No expressions. No arithmetic, comparisons, filters, function calls, or array indexes. Markup has
{path},each,if, and guards; anything computed comes from the host as data. - No pixels. One unit is one terminal cell.
px,em,vhand friends areV003. - No open vocabulary. Tags and properties are a fixed catalog, so an agent cannot invent a widget that silently does nothing.
- No dynamic props, no named slots. A prop is literal text replaced when the document is read, never a path or an expression; a template has one slot, with no name and no fallback content; and a slot cannot stand where content repeats per row. Data goes through
with. - No generated code. A
.tuifile is interpreted at run time; nothing is compiled to Go.
Formatting
tuimark fmt rewrites a document in one canonical shape: two-space indentation, one element per line, attributes in a fixed order (id, class, the class:NAME guards, then the rest), self-closing empty elements, and comments kept in place.
tuimark fmt app.tui # print the formatted document
tuimark fmt app.tui --write # rewrite the file
tuimark fmt app.tui --check # exit 2 when it is not formattedIt works on any well-formed document, even one with diagnostics, so it is safe to run before anything else.
Use Tuimark with AI agents
How a coding agent such as Claude Code or Cursor builds terminal UIs with Tuimark - the AGENTS.md briefing from tuimark agents, the tuimark mcp server, the validate, dump and play loop, and the rules that keep it on track.
TCSS
Tuimark's cell CSS - selectors, specificity, colors and theme tokens, dark, light and auto themes, and @media queries on columns, rows and theme.