docs: update skill documentation with upstream repo (#3)

* fix(patterns): replace process.exit() with renderer.destroy() in react patterns

process.exit() violates Critical Rule #2 which states you must never call
it directly. Instead, use renderer.destroy() to properly clean up the
renderer and exit gracefully.

* docs(containers): add focusable prop and auto-focus behavior to Box

Documents the focusable prop on Box which allows boxes to receive focus
via mouse click. Includes controlled focus state example and notes about
focus bubbling and preventDefault behavior.

* docs(react/api): add focusable, themeMode, and theme_mode event

- Documents renderer.themeMode property for detecting terminal theme
- Adds theme_mode event listener example for reactive theme changes
- Adds focusable and focused props to Box component
- Adds paddingX/Y and marginX/Y axis shorthand props to Box

* docs(solid/api): add focusable, themeMode, and enhance useSelectionHandler

- Documents renderer.themeMode property and theme_mode event
- Adds focusable and focused props to Box component
- Adds paddingX/Y and marginX/Y axis shorthand props
- Expands useSelectionHandler docs with Selection API details
- Notes that useSelectionHandler is Solid-only

* docs(components): add markdown component and axis shorthand props

- Adds markdown component to component table and chooser
- Documents paddingX/Y and marginX/Y axis shorthand properties
- Updates Code & Diff category to include markdown

* docs(config): add autoFocus renderer option to react configuration

Documents the autoFocus option that controls whether clicking on a
focusable element automatically focuses it. Default is true.

* docs(config): add autoFocus renderer option to solid configuration

Documents the autoFocus option that controls whether clicking on a
focusable element automatically focuses it. Default is true.

* docs(keyboard): clarify usePaste is Solid-only, add OSC 52 clipboard API

- Notes that usePaste hook is only available in Solid, not React
- Documents copyToClipboardOSC52, clearClipboardOSC52, isOsc52Supported
- Adds ClipboardTarget enum usage for X11 clipboard targets
- Shows Selection.copyToClipboard() convenience method

* docs(code-diff): add onHighlight callback and markdown component

- Documents onHighlight callback for intercepting/modifying highlights
- Adds full Markdown component section with Core/React/Solid examples
- Includes renderNode custom rendering and streaming mode docs

* docs(skill): add markdown to decision tree and product index

Updates the display content decision tree and component categories
to include the markdown component.

* docs(layout): add axis shorthand spacing examples

Documents paddingX/Y and marginX/Y shorthand props with examples
showing horizontal and vertical spacing patterns.

* docs(containers): add axis shorthand to Box spacing section

Adds paddingX/Y and marginX/Y to the spacing props example to
show the axis shorthand options alongside individual side props.

* docs(gotchas): document expanded signal handling

Lists all signals handled by OpenTUI for automatic cleanup including
SIGPIPE, SIGBUS, SIGFPE, SIGHUP, and SIGBREAK.

* docs: add See Also sections to keyboard, animation, and testing references

These three cross-cutting REFERENCE.md files were navigation dead-ends
with no outbound links to related content. Adds cross-references so
agents can discover related APIs, components, and patterns.

* docs(skill): add keyboard and animation to Reading Order section

These two reference areas were only discoverable via the decision trees
further down. Adding them to the Reading Order ensures agents following
the prescribed path don't miss them.
This commit is contained in:
Matt Simpson
2026-02-15 19:20:08 +00:00
committed by GitHub
parent 860be00bc6
commit 87c512939f
14 changed files with 363 additions and 14 deletions
+5 -2
View File
@@ -43,6 +43,8 @@ Cross-cutting concepts in `./references/<concept>/` have `REFERENCE.md` as the e
- Building components -> `api.md` + `components/<category>.md`
- Setting up project -> `configuration.md`
- Layout/positioning -> `layout/REFERENCE.md`
- Keyboard/input handling -> `keyboard/REFERENCE.md`
- Animations -> `animation/REFERENCE.md`
- Troubleshooting -> `gotchas.md` + `testing/REFERENCE.md`
### Example Paths
@@ -85,7 +87,8 @@ Display content?
├─ ASCII art banner/title -> components/text-display.md (ascii-font)
├─ Code with syntax highlighting -> components/code-diff.md
├─ Diff viewer (unified/split) -> components/code-diff.md
└─ Line numbers with diagnostics -> components/code-diff.md
├─ Line numbers with diagnostics -> components/code-diff.md
└─ Markdown content (streaming) -> components/code-diff.md (markdown)
```
### "I need user input"
@@ -185,7 +188,7 @@ For component naming differences and text modifiers, see `components/REFERENCE.m
| Text & Display | `./references/components/text-display.md` | text, ascii-font, styled text |
| Containers | `./references/components/containers.md` | box, scrollbox, borders |
| Inputs | `./references/components/inputs.md` | input, textarea, select, tab-select |
| Code & Diff | `./references/components/code-diff.md` | code, line-number, diff |
| Code & Diff | `./references/components/code-diff.md` | code, line-number, diff, markdown |
## Resources
@@ -422,3 +422,10 @@ useEffect(() => {
return () => clearInterval(interval)
}, [])
```
## See Also
- [React API](../react/api.md) - `useTimeline` hook reference
- [Solid API](../solid/api.md) - `useTimeline` hook reference
- [Core API](../core/api.md) - `AnimationEngine` and `Timeline` classes
- [Layout Patterns](../layout/patterns.md) - Animated positioning and transitions
@@ -13,7 +13,7 @@ Use this reference when you need to find the right component category or compare
| Text & Display | text, ascii-font, styled text | [text-display.md](./text-display.md) |
| Containers | box, scrollbox, borders | [containers.md](./containers.md) |
| Inputs | input, textarea, select, tab-select | [inputs.md](./inputs.md) |
| Code & Diff | code, line-number, diff | [code-diff.md](./code-diff.md) |
| Code & Diff | code, line-number, diff, markdown | [code-diff.md](./code-diff.md) |
## Component Chooser
@@ -22,7 +22,7 @@ Need a component?
├─ Styled text or ASCII art -> text-display.md
├─ Containers, borders, scrolling -> containers.md
├─ Forms or input controls -> inputs.md
└─ Code blocks, diffs, line numbers -> code-diff.md
└─ Code blocks, diffs, line numbers, markdown -> code-diff.md
```
## Component Naming
@@ -42,6 +42,7 @@ Components have different names across frameworks:
| Code | `CodeRenderable` | `<code>` | `<code>` |
| Line Number | `LineNumberRenderable` | `<line-number>` | `<line_number>` |
| Diff | `DiffRenderable` | `<diff>` | `<diff>` |
| Markdown | `MarkdownRenderable` | `<markdown>` | `<markdown>` |
**Note**: Solid uses underscores (`tab_select`) while React uses hyphens (`tab-select`).
@@ -65,7 +66,9 @@ flexWrap, gap
// Spacing
padding, paddingTop, paddingRight, paddingBottom, paddingLeft
paddingX, paddingY // Axis shorthand (horizontal/vertical)
margin, marginTop, marginRight, marginBottom, marginLeft
marginX, marginY // Axis shorthand (horizontal/vertical)
// Display
display="flex" | "none"
@@ -54,6 +54,42 @@ OpenTUI uses Tree-sitter for syntax highlighting. Common languages:
/>
```
### onHighlight Callback
Intercept and modify syntax highlights before rendering:
```tsx
// Core
const codeBlock = new CodeRenderable(renderer, {
id: "code",
code: sourceCode,
language: "typescript",
onHighlight: (highlights, context) => {
// Add custom highlights
highlights.push([10, 20, "custom.error", {}])
return highlights
},
})
// React/Solid
<code
code={sourceCode}
language="typescript"
onHighlight={(highlights, context) => {
// context: { content, filetype, syntaxStyle }
// Modify and return highlights array
return highlights.filter(h => h[2] !== "comment")
}}
/>
```
**Callback signature:**
- `highlights: SimpleHighlight[]` - Array of `[start, end, scope, metadata]`
- `context: { content, filetype, syntaxStyle }` - Highlighting context
- Return modified highlights array or `undefined` to use original
Supports async callbacks for fetching additional highlight data.
## Line Number Component
Code display with line numbers, highlighting, and diagnostics.
@@ -239,6 +275,88 @@ const diffView = new DiffRenderable(renderer, {
/>
```
## Markdown Component
Render markdown content with syntax highlighting for code blocks.
### Basic Usage
```tsx
// React
<markdown
content={markdownText}
syntaxStyle={mySyntaxStyle}
/>
// Solid
<markdown
content={markdownText}
syntaxStyle={mySyntaxStyle}
/>
// Core
import { MarkdownRenderable } from "@opentui/core"
const md = new MarkdownRenderable(renderer, {
id: "markdown",
content: "# Hello\n\nThis is **markdown**.",
syntaxStyle: mySyntaxStyle,
})
```
### Options
```tsx
<markdown
content={markdownText}
syntaxStyle={syntaxStyle}
treeSitterClient={client} // Optional: custom tree-sitter client
conceal={true} // Hide markdown syntax characters
streaming={true} // Enable streaming mode for incremental updates
/>
```
### Custom Node Rendering
```tsx
// Core
const md = new MarkdownRenderable(renderer, {
id: "markdown",
content: "# Custom Heading",
syntaxStyle,
renderNode: (node, ctx, defaultRender) => {
if (node.type === "heading") {
// Return custom renderable for headings
return new TextRenderable(ctx, {
content: `>> ${node.content} <<`,
})
}
return null // Use default rendering
},
})
```
### Streaming Mode
For real-time content like LLM output:
```tsx
const [content, setContent] = useState("")
// Append text as it arrives
useEffect(() => {
llmStream.on("token", (token) => {
setContent(c => c + token)
})
}, [])
<markdown
content={content}
syntaxStyle={syntaxStyle}
streaming={true} // Optimizes for incremental updates
/>
```
## Use Cases
### Code Editor
@@ -105,8 +105,12 @@ Boxes are flex containers by default:
paddingRight={2}
paddingBottom={1}
paddingLeft={2}
paddingX={2} // Horizontal (left + right)
paddingY={1} // Vertical (top + bottom)
margin={1}
marginTop={1}
marginX={2} // Horizontal (left + right)
marginY={1} // Vertical (top + bottom)
>
Spaced content
</box>
@@ -141,6 +145,31 @@ Boxes are flex containers by default:
</box>
```
### Focusable Boxes
By default, Box elements are not focusable. Set the `focusable` prop to enable focus behavior:
```tsx
// Make a box focusable - it can receive focus via mouse click
<box focusable border>
<text>Click to focus</text>
</box>
// Controlled focus state
const [focused, setFocused] = useState(false)
<box
focusable
focused={focused}
border
borderColor={focused ? "#00ff00" : "#888"}
>
<text>{focused ? "Focused!" : "Not focused"}</text>
</box>
```
When a focusable Box is clicked, focus bubbles up from the click target to the nearest focusable parent. Use `event.preventDefault()` in `onMouseDown` to prevent auto-focus.
## ScrollBox Component
A scrollable container for content that exceeds the viewport.
+56 -3
View File
@@ -397,11 +397,57 @@ renderer.keyInput.on("paste", (text: string) => {
})
```
### React/Solid
### Solid
Solid provides a dedicated `usePaste` hook:
```tsx
// Currently handled through the global keyboard listener
// or via input component's onChange
import { usePaste } from "@opentui/solid"
function App() {
usePaste((event) => {
console.log("Pasted:", event.text)
})
return <text>Paste something</text>
}
```
> **Note**: `usePaste` is **Solid-only**. React does not have this hook - handle paste via the Core event emitter or input component's `onChange`.
## Clipboard API (OSC 52)
Copy text to the system clipboard using OSC 52 escape sequences. Works over SSH and in most modern terminal emulators.
### Core
```typescript
// Copy to clipboard
const success = renderer.copyToClipboardOSC52("text to copy")
// Check if OSC 52 is supported
if (renderer.isOsc52Supported()) {
renderer.copyToClipboardOSC52("Hello!")
}
// Clear clipboard
renderer.clearClipboardOSC52()
// Target specific clipboard (X11)
import { ClipboardTarget } from "@opentui/core"
renderer.copyToClipboardOSC52("text", ClipboardTarget.Primary) // X11 primary
renderer.copyToClipboardOSC52("text", ClipboardTarget.Clipboard) // System clipboard (default)
```
### From Selection
The Selection object provides a convenience method:
```tsx
// Solid
useSelectionHandler((selection) => {
selection.copyToClipboard() // Uses OSC 52 internally
})
```
## Focus and Input Components
@@ -456,3 +502,10 @@ Key detection may vary over SSH. Test on target environments.
### Multiple Handlers
Multiple `useKeyboard` calls all receive events. Coordinate handlers to prevent conflicts.
## See Also
- [React API](../react/api.md) - `useKeyboard` hook reference
- [Solid API](../solid/api.md) - `useKeyboard` hook reference
- [Input Components](../components/inputs.md) - Focus management with input, textarea, select
- [Testing](../testing/REFERENCE.md) - Simulating key presses in tests
@@ -410,3 +410,35 @@ function Divider() {
<text>Section 2</text>
</box>
```
### Axis Shorthand Props
Use `paddingX`/`paddingY` and `marginX`/`marginY` for horizontal/vertical spacing:
```tsx
// Horizontal padding (left + right)
<box paddingX={4}>
<text>4 chars padding left and right</text>
</box>
// Vertical padding (top + bottom)
<box paddingY={2}>
<text>2 lines padding top and bottom</text>
</box>
// Horizontal margin for centering-like effect
<box marginX={10}>
<text>Indented content</text>
</box>
// Combined for card-like spacing
<box paddingX={3} paddingY={1} marginY={1} border>
<text>Nicely spaced card</text>
</box>
```
These are shorthand for:
- `paddingX={n}` = `paddingLeft={n}` + `paddingRight={n}`
- `paddingY={n}` = `paddingTop={n}` + `paddingBottom={n}`
- `marginX={n}` = `marginLeft={n}` + `marginRight={n}`
- `marginY={n}` = `marginTop={n}` + `marginBottom={n}`
+31
View File
@@ -37,10 +37,33 @@ function App() {
// Show debug console
renderer.console.show()
// Access theme mode (dark/light based on terminal settings)
console.log(`Theme: ${renderer.themeMode}`) // "dark" | "light" | null
}, [renderer])
return <text>Hello</text>
}
// Listen for theme mode changes
function ThemedApp() {
const renderer = useRenderer()
const [theme, setTheme] = useState(renderer.themeMode ?? "dark")
useEffect(() => {
const handler = (mode: "dark" | "light") => setTheme(mode)
renderer.on("theme_mode", handler)
return () => renderer.off("theme_mode", handler)
}, [renderer])
return (
<box backgroundColor={theme === "dark" ? "#1a1a2e" : "#ffffff"}>
<text fg={theme === "dark" ? "#fff" : "#000"}>
Current theme: {theme}
</text>
</box>
)
}
```
### useKeyboard(handler, options?)
@@ -233,13 +256,21 @@ function AnimatedBox() {
// Spacing
padding={2}
paddingTop={1}
paddingX={2} // Horizontal (left + right)
paddingY={1} // Vertical (top + bottom)
margin={1}
marginX={2} // Horizontal (left + right)
marginY={1} // Vertical (top + bottom)
// Dimensions
width={40}
height={10}
flexGrow={1}
// Focus
focusable // Allow box to receive focus
focused={isFocused} // Controlled focus state
// Events
onMouseDown={(e) => {}}
onMouseUp={(e) => {}}
@@ -146,6 +146,8 @@ const renderer = await createCliRenderer({
// Behavior
exitOnCtrlC: true, // Set false to handle Ctrl+C yourself
autoFocus: true, // Auto-focus elements on click (default: true)
useMouse: true, // Enable mouse support (default: true)
// Debug console
consoleOptions: {
+11
View File
@@ -24,6 +24,17 @@ function App() {
`renderer.destroy()` restores the terminal (exits alternate screen, restores cursor, etc.) before exiting.
### Signal Handling
OpenTUI automatically handles cleanup for these signals:
- `SIGINT` (Ctrl+C), `SIGTERM`, `SIGQUIT` - Standard termination
- `SIGHUP` - Terminal closed/hangup
- `SIGBREAK` - Ctrl+Break (Windows)
- `SIGPIPE` - Broken pipe (output closed)
- `SIGBUS`, `SIGFPE` - Hardware errors
This ensures terminal state is restored even on unexpected termination. If you need custom signal handling, use `exitOnCtrlC: false` and handle signals yourself while still calling `renderer.destroy()`.
## JSX Configuration
### Missing jsxImportSource
+6 -3
View File
@@ -169,13 +169,16 @@ function AutoFocusInput() {
### Global Shortcuts
```tsx
import { useKeyboard } from "@opentui/react"
import { useKeyboard, useRenderer } from "@opentui/react"
function App() {
const renderer = useRenderer()
useKeyboard((key) => {
// Quit on Escape or Ctrl+C
// Quit on Escape or Ctrl+C - use renderer.destroy(), never process.exit()
if (key.name === "escape" || (key.ctrl && key.name === "c")) {
process.exit(0)
renderer.destroy()
return
}
// Toggle help on ?
+52 -4
View File
@@ -85,10 +85,31 @@ function App() {
onMount(() => {
console.log(`Terminal: ${renderer.width}x${renderer.height}`)
renderer.console.show()
// Access theme mode (dark/light based on terminal settings)
console.log(`Theme: ${renderer.themeMode}`) // "dark" | "light" | null
})
return <text>Hello</text>
}
// Listen for theme mode changes
function ThemedApp() {
const renderer = useRenderer()
const [theme, setTheme] = createSignal(renderer.themeMode ?? "dark")
onMount(() => {
renderer.on("theme_mode", (mode: "dark" | "light") => setTheme(mode))
})
return (
<box backgroundColor={theme() === "dark" ? "#1a1a2e" : "#ffffff"}>
<text fg={theme() === "dark" ? "#fff" : "#000"}>
Current theme: {theme()}
</text>
</box>
)
}
```
### useKeyboard(handler, options?)
@@ -189,20 +210,39 @@ function ResponsiveLayout() {
### useSelectionHandler(handler)
Handle text selection events.
Handle text selection events. Solid-only hook - React does not have this.
```tsx
import { useSelectionHandler } from "@opentui/solid"
import type { Selection } from "@opentui/core"
function SelectableText() {
useSelectionHandler((selection) => {
console.log("Selected:", selection.text)
const [selected, setSelected] = createSignal("")
useSelectionHandler((selection: Selection) => {
const text = selection.getSelectedText()
if (text) {
setSelected(text)
// Copy to clipboard if needed
selection.copyToClipboard()
}
})
return <text selectable>Select this text</text>
return (
<box flexDirection="column">
<text selectable>Select this text with your mouse</text>
<text fg="#888">Selected: {selected()}</text>
</box>
)
}
```
**Selection properties/methods:**
- `getSelectedText(): string` - Get the selected text content
- `copyToClipboard(): void` - Copy selection to system clipboard (via OSC 52)
- `start: ConsolePosition` - Selection start position
- `end: ConsolePosition` - Selection end position
### useTimeline(options?)
Create animations with the timeline system.
@@ -282,13 +322,21 @@ function AnimatedBox() {
// Spacing
padding={2}
paddingX={2} // Horizontal (left + right)
paddingY={1} // Vertical (top + bottom)
margin={1}
marginX={2} // Horizontal (left + right)
marginY={1} // Vertical (top + bottom)
// Dimensions
width={40}
height={10}
flexGrow={1}
// Focus
focusable // Allow box to receive focus
focused={isFocused()} // Controlled focus state
// Events
onMouseDown={(e) => {}}
onMouseUp={(e) => {}}
@@ -150,6 +150,8 @@ render(() => <App />, {
// Behavior
exitOnCtrlC: true,
autoFocus: true, // Auto-focus elements on click (default: true)
useMouse: true, // Enable mouse support (default: true)
// Debug console
consoleOptions: {
@@ -605,3 +605,10 @@ bun test
# Not from repo root for package-specific tests
```
## See Also
- [Core API](../core/api.md) - `createTestRenderer` and renderable classes
- [React Configuration](../react/configuration.md) - React test setup
- [Solid Configuration](../solid/configuration.md) - Solid test setup
- [Keyboard](../keyboard/REFERENCE.md) - Simulating key events in tests