import type { Ref } from "vue"; import type { Rect } from "../events/manager/types.js"; import type { ClipboardApi } from "../runtime/index.js"; import type { Cell, Style, Terminal } from "../core/types.js"; export type TerminalSelectionPoint = Readonly<{ x: number; y: number; }>; export type TerminalSelectionRange = Readonly<{ anchor: TerminalSelectionPoint; focus: TerminalSelectionPoint; mode: "linear" | "block"; }>; export type TerminalSelectionState = Readonly<{ active: boolean; anchor: TerminalSelectionPoint | null; focus: TerminalSelectionPoint | null; text: string; hasRange: boolean; }>; export type TerminalSelectionCopyPayload = Readonly<{ text: string; rows: number; chars: number; ok: boolean; error?: unknown; }>; export type TerminalSelectionOptions = Readonly<{ autoCopy?: boolean; copyOnMouseUp?: boolean; style?: Style; }>; export type TerminalSelectionConfig = boolean | TerminalSelectionOptions; /** * A visible overlay span in terminal screen coordinates. * Provider-space spans must be translated to screen coordinates before * returning from `getVisibleSpans()`. */ export type SelectedRowSpan = Readonly<{ /** Terminal screen row y */ y: number; /** Terminal screen column x inclusive */ x0: number; /** Terminal screen column x exclusive */ x1: number; }>; export type SelectionTextProvider = Readonly<{ id: string; /** * Current provider viewport rect in terminal screen coordinates. */ rect: Rect; /** * Receives a terminal screen-space range. Return true when this provider * can resolve the range without relying on the terminal buffer fallback. */ canHandle: (screenRange: TerminalSelectionRange) => boolean; /** * Maps a terminal screen-space point to provider-space point. */ pointForCell?: (screenPoint: TerminalSelectionPoint) => TerminalSelectionPoint | null; /** * Receives a provider-space range (i.e. after `pointForCell` mapping). */ getText: (providerRange: TerminalSelectionRange) => string; /** * Return overlay highlight spans for the portion of the selection that is * currently visible in the viewport. Coordinates are terminal screen cells. * * When a virtual-scrolling provider scrolls during a drag-selection, the * selection range may span content that has already scrolled out of view. * The default `terminalSelectionRowSpans()` uses screen coordinates and * cannot account for this, so the highlight becomes stale after each scroll * tick. Providers that support cross-viewport selection should implement * this method to return only the spans that intersect the current viewport, * mapped back to screen cell coordinates. * * @param providerRange - The selection range in provider-space coordinates * (i.e. after `pointForCell` mapping). * @param screenRange - The same selection range in terminal screen * coordinates (before `pointForCell` mapping). */ getVisibleSpans?: (providerRange: TerminalSelectionRange, screenRange: TerminalSelectionRange) => readonly SelectedRowSpan[]; }>; export type TerminalSelectionRefreshOptions = Readonly<{ /** * Re-map the current screen-space focus point through the active provider. * Use this for selection-driven auto-scroll after the viewport has moved. */ remapFocus?: boolean; }>; export type TerminalSelectionController = Readonly<{ state: Ref; start: (point: TerminalSelectionPoint, options?: { extend?: boolean; }) => void; update: (point: TerminalSelectionPoint) => void; finish: () => Promise; clear: () => void; copy: () => Promise; paint: (dirtyRows?: readonly number[]) => void; refresh: (options?: TerminalSelectionRefreshOptions) => void; clearProvider: (providerId: string) => void; }>; type ResolvedSelectionOptions = Readonly<{ autoCopy: boolean; copyOnMouseUp: boolean; style: Style; }>; export type CreateTerminalSelectionControllerOptions = Readonly<{ terminal: Terminal; overlayTerminal: Terminal; clipboard: ClipboardApi; getRow?: (y: number) => readonly Cell[]; getOptions?: () => Partial; getTextProviders?: () => readonly SelectionTextProvider[]; onDirtyRows?: (rows: readonly number[]) => void; onCopy?: (payload: TerminalSelectionCopyPayload) => void; }>; export declare function terminalSelectionRowSpans(range: TerminalSelectionRange, cols: number, rows: number): SelectedRowSpan[]; export declare function terminalSelectionVisibleRowSpans(range: TerminalSelectionRange, cols: number, rows: number, visibleStartY: number, visibleEndY: number): SelectedRowSpan[]; export declare function createTerminalSelectionController(options: CreateTerminalSelectionControllerOptions): TerminalSelectionController; export {};