/** * A single-choice list overlay, bounded to the terminal and searchable when long. * * Approvals, `ask_user_question`, and the model picker are the same interaction * — read a prompt, move through choices, confirm one — so they share one * implementation and differ only in what they do with the result. Anything that * needs a different presentation registers its own overlay instead; the slot * registry does not privilege this one. * * Sharing that implementation is also why the list has to bound itself HERE. * Every caller used to decide how many choices it offered, and one of them — * `/model` over a gateway route — offers whatever the provider advertises, * which for OpenRouter or opencode is hundreds. A picker that draws a row per * choice then hands `Screen` a live region taller than the screen, and the rows * that scrolled off can no longer be reached or erased: the next redraw leaves * duplicates in real scrollback and can clear output the picker never owned. * The list is therefore a viewport over its rows, exactly as Work, Sessions, * and Connect are. * * A long list also has to be reachable, not merely drawable, so past * {@link SEARCHABLE_CHOICES} the picker grows a query box and filters as you * type. Below it nothing changes: a three-choice approval spends no row on a * search box, and typed characters stay meaningless there. * @module dshline/select */ import type { Context } from '@deepseek-ai/cordis'; import type { TuiOverlay } from './slots.ts'; /** * Choices past which the picker offers a query box. * * Twelve is about what the list can show on the shortest terminal anyone drives * without scrolling, so below it a search box would cost a row to reach rows * that are already on screen. Above it the list scrolls, and typing is how a * reader gets to the end of it without holding a key down. */ export declare const SEARCHABLE_CHOICES = 12; /** One selectable row. */ export interface SelectChoice { /** The value handed back on confirmation. */ value: string; /** User-facing label. */ label: string; /** Optional second line shown under the label when selected. */ description?: string; } /** How a select overlay is built and what it reports. */ export interface SelectSpec { /** Headline shown above the list. */ title: string; /** Concise identity shown in the shared root chrome. */ readonly view?: string; /** Optional supporting text between the title and the list. */ detail?: string; /** The rows; an empty list is a programming error and renders as such. */ choices: readonly SelectChoice[]; /** Optional initially highlighted value when it remains in the offered rows. */ initialValue?: string; /** * Whole footer-help phrases for secondary actions this overlay's OWNER * handles itself. * * Each item is one complete footer-help phrase. Callers must not include the * footer separator (` · `) inside an item: the picker treats each item as one * indivisible segment, so an embedded separator would look like a boundary it * does not actually control. * * Presentation only. The picker escapes and renders each phrase but never * interprets or handles it — the owning overlay keeps the keys, so a phrase * here cannot make this primitive aware of a domain or a key. They are * composed after the picker's own navigation help and before confirmation * and the way out, so width pressure drops them in that order. */ readonly extraHelp?: readonly string[]; /** * Called once with the confirmed value, or with undefined when the user * cancelled. The overlay never calls this twice. */ settle(value: string | undefined): void; /** Asks the runner to redraw after a selection move. */ invalidate(): void; } /** * Apply a query to the choices, preserving the caller's order. * * Matched against the LABEL alone, which is the only part of a choice every row * shows. Matching a description that is drawn under the selection only would * leave a reader unable to see why a row survived — and unable to trust the ones * that did not. * @param choices - the offered choices. * @param query - raw query text. * @returns the matching choices, in their original order. */ export declare function filterChoices(choices: readonly SelectChoice[], query: string): readonly SelectChoice[]; /** * Build a select overlay. * @param spec - the prompt, choices, and settlement callback. * @returns the overlay to push onto the slot registry. */ export declare function createSelectOverlay(spec: SelectSpec): TuiOverlay; /** * Show a list and wait for the answer. * * The push-await-dismiss dance is the same every time — build the overlay, hold * the disposer the registry hands back, and make sure settling runs it before * the promise resolves — and it was written out at every call site. Getting the * order wrong leaves a picker on screen after it has been answered, which is a * bug each copy has to avoid separately. * * Anything whose settlement is not a straight line from the promise keeps its * own: the approval prompt also settles from an abort listener, and the Sessions * browser settles from a resume decision its owner makes rather than from the * chosen row. * @param ctx - context carrying the slot registry. * @param spec - the prompt and its choices; settlement is this function's. An * optional `signal` takes the question down without an answer, for a caller * whose question can stop being worth asking — a Harness authorization flow * racing a typed code against a browser callback withdraws the loser that way. * @returns the confirmed value, or undefined when the user cancelled or the * question was withdrawn. */ export declare function promptSelect(ctx: Context, spec: Omit & { signal?: AbortSignal; }): Promise; //# sourceMappingURL=select.d.ts.map