/** * Editing model for the TUI prompt: one text buffer, one caret, one history. * * The TUI renders through Ink, but the editing rules are shared with the legacy * readline editor and are far easier to pin down without a renderer attached, so * this module stays free of React, Ink and IO. Callers keep an `EditorState` and * feed it semantic keys; every function returns a fresh state and leaves the * argument untouched, which is what React's state updates require. * * Operations that cannot move anything (a caret already at the buffer edge, a * paste that sanitizes down to nothing) return the state they were given, so the * caller's re-render is skipped instead of repeating an identical frame. */ export interface EditorState { /** Full buffer, may contain '\n'. */ readonly text: string; /** Caret offset into `text`, 0..text.length. */ readonly cursor: number; /** Previously submitted entries, oldest first. */ readonly history: readonly string[]; /** null = editing a fresh line; otherwise an index into `history`. */ readonly historyIndex: number | null; /** Buffer stashed when history browsing started, restored on the way back. */ readonly draftBeforeHistory: string | null; } /** * A line still being written, taken out of the buffer it lives in. * * Only the two things a reader of the prompt can see are carried: what stands * there and where the caret is. The recall history is the mount's own and * travels separately. */ export interface EditorDraft { readonly text: string; readonly cursor: number; } export type EditorKey = { readonly kind: 'insert'; readonly text: string; } | { readonly kind: 'newline'; } | { readonly kind: 'backspace'; } | { readonly kind: 'delete'; } | { readonly kind: 'left'; } | { readonly kind: 'right'; } | { readonly kind: 'home'; } | { readonly kind: 'end'; } | { readonly kind: 'deleteToLineEnd'; } /** * Caret one drawn row up, or the previous history entry from the first row. * The rows are the wrapped ones the prompt box shows, so the width the box * has for text comes along with the key. */ | { readonly kind: 'up'; readonly contentWidth: number; } /** Caret one drawn row down, or the next history entry from the last row. */ | { readonly kind: 'down'; readonly contentWidth: number; }; export declare function createEditorState(text: string): EditorState; export declare function applyEditorKey(state: EditorState, key: EditorKey): EditorState; /** Push the submitted text onto history and return a cleared editor. */ export declare function commitEditorInput(state: EditorState, submitted: string): EditorState; /** Replace the whole buffer, placing the cursor at the end (used by completion accept). */ export declare function replaceEditorText(state: EditorState, text: string): EditorState; //# sourceMappingURL=editorState.d.ts.map