tuimark

The kit

A copy-paste component kit for Tuimark - one file of templates you include, design tokens and k- component classes, small documents that show each of the 25 components, and a gallery app that shows them all.

The kit is a set of ready-made components for Tuimark: buttons, cards, alerts, a data table, a command palette, dialogs, toasts, and more. It follows the shadcn way: you do not install it, you copy it into your project and own it. There is nothing to import from a registry and nothing to keep in sync; if a card should look different, you edit your copy.

The kit adds no tag, attribute, or CSS property to the language. It is a fragment of <template> elements, two stylesheets, and a few conventions for class names, ids, and action names. It lives in the repository's kit/ directory.

FileHolds
kit/kit.tuithe kit as one fragment: it loads the two sheets, holds the overlays' keys, and has one <template> per component that takes text, data, or content
kit/theme.tcssthe design tokens, dark and light, and the base typography
kit/kit.tcssthe component classes
kit/components/NAME.tuione small, valid document per component: a template in use, or the markup to copy for a class component, with a NAME.sample.json beside it when it binds data
examples/kit-galleryevery component in one app, on six tabs, with a Go host

Using it

Copy kit.tui, theme.tcss, and kit.tcss into a folder of your project (they find each other by their relative paths), include the kit as the first child of your <tui>, and load your own sheet after it:

<tui theme="auto">
  <include src="kit/kit.tui"/>
  <style src="app.tcss"/>
  <screen id="main">
    <col width="1fr" height="1fr" gap="1" pad="1">
      <use template="k-alert" class="warn" title="Quota" icon="!" text="You have used 92% of this month's build minutes."/>
      <use template="k-card" title="Deploy">
        <text class="k-card-title">api-gateway 2.14.0</text>
        <row class="k-card-actions">
          <button id="deploy__go" class="k-btn primary" label="Deploy" on:click="button_deploy"/>
          <button id="deploy__skip" class="k-btn ghost" label="Not now" on:click="button_skip"/>
        </row>
      </use>
    </col>
    <use id="confirm" template="k-confirm" class="danger" with="confirm as d"/>
  </screen>
</tui>

A component that takes text, data, or a body is a template: <use template="k-NAME"> copies it where it stands, and a <use> passes it three kinds of arguments. A component whose rows, columns, or panes read a row alias (a table, a menu, a split pane), or that is one element (a button, a badge, a tabs), is a class: you write the markup and give it the kit's classes.

Props: literal text

A prop is an attribute of the <use> that the template reads: a title, a label, a placeholder, an icon, the limits of a sparkline.

<use template="k-stat" title="CPU" min="0" with="detail.stats.cpu as s"/>
<use template="k-field" id="profile__email" label="Email" placeholder="you@example.com" help="We never share it." with="forms.profile.email as f"/>

A prop is text, never a path: title="{card.title}" is a V003. A title that comes from your data uses the class markup (<box class="k-card" title="{PATH}">, which stays valid next to the template); only the confirm dialog and the log read their title from with. A prop you leave out is an attribute the copy does not write, or an empty text that the kit hides, so k-alert without icon has no icon and no gap. Every template takes a style prop, which lands on the copy's root.

Content: the slot

The templates that have a body take it as the content of the <use>: k-card (the body), k-appbar (the right side), k-alert (more body after its text), k-empty (the call to action) and k-confirm (more body under the question).

<use template="k-card" title="Deploy">
  <text class="k-card-title">{card.heading}</text>
  <row class="k-card-actions">
    <button id="card__open" class="k-btn primary" label="Open" on:click="card_open"/>
  </row>
</use>
<use template="k-empty" icon="◌" title="No deployments yet" text="Push a commit or create one by hand.">
  <button id="deploy__create" class="k-btn primary" label="New deployment" on:click="deploy_create"/>
</use>

