import type {
Component,
Focusable,
EditorOptions,
SelectItem,
} from "@mariozechner/pi-tui";
import { Editor, SelectList } from "@mariozechner/pi-tui";
// Type-safe editor options
const editorOptions: EditorOptions = {
placeholder: "Type here...",
language: "typescript",
keybindings: {
"ctrl+enter": "submit",
"escape": "cancel",
},
};
const editor = new Editor(editorOptions);
// Type-safe select list
const items: SelectItem[] = [
{ id: "1", label: "Option 1" },
{ id: "2", label: "Option 2", disabled: true },
];
const list = new SelectList({ items });
// Type guard
if (isFocusable(editor)) {
editor.focused = true;
}
function isFocusable(component: Component): component is Component & Focusable {
return "focused" in component;
}