doc(README): update "quick start" (#3740)
This commit is contained in:
@@ -16,7 +16,7 @@ Minimal terminal UI framework with differential rendering and synchronized outpu
|
|||||||
## Quick Start
|
## Quick Start
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import { TUI, Text, Editor, ProcessTerminal } from "@mariozechner/pi-tui";
|
import { TUI, Text, Editor, ProcessTerminal, matchesKey } from "@mariozechner/pi-tui";
|
||||||
|
|
||||||
// Create terminal
|
// Create terminal
|
||||||
const terminal = new ProcessTerminal();
|
const terminal = new ProcessTerminal();
|
||||||
@@ -27,6 +27,7 @@ const tui = new TUI(terminal);
|
|||||||
// Add components
|
// Add components
|
||||||
tui.addChild(new Text("Welcome to my app!"));
|
tui.addChild(new Text("Welcome to my app!"));
|
||||||
|
|
||||||
|
import { defaultEditorTheme as editorTheme } from './test/test-themes.ts';
|
||||||
const editor = new Editor(tui, editorTheme);
|
const editor = new Editor(tui, editorTheme);
|
||||||
editor.onSubmit = (text) => {
|
editor.onSubmit = (text) => {
|
||||||
console.log("Submitted:", text);
|
console.log("Submitted:", text);
|
||||||
@@ -34,6 +35,17 @@ editor.onSubmit = (text) => {
|
|||||||
};
|
};
|
||||||
tui.addChild(editor);
|
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
|
// Start
|
||||||
tui.start();
|
tui.start();
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user