Prerequisites: Complete the Installation guide before starting this tutorial.
Choose Your API Style
Kraken TUI offers two APIs with the same underlying performance:- Imperative API — Direct control with explicit widget creation and manipulation
- JSX API — Declarative composition with reactive signals (requires
@preact/signals-core)
- Imperative API
- JSX API
Imperative: Hello World
Let’s start with the simplest possible application:How It Works
- Initialize —
Kraken.init()creates the native context and terminal backend - Compose — Create widgets and build a tree structure using
append() - Mount —
app.setRoot()attaches your tree to the rendering surface - Loop — Read input → drain events → render (60fps pattern)
- Shutdown —
app.shutdown()restores terminal state
Interactive Todo List
Now let’s build a more complete application with input handling:todo.ts
Key Concepts
Widget Tree
Widgets are composed hierarchically.
Box containers hold children arranged by Flexbox layout.Handles
Each widget has a
handle property — an opaque u32 reference. Use handles to identify event targets.Event Loop
The host controls timing:
readInput() → drainEvents() → render(). Typically 60fps (16ms interval).Focus Management
Call
setFocusable(true) on interactive widgets. Use Tab/Shift+Tab for keyboard traversal.Core Concepts Explained
Widget Types
Kraken TUI provides six core widgets:| Widget | Purpose | Key Props |
|---|---|---|
| Box | Container with Flexbox layout | flexDirection, gap, padding, border |
| Text | Display text (plain/markdown/code) | content, format, fg, bold, italic |
| Input | Single-line text input | maxLength, fg, border, focusable |
| Select | Option list with arrow navigation | options, border, focusable |
| ScrollBox | Scrollable container (one child) | border, fg, bg |
| TextArea | Multi-line text editor | wrapMode, fg, border, focusable |
Layout with Flexbox
Kraken TUI uses Taffy (Rust Flexbox implementation) for layout:- Fixed:
width: 40(cells) - Percentage:
width: "50%"(of parent) - Fill:
width: "100%"(full parent width) - Auto:
width: "auto"(content-based)
Event Handling
All events are drained from a buffer each frame:Styling
Colors can be specified as:- Hex:
"#FF0000"(RGB) - Named:
"red","cyan","bright-black"(16 color names) - Indexed:
196(256 color palette index)
bold: trueitalic: trueunderline: true
border: "single"—┌─┐border: "double"—╔═╗border: "rounded"—╭─╮border: "none"(default)
Next Steps
Now that you’ve built your first application, explore these topics:Core Concepts
Deep dive into widgets, layout, and state management
API Reference
Complete API documentation for all widgets and methods
Animation
Add smooth transitions and built-in animation primitives
Theming
Customize appearance with themes and runtime switching