The content stays in the place where you wrote it. Its paths are the document's, so the with aliases of the <use> do not exist inside it ({confirm.detail}, not {d.detail}); its ids are yours: you write the full id (deploy__create), and the <use> adds no prefix, so two uses of one template cannot repeat the same id; and its actions are the app's: k-empty has no action of its own, the button and its action are yours. Content in a <use> of a template with no slot is V013, and a template has one slot.

Data: with

with is for data: values, arrays, flags, and the paths a widget writes. A template reads them through the alias: with="quota as a" makes a.value read quota.value, so one template serves any part of your store, and a widget that writes (a field's input, the palette's cursor) writes the path the alias stands for:

{
  "detail": { "stats": { "cpu": { "value": "2.5%", "delta": "avg 3.6%", "hist": [4.3, 4.6, 3.8, 3.2] } } },
  "confirm": { "open": false, "title": "Delete project", "body": "This cannot be undone.", "no": "Cancel", "yes": "Delete" }
}

The confirm dialog's labels are data because one dialog serves several operations (stop, restart, delete): the helper writes them on every open. Flags (the paths a template reads in if, open, or a class:NAME guard) are optional members of the with object: a missing one reads as false, so {"good": true} colors the change green and leaving good out does not. The elements of an array the template repeats, such as the log's lines, still carry every flag. A template that reads two objects takes two aliases: with="palette as p, found as f", and k-kv takes a path to a scalar: with="svc.owner as v".

Variants: class

A variant is a static class on the <use>: <use template="k-alert" class="danger" …/>. It lands on the copy's root, and the kit's rules style the parts from there. When the variant comes from your data instead, a template reads a flag for it (d.danger on the dialog, m.ok, m.warn, and m.danger on the meter).

Size: style

A copy has no id of its own (a <use> is not a node), and the root of most templates has none either, so a rule in your sheet cannot name it (the overlays' root is U__dialog and the log's is U__view). The style prop lands on its root: <use template="k-card" title="Empty state" style="height: 10">. If a media rule needs an id, wrap the copy in an element that has one.

Ids and actions

A template that holds ids needs an id on its <use>, which becomes the prefix of every id in the copy, with two underscores. <use id="confirm" template="k-confirm"> makes confirm__dialog, confirm__no, and confirm__yes, and a field <use id="profile__email" template="k-field"> makes the input profile__email__input. Refer to them by those names from your own markup and host: focus="#profile__email__input", when="#log__view".

The kit's actions are component_verb: dialog_confirm, palette_run, toast_show, form_submit. An action does not say which copy fired it; a host routes by the part of the event's source before the last __, so confirm__yes belongs to the instance confirm, and one handler serves every dialog the document uses.

The kit's keymaps name classes only, never ids, since they land in every document that includes the kit: y and n answer whichever dialog has focus. While a modal is open it traps the keymap, so a key that must also work under one goes in a <keymap when="modal"> of your own. The palette's arrows move the list of your copy, so they name its id and live in your document:

<keymap when=".k-palette">
  <bind keys="down,ctrl+n" action="move-next" to="#palette__list"/>
  <bind keys="up,ctrl+p" action="move-prev" to="#palette__list"/>
</keymap>

Rebranding

The sheets are cascaded together, and where two rules tie the later one wins. That is how you rebrand the kit: every color is a token in :root, so your own sheet only re-declares the ones you want to change.

/* app.tcss, loaded after the kit */
:root { --accent: #e8590c; --focus: #e8590c; }
@media (theme: light) {
  :root { --accent: #c2410c; --focus: #c2410c; }
}

Checking it

The kit itself is checked on its own, and every component document validates and runs, so you can try a component before using it:

tuimark validate kit/kit.tui          # ok (fragment checked on its own)
tuimark validate kit/components/table.tui --data kit/components/table.sample.json
tuimark run kit/components/confirm.tui --data kit/components/confirm.sample.json

Each component file starts with a contract, an XML comment that says what it needs from your store and your host:

k-NAME · Contract: <the props, the with alias and the paths it reads and writes, the slot> · Actions: <named actions> · Keys: <keys> · Requires: <other kit classes>

Tokens

All color lives in :root of theme.tcss, read as $name. The first ten names are the runtime's own required tokens (the same names its built-in themes define); the kit adds the rest.

TokenUse
bg fg muted border panelthe screen, body text, secondary text, idle borders, cards and modals
accent focusthe brand color, and the border or fill of the focused thing
ok warn danger infostatus colors
subtle raised seltertiary text, raised or inset fills, the cursor row of an unfocused list
on-accent on-ok on-warn on-dangertext drawn on a filled color
codeinline code

Selection and focus never rely on a background color alone. A cursor row is also bold, a focused list or table gets a double border and a solid accent bar, and a focused button is inverted and underlined, so all of it still reads under 16 colors.

Conventions

Classes. Every kit class starts with k-: k-card for a component and k-card-title for a part of it. (TCSS has no descendant combinator, only >, so a part cannot be styled as "text inside a card"; each part carries its own class.) A modifier is a second, short class on the same node, such as primary, ok, warn, danger, and it is only ever used next to its component class (k-btn danger, k-badge ok) or as a <use>'s variant, which lands on a k- root. Pick a modifier from your data with class:NAME="path" guards.

Ids are instance__part: a use's id is the instance and the template's ids are the parts. A node that is the whole component keeps the instance name (svc for a table), and so do the singletons of your app (app, status, nav).

Actions are component_verb, a plain identifier. Generic names such as cancel or save are avoided.

Overlays (the dialog, the palette, the help) are modals that close on esc through their on:escape action, and declare their keys in a keymap scoped to their own class, listed before any global keymap (the kit's come first, from the include):

<keymap when=".k-dialog">
  <bind keys="y" action="dialog_confirm"/>
  <bind keys="n" action="dialog_cancel"/>
</keymap>

The dialog's rows have no label: its buttons name the choices, and y and n work while it is open. So the help overlay, which lists every labeled row, never shows them.

Sizes are explicit. Every template's root writes its own size, so a copy is the same size in a screen, a tab, or a column (style changes one copy's); a component that fills a space says so in its class; a tabs writes focusable. The confirm dialog takes the size of its content, up to 60 columns where its text wraps.

Templates in your own markup

A template from the kit is an ordinary template, so everything about <use> holds for it. The confirm dialog, included and used once:

<tui theme="auto">
  <include src="../../../kit/kit.tui"/>
  <screen id="demo">
    <col width="1fr" height="1fr" pad="1">
      <text class="k-title">confirm dialog</text>
    </col>
    <use id="confirm" template="k-confirm" class="danger" with="confirm as d"/>
  </screen>
</tui>

The include's path points at the kit in this repository; use the path of your copy. The dialog's y key routes to the copy that has focus:

$ tuimark play kit-dialog.tui --data ../../../kit/components/confirm.sample.json --cols 60 --rows 12 --input y
1 dialog_confirm confirm__no {} null

The source is confirm__no, the button the template's focus="#no" put the cursor on (the safe one), so one dialog_confirm handler serves every dialog the document uses.

Chat and inline components

Three templates serve a chat, whether it runs on the alternate screen or inline in the terminal's scrollback. Like the rest of the kit they add nothing to the language: their block schema is a pattern, not part of it.

k-composer is the box a message is typed in: a rule, a textarea, and the key hints of your keymap. with="composer as c" reads c.draft, which the textarea writes and the host clears after a send, and the optional flag c.disabled. It fires composer_change and composer_submit, both with the text as value. Use it as <use id="composer" …/>: the textarea is composer__input, which a focus= and a when="#composer__input:focus" name. It is one row when empty and grows with its text up to eight rows, so in an inline screen the region grows with it.

<use id="composer" template="k-composer" placeholder="Message the model" with="composer as c"/>

k-block is one block of a transcript. with="b as blk" reads blk.runs, an array of strings and {text, class} runs, and five optional boolean flags that read as false when missing, with no diagnostic: code (a code block, which keeps its line breaks, tabs, and spaces: wrap: pre-wrap), head, quote, item, and rule. The classes k-strong, k-em, and k-code style a run. A transcript is one <use template="k-block" with="b as blk"/> per element of an array of {id, runs, …}, and the schema is what markdownToBlocks in examples/host-ts produces from markdown. The same use shows the unfinished tail in a live region and, as a committed template, each finished block in the scrollback.

k-receipt is what a tool did: a bordered box with its call as the title, its output, and a status line. with="call as r" reads r.title, r.status, r.output, and the flags r.ok and r.err. The output is shown with runs, not with a {path}: a {path} removes a tab, and run text makes it four spaces, so an ls -l keeps its columns.

k-composer stands in for the textarea of the composer guide in a document of its own: it passes the same behavior as a bare textarea (typing, line breaks, submitting, up and down through the lines before the keymap), with the ids, the action names, and one more row above and below it that the template brings.

Components

ComponentUseIn one line
badgeclass k-badgea short status label, with a modifier for its color
buttonclass k-btnprimary, secondary, danger and ghost, inverted when focused
cardtemplate k-carda bordered panel with a title that takes the focus color while it holds focus
key / valuetemplate k-kva muted label and a value on one row, for a card of facts
alerttemplate k-alerta callout with an icon, in four status colors
app bartemplate k-appbara one-row bar docked to the top
status barclass k-statusbara one-row bar docked to the bottom, with filled segments
key hintsclass k-hintsthe keymap's labeled rows as a row of hints
confirm dialogtemplate k-confirma modal that puts the cursor on the safe button
form fieldtemplate k-fielda label, an input, help text and an error line, with invalid styling
empty statetemplate k-emptyan icon, a title, a line of help and a call to action, centered
data tableclass k-tablea table with a header, right-aligned numbers and columns that hide by priority
menuclass k-menua navigation list with icons, shortcuts and optional check marks
tabsclass k-tabsa tab strip bound to a path
labeled progresstemplate k-metera label, a value and a bar in eighths
stattemplate k-stata KPI card with a change and a sparkline
toasttemplate k-toasta one-row notice that never moves the page
command palettetemplate k-palettea modal with an input over a filtered list
help overlaytemplate k-helpa modal that lists every labeled key
split paneclass k-splita list beside a detail card, stacked on a narrow terminal
log paneltemplate k-loga scrolling log that follows its end
breadcrumbtemplate k-breadcrumbthe current path, down to the last crumb on a narrow terminal
composertemplate k-composera message box that grows with its text, with the key hints of your keymap
transcript blocktemplate k-blocka paragraph, heading, quote, list item, code block, or rule made of runs
tool receipttemplate k-receiptwhat a tool did: its call, its output kept as runs, and a status line

Markup has no expressions, so a few components lean on the host: the palette's filtered list and the split pane's detail are computed with Derive, and a toast is cleared by an Every tick. The contract comment of each file says which, and the helpers below do the common ones for you.

Helpers

A component is markup, and markup has no expressions. Expiring a toast, filtering the palette, validating a form and routing a dialog's answer have to happen in the host. The kit ships that code as helpers: small files in Go and in TypeScript that write the store paths the components read. Like the components, you copy them and own them. They are not a package: kit/go is a nested module named tuimarkkit, with no dot in its name so that go get cannot fetch it, and kit/ts has no published name.

To use one, copy its file into your project. In Go, change package kit to your package; a helper imports only github.com/abdul-hamid-achik/tuimark. In TypeScript, copy the .ts file next to your parent; it imports only types from @thelacanians/tuimark. A file that needs another says so in its header: dialog and form need route, and palette needs filter. Each helper has a test beside it. The Go tests of toasts, form, dialog, palette and sortpage load the real component documents and drive them; the others, and the TypeScript tests, run against the store alone.

HelperWhat it doesWrites
routeInstance(source) and Part(source): the two halves of an instance__part idnothing
toastsPush(kind, text, ttl) into a capped queue that shows one toast at a time and expires themtoast.show, .text, .is_ok, .is_warn, .is_danger
filtersubstring or fuzzy match over an array of objects, by named fields{items, any, count, total} at a path you choose
sortpagecycle the sort of a column (with an arrow in its title) and paginate (1–50 of 340)the sorted rows of the page, and a meta object
formper-field rules (required, pattern, length, your own function) on change and on submitforms.<form>.<field>.error, forms.<form>.valid
dialogConfirm(instance, title, body, onConfirm) opens a k-confirm copy and routes dialog_confirm / dialog_cancel by instance<instance>.open, .title, .body, .yes, .no, .result
palettea registry of commands (title, key hint, function) behind the palettepalette.commands, found, palette.open, .query, .cur, .last
asyncLoad(path, fn) runs slow work off the handler<path>.loading, .error, .data
formatBytes, Duration, Relative, Percent, Thousandsstrings ready for {path}

The dialog's button labels are Confirm and Cancel unless the request names its own (Yes and No in Go, yes and no in TypeScript): an empty label means the default, and both are written on every open, so an earlier question's labels never stay. The dialog helper writes a dialog's data at the path named by its instance, the part of the event's source before the last __, which is the <use>'s id, so the use's with path is that id: <use id="confirm" template="k-confirm" with="confirm as d"/>.

The palette helper writes the palette's state only where the store has none. Its title and its input's placeholder are props of the <use> (title="Command palette" placeholder="type a command…"), not data, so it writes neither.

The Go API has Derive and Every and the TypeScript host does not, so two things differ. In Go, filter and sortpage are derived values that follow every store write, and a toast expires on an Every tick. In TypeScript you call recompute() after a write, the palette's input fires palette_query on every change so the parent can, and toasts.start() runs the tick on a timer.

A toast queue, in Go:

ts, _ := kit.NewToasts(app, kit.ToastOptions{Max: 5, TTL: 3 * time.Second})
ts.Register()                       // toast_dismiss (esc)
stop := ts.Start(time.Second)       // app.Every(time.Second, ts.Tick)
defer stop()

ts.Push("ok", "Settings saved", 0)  // info, ok, warn or danger; 0 is the default time to live

The same, in TypeScript:

const toasts = createToasts(ui, { max: 5, ttl: 3000 });
toasts.register();
const stop = toasts.start(500);
await toasts.push("ok", "Settings saved");

A form is named by the id prefix of its fields, <use id="profile__name" template="k-field" label="Name" with="forms.profile.name as f"/> and <use id="profile__email" …/>, whose inputs fire form_validate from profile__name__input and profile__email__input. In Go:

forms := kit.NewForms(app)
forms.Add("profile").
    Field("name", kit.Required("Name is required.")).
    Field("email", kit.Required("Email is required."), kit.Pattern(emailRE, "Enter a full address.")).
    OnSubmit(func(v map[string]string) error { return save(v) }).
    Reset(nil)                      // writes each field's value and error, and the form's valid
forms.Register()                    // form_validate, form_submit

Reset writes only forms.profile.<field>.value and .error and forms.profile.valid. A field's label, placeholder, and help are props of its <use>, not data.

A rule is a function from the value to the message to show ("" when it is fine), so a custom rule is a plain function. Submitting shows every error and moves focus to the first invalid input.

Sorting by clicking a column header (<column on:click="table_sort">, with title="{svc_meta.titles.name}" so the arrow shows) needs the mouse on (<tui mouse="…">); for the keyboard, bind keymap rows to your own action that cycles the column.

examples/kit-gallery includes the kit and shows every component together, with a Go host that implements the actions and routes them by instance. See it on the Examples page, or run the view alone with fixed answers for every action:

tuimark run examples/kit-gallery/app.tui --data examples/kit-gallery/sample.json --mock examples/kit-gallery/mock.json

The mock opens and closes the dialogs and shows toasts; filtering the palette, validating the form and appending to the log need the Go host (go run ./examples/kit-gallery).

Edit on GitHub

Last updated on

On this page