doc(README): update "quick start" (#3740)

This commit is contained in:
Yves Jutard
2026-04-28 16:48:21 +10:00
committed by GitHub
parent c241c6d6d0
commit 946bee1946

View File

@@ -16,7 +16,7 @@ Minimal terminal UI framework with differential rendering and synchronized outpu
## Quick Start
```typescript
import { TUI, Text, Editor, ProcessTerminal } from "@mariozechner/pi-tui";
import { TUI, Text, Editor, ProcessTerminal, matchesKey } from "@mariozechner/pi-tui";
// Create terminal
const terminal = new ProcessTerminal();
@@ -27,6 +27,7 @@ const tui = new TUI(terminal);
// Add components
tui.addChild(new Text("Welcome to my app!"));
import { defaultEditorTheme as editorTheme } from './test/test-themes.ts';
const editor = new Editor(tui, editorTheme);
editor.onSubmit = (text) => {
console.log("Submitted:", text);
@@ -34,6 +35,17 @@ editor.onSubmit = (text) => {
};
tui.addChild(editor);
// Focus the editor so it receives keyboard input
tui.setFocus(editor);
// In raw mode Ctrl+C doesn't send SIGINT — intercept it here to allow exit
tui.addInputListener((data) => {
if (matchesKey(data, 'ctrl+c')) {
tui.stop();
process.exit(0);
}
});
// Start
tui.start();
```