@estebanforge/pi-tui-dialogs
v0.1.3
Published
Framed TUI dialog kit for @estebanforge Pi extensions: bordered settings menus with label/value columns, help panel, tabs, type-to-search, and validated input dialogs. Dialog pattern adapted from pi-subagent-manager (MIT). Plain library, no Pi entrypoint:
Readme
@estebanforge/pi-tui-dialogs
Framed TUI dialog kit for @estebanforge Pi Coding Agent extensions. One
settings/picker pattern for every extension instead of one per package.
Dialog pattern adapted from pi-subagent-manager (MIT); tabs and type-to-search follow the Zellij modal they replace.
What it ships
frameDialog/dialogHeight/DIALOG_OPTIONS— shared rounded frame: title in the top border, body, footer line above the bottom border, padded to a stable height so centered overlays do not jump between views.dialogBlocked(title)— the pi 1.5.1 overlayblockedoption payload ({ kind: "question", message: title }): pi reports the overlay as waiting on user input (OSC 7501) untildone(), also while hidden.dialogMenu,dialogInput, anddialogChoicepass it for you; hand-rolled overlays can spread it into their ownctx.ui.customoptions. Hosts older than pi 1.5.1 ignore the field.DialogMenu/dialogMenu— framed menu withlabel │ valuerows, a counter line, a muted help panel for the selected row, optional tab groups (left/right to switch) and type-to-search within the active tab. Rows withvaluescycle in place on Enter; rows withonEditrun a custom action and keep the menu open; plain rows resolve the menu with their id.dialogInput— framed single-line input with placeholder, help lines, and optionalvalidate: return an error string to keep the dialog open with the message inline, returnundefinedto accept.dialogChoice— framed single-choice modal: one decision statement (wraps), a closed option list of 1 toMAX_CHOICE_OPTIONS(10) options with unique values and an optional preselect. Enter resolves the chosen option's value; esc resolvesundefined(the escape hatch). Caller-contract violations (0 or >10 options, duplicate values, unknown preselect) throw before any overlay opens.canOpenDialog— headless guard for non-TUI modes.
Usage
import { canOpenDialog, dialogChoice, dialogInput, dialogMenu, DialogMenu } from "@estebanforge/pi-tui-dialogs";
await ctx.ui.custom(
(host, theme, _keys, done) =>
new DialogMenu(
host,
theme,
{
title: "My extension",
subtitle: "Project file: .pi/my-extension.json",
tabs: [
{ label: "General", rows: [{ id: "enabled", label: "Enabled", value: "on", values: ["on", "off"], help: "Master switch." }] },
{ label: "Limits", rows: [{ id: "cap", label: "Cap", value: "100", onEdit: () => void dialogInput(ctx, "Cap", { initial: "100", validate: (raw) => (/^\d+$/.test(raw) ? undefined : "must be a number") }) }] },
],
onChange: (id, value) => save(id, value),
},
() => done(),
),
// DIALOG_OPTIONS centers the dialog near fullscreen
);A closed choice reads the same way:
const engine = await dialogChoice(ctx, "Choose your engine", {
description: "Which engine runs your turns? Switch anytime with /engine.",
options: [
{ value: "fast", label: "Fast", description: "default · lighter" },
{ value: "deep", label: "Deep", description: "downloads a big binary" },
],
selected: "fast",
});
// engine === undefined means esc: decide later, persist nothing.Plain library, no Pi entrypoint: depend on it and Pi installs it transitively.
License
MIT. See LICENSE for the pi-subagent-manager attribution.
