Core TypeScript types for theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/badlogic/pi-mono/llms.txt
Use this file to discover all available pages before exploring further.
@mariozechner/pi-tui package.
Powered by Mintlify
Auto-generate your docs
Type definitions for the TUI package
Core TypeScript types for theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/badlogic/pi-mono/llms.txt
Use this file to discover all available pages before exploring further.
@mariozechner/pi-tui package.
import type {
Component,
Focusable,
Terminal,
OverlayOptions,
EditorOptions,
SelectItem,
} from "@mariozechner/pi-tui";
interface Component {
render(width: number): string[];
handleInput?(data: string): void;
wantsKeyRelease?: boolean;
invalidate(): void;
}
interface Focusable {
focused: boolean;
}
interface Terminal {
write(data: string): void;
getSize(): { rows: number; cols: number };
setRawMode(enabled: boolean): void;
onData(callback: (data: string) => void): void;
onResize(callback: () => void): void;
clear(): void;
}
interface OverlayOptions {
width?: SizeValue;
minWidth?: number;
maxHeight?: SizeValue;
anchor?: OverlayAnchor;
offsetX?: number;
offsetY?: number;
row?: SizeValue;
col?: SizeValue;
margin?: OverlayMargin | number;
visible?: (termWidth: number, termHeight: number) => boolean;
}
type SizeValue = number | `${number}%`;
type OverlayAnchor =
| "center"
| "top-left"
| "top-right"
| "bottom-left"
| "bottom-right"
| "top-center"
| "bottom-center"
| "left-center"
| "right-center";
interface OverlayMargin {
top?: number;
right?: number;
bottom?: number;
left?: number;
}
type OverlayHandle = { readonly __brand: unique symbol };
interface EditorOptions {
placeholder?: string;
language?: string;
theme?: EditorTheme;
keybindings?: EditorKeybindingsConfig;
autocomplete?: AutocompleteProvider;
}
interface EditorTheme {
text: string;
cursor: string;
selection: string;
lineNumber: string;
placeholder: string;
}
type EditorKeybindingsConfig = Record<string, EditorAction>;
type EditorAction =
| "move-left"
| "move-right"
| "move-up"
| "move-down"
| "move-word-left"
| "move-word-right"
| "move-line-start"
| "move-line-end"
| "move-doc-start"
| "move-doc-end"
| "delete-char"
| "delete-word"
| "delete-line"
| "newline"
| "submit"
| "cancel"
| "undo"
| "redo";
interface SelectItem {
id: string;
label: string;
description?: string;
disabled?: boolean;
}
interface SelectListTheme {
selected: string;
unselected: string;
disabled: string;
searchQuery: string;
}
interface SettingItem {
id: string;
label: string;
value: string;
description?: string;
}
interface SettingsListTheme {
selected: string;
unselected: string;
value: string;
description: string;
}
interface MarkdownTheme {
heading1: string;
heading2: string;
heading3: string;
bold: string;
italic: string;
code: string;
codeBlock: string;
link: string;
list: string;
}
interface DefaultTextStyle {
color?: string;
backgroundColor?: string;
bold?: boolean;
dim?: boolean;
italic?: boolean;
}
interface ImageOptions {
data: string; // base64
mimeType: string;
maxWidth?: number;
maxHeight?: number;
theme?: ImageTheme;
}
interface ImageTheme {
border?: string;
}
type ImageProtocol = "kitty" | "iterm2" | null;
interface TerminalCapabilities {
imageProtocol: ImageProtocol;
colorDepth: 24 | 256 | 16;
cellDimensions: CellDimensions | null;
}
interface CellDimensions {
width: number; // pixels
height: number; // pixels
}
interface Key {
type: KeyEventType;
sequence: string;
name?: string;
ctrl?: boolean;
shift?: boolean;
alt?: boolean;
meta?: boolean;
}
type KeyEventType = "press" | "release" | "repeat";
type KeyId = string; // e.g., "ctrl+c", "enter", "esc"
interface AutocompleteProvider {
getSuggestions(text: string, cursorPos: number): Promise<AutocompleteItem[]>;
}
interface AutocompleteItem {
text: string;
label?: string;
description?: string;
}
interface SlashCommand {
name: string;
description?: string;
shortcut?: string;
}
interface FuzzyMatch {
item: string;
score: number;
indices: number[];
}
interface StdinBufferOptions {
batchSize?: number;
batchDelayMs?: number;
}
interface StdinBufferEventMap {
data: { data: string };
error: { error: Error };
}
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;
}