All skills
msmps avatar

/opentui

@0d61d6d
by Matt Simpsonmsmps/opentui-skill225 stars
9

OpenTUI skill for building terminal user interfaces with the Core, React, or Solid APIs. Use for any TUI task including components, layout, keyboard and keymap handling, animations, and testing.

Use this Skill: https://skilld.dev/gh/msmps/opentui-skill/opentui

This session only. Nothing lands on disk.

referenceskeymapREFERENCE.md

≈1.2k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Keymap (@opentui/keymap)

A host-agnostic key binding, command, and sequence engine for both terminal (OpenTUI) and browser (DOM) hosts. It is a separate package from @opentui/core, shipped as @opentui/keymap, and is pure JavaScript — it imports in Node.js with no Bun and no native FFI required (only creating a native OpenTUI renderer needs FFI).

When to Use

Use keymap when you need declarative, layered keybindings with commands, leader keys, multi-key sequences (dd, <leader>s), counts ({count}j), or ex-style commands — instead of hand-rolling useKeyboard/keyInput handlers.

Install

bun add @opentui/keymap

Entry Points

Import Purpose
@opentui/keymap Main engine: Keymap, key stringifiers, shared types
@opentui/keymap/addons Universal addons (parser stages, metadata, diagnostics, sequences, ex-commands)
@opentui/keymap/addons/opentui Universal addons + OpenTUI base-layout & edit-buffer helpers
@opentui/keymap/extras Config/formatting helpers (commandBindings, createBindingLookup, formatKeySequence, formatCommandBindings)
@opentui/keymap/extras/graph getGraphSnapshot() for debug/graph UIs
@opentui/keymap/testing Fake host + diagnostics for addon tests
@opentui/keymap/opentui OpenTUI terminal host adapter
@opentui/keymap/html DOM host adapter
@opentui/keymap/react React provider/hooks
@opentui/keymap/solid Solid provider/hooks

Quick Start (Terminal)

import { createCliRenderer } from "@opentui/core"
import { createDefaultOpenTuiKeymap } from "@opentui/keymap/opentui"

const renderer = await createCliRenderer()
const keymap = createDefaultOpenTuiKeymap(renderer)

keymap.registerLayer({
  commands: [{ name: "quit", run() { renderer.destroy() } }],
  bindings: [{ key: "q", cmd: "quit" }],
})

Construction options:

  • Bare: new Keymap(host)
  • Host helpers: createOpenTuiKeymap(renderer) / createHtmlKeymap(root)
  • With default addons: createDefaultOpenTuiKeymap(renderer) / createDefaultHtmlKeymap(root)

Binding Shape

A binding has a required key, plus optional fields:

{
  key: "ctrl+x",          // string ("dd", "<leader>s", "{count}j") or stroke object { name: "return", ctrl: true }
  cmd: "quit",            // command name to run
  event: "press",         // "press" (default) | "release"
  preventDefault: true,   // default true
  fallthrough: false,     // default false
  // ...custom addon fields
}

Core API (Keymap instance)

  • Register (each returns a disposer): registerLayer(), registerToken(), registerSequencePattern(), registerLayerFields(), registerBindingFields(), registerCommandFields(), plus parser/expander/transformer/resolver prepend*/append* stages.
  • Dispatch/execute: runCommand(), dispatchCommand(), intercept("key" | "key:after" | "raw", fn).
  • Query: getActiveKeys(options?), getCommands(), getCommandEntries(), getCommandBindings(), getPendingSequence(), hasPendingSequence(), clearPendingSequence(), popPendingSequence().
  • Data/state: setData(name, value), getData(name); events via on("state" | "pendingSequence" | "dispatch" | "warning" | "error", fn).
  • Key helpers: parseKeySequence(), formatKey(), createKeyMatcher(), getHostMetadata(); exported stringifyKeyStroke() / stringifyKeySequence().

Shipped Addons

registerDefaultKeys(), registerLeader(), registerTimedLeader(), registerModBindings(), registerCommaBindings(), registerEmacsBindings(), registerExCommands(), registerNeovimDisambiguation(), registerMetadataFields(), registerEnabledFields(); OpenTUI-specific registerBaseLayoutFallback(), createTextareaBindings(), registerManagedTextareaLayer(), registerEditBufferCommands().

React

import { KeymapProvider, useKeymap, useBindings, useActiveKeys } from "@opentui/keymap/react"

// Provide a pre-created Keymap<Renderable, KeyEvent>, then:
useBindings((keymap) => keymap.registerLayer({ /* ... */ }), [deps])
const active = useActiveKeys()

Exports: KeymapProvider, useKeymap(), useBindings(createLayer, deps?), useActiveKeys(options?), usePendingSequence(), reactiveMatcherFromStore().

Solid

The Solid adapter (@opentui/keymap/solid) exposes an equivalent provider and hooks that consume a pre-created Keymap.

Keymap vs Keyboard

  • Keyboard (keyboard/REFERENCE.md, useKeyboard/keyInput): low-level raw key events. Best for simple, one-off shortcuts.
  • Keymap (this file): declarative layered bindings, commands, sequences, leader keys, and counts. Best for editor-style keymaps and larger apps.

Source: SKILL.md on GitHub

No alerts17d5 checks · Risk SAFE
  • Gen Agent Trust Hub17d

    This skill contains documentation and usage patterns for the OpenTUI framework, designed for building terminal user interfaces across Core, React, and SolidJS. The analysis confirmed that the skill provides legitimate development guidance; no malicious code, persistence mechanisms, or obfuscation were detected. Findings are limited to standard platform capabilities and recommended scaffolding tools.

  • Socket17d

    No alerts

  • Snyk17d

    Risk: LOW · No issues

  • Runlayer7mo

    1/26 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 0d61d6d. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last month.

Steadyupdated last month
Other metadata
metadata
{
  "references": "core, react, solid, components, layout, keyboard, keymap, animation, testing"
}
  • React
  • Testing
  • terminal-ui
  • tui
  • solid
  • components
  • keyboard-input
  • animations
  • layout

README badge

README badge for msmps/opentui-skill

Builds terminal user interfaces with OpenTUI using an imperative core API or React/Solid reconcilers. Covers layout, keyboard handling, animations, components, and testing for full-featured TUI applications.

Generated from the current SKILL.md.

Does this skill cover all three OpenTUI frameworks?
Yes. The skill consolidates the core imperative API, React reconciler, and Solid reconciler. Use the decision tree in the skill to pick the right framework for your task.
How do I start a new OpenTUI project?
Use `create-tui` with options before arguments: `bunx create-tui -t react my-app` (not `bunx create-tui my-app -t react`). Then read the REFERENCE.md for your chosen framework.
What runtime does OpenTUI require?
OpenTUI runs on Bun and uses Zig for native builds. See `./references/core/gotchas.md` for runtime requirements and build guidance.
Can I use `process.exit()` to shut down my TUI?
No. Always use `renderer.destroy()` instead. Calling `process.exit()` directly is a common pitfall covered in `core/gotchas.md`.
How do I apply text styling in React or Solid?
Use nested modifier elements, not props. See `components/text-display.md` for the correct pattern.

Generated from the current SKILL.md. These answers refresh after source changes.