/** * The shared editable command line under every text prompt, ported * from less's cmdbuf.c: a buffer of grapheme clusters with a cursor, * a horizontal display offset and history recall. */ /** cmd_char results, like CC_OK / CC_QUIT / CC_ERROR / CC_PASS. */ type CmdResult = 'ok' | 'quit' | 'error' | 'pass'; /** A completion hook, run for TAB / SHIFT-TAB / ^L when allowed. */ export type Completer = (action: 'complete' | 'reverseComplete' | 'expand') => void; interface CmdState { /** True while a prompt is being edited through cmdbuf. */ active: boolean; /** The buffer, one grapheme cluster per entry. */ steps: string[]; /** Cursor position: index into steps, like cp. */ cur: number; /** First displayed step, like cmd_offset. */ offset: number; /** Column just after the prompt, like prompt_col. */ promptCol: number; /** Next char inserts literally (^V / ^A), like `literal`. */ literal: boolean; /** Pending multi-char edit sequence (ESC combos typed slowly). */ prefix: string; /** Prefix length latched by the first up/down, like updown_match; * -1 when unset. */ updownMatch: number; /** The current history list, like curr_mlist; null = no history. */ history: string[] | null; /** Recall position, like curr_mp: history.length is the sentinel. */ histPos: number; /** Abort the command when it is entirely erased (CF_QUIT_ON_ERASE). */ quitOnErase: boolean; /** Filename completion is allowed at this prompt. */ complete: Completer | null; /** True while TAB cycling, like in_completion. */ inCompletion: boolean; } export declare const cmd: CmdState; /** * A cluster's display form, like cmd_step_common: caret notation for * controls (ESC spelled out, like less's prchar), everything else as-is. */ export declare function stepText(step: string): string; /** * Opens the command buffer for a prompt, like start_mca calling * cmd_reset and set_mlist: the recall spot returns to the newest * entry so up-arrow retrieves the previous command. */ export declare function cmdOpen(prompt: string, opts?: { history?: string[] | null; quitOnErase?: boolean; complete?: Completer | null; text?: string; }): void; /** Closes the buffer when its prompt ends. */ export declare function cmdClose(): void; /** * Updates the prompt width when the prompt text changes mid-edit * (search modifier toggles), like mca_search repainting. */ export declare function cmdPrompt(prompt: string): void; /** The buffer contents, like get_cmdbuf. */ export declare const cmdText: () => string; /** Replaces the buffer, cursor to the end, like cmd_setstring. */ export declare function cmdSetText(text: string): void; /** * Replaces the clusters from `start` to the cursor with new text, * cursor landing at its end, like cmd_complete erasing back to the * word start and inserting the trial with cmd_istr. */ export declare function cmdReplaceRange(start: number, text: string): void; /** The cursor's screen column (0-based), like cmd_col. */ export declare function cmdCol(): number; /** * The visible slice of the buffer, like cmd_repaint's draw loop: * chars paint while they fit strictly inside the screen width. */ export declare function cmdDisplay(): string; /** Moves the cursor right one cluster, like cmd_right. */ export declare function cmdRight(): void; /** * Takes one ungot char for reprocessing; the prompt key handler * drains this after every cmdChar call. */ export declare function cmdUngot(): string | null; export declare function cmdChar(key: string): CmdResult; export {};