/** * run-wishlist-picker.tsx — Standalone launcher for the WishlistPicker. * * Creates and destroys its own Ink render instance, returning a Promise * that resolves with the user's action (promote to errand/genesis/quest, * or go back). */ import React from "react"; import { getStableStdin } from "./bun-stdin"; import { render } from "ink"; import { WishlistPicker } from "./wishlist-picker"; import type { WishlistItem } from "../lib/wishlist-store"; // --------------------------------------------------------------------------- // Action Type // --------------------------------------------------------------------------- export type WishlistPickerAction = | { type: "promoteErrand"; item: WishlistItem } | { type: "promoteGenesis"; item: WishlistItem } | { type: "promoteQuest"; item: WishlistItem } | { type: "back" } | { type: "quit" }; // --------------------------------------------------------------------------- // Options // --------------------------------------------------------------------------- export interface RunWishlistPickerOptions { projectRoot: string; } // --------------------------------------------------------------------------- // Standalone Launcher // --------------------------------------------------------------------------- /** * Run the wishlist picker as a standalone Ink instance. * Returns the user's chosen action. */ export function runWishlistPickerInk( opts: RunWishlistPickerOptions ): Promise { const { projectRoot } = opts; return new Promise((resolve) => { let instance: ReturnType; const handleAction = (action: WishlistPickerAction) => { instance.unmount(); resolve(action); }; process.stdin.resume(); // keep event loop alive between renders instance = render( handleAction({ type: "promoteErrand", item })} onPromoteGenesis={(item) => handleAction({ type: "promoteGenesis", item })} onPromoteQuest={(item) => handleAction({ type: "promoteQuest", item })} onBack={() => handleAction({ type: "back" })} onQuit={() => handleAction({ type: "quit" })} />, { exitOnCtrlC: false, stdin: getStableStdin() } ); }); }