@m4ike1/ion-tui 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +114 -0
- package/dist/alt-screen-search.d.ts +46 -0
- package/dist/alt-screen-search.d.ts.map +1 -0
- package/dist/alt-screen-search.js +282 -0
- package/dist/alt-screen-search.js.map +1 -0
- package/dist/autocomplete.d.ts +75 -0
- package/dist/autocomplete.d.ts.map +1 -0
- package/dist/autocomplete.js +749 -0
- package/dist/autocomplete.js.map +1 -0
- package/dist/components/alt-screen-flash.d.ts +13 -0
- package/dist/components/alt-screen-flash.d.ts.map +1 -0
- package/dist/components/alt-screen-flash.js +37 -0
- package/dist/components/alt-screen-flash.js.map +1 -0
- package/dist/components/box.d.ts +24 -0
- package/dist/components/box.d.ts.map +1 -0
- package/dist/components/box.js +133 -0
- package/dist/components/box.js.map +1 -0
- package/dist/components/cancellable-loader.d.ts +22 -0
- package/dist/components/cancellable-loader.d.ts.map +1 -0
- package/dist/components/cancellable-loader.js +35 -0
- package/dist/components/cancellable-loader.js.map +1 -0
- package/dist/components/editor.d.ts +266 -0
- package/dist/components/editor.d.ts.map +1 -0
- package/dist/components/editor.js +2087 -0
- package/dist/components/editor.js.map +1 -0
- package/dist/components/h-stack.d.ts +7 -0
- package/dist/components/h-stack.d.ts.map +1 -0
- package/dist/components/h-stack.js +43 -0
- package/dist/components/h-stack.js.map +1 -0
- package/dist/components/image.d.ts +28 -0
- package/dist/components/image.d.ts.map +1 -0
- package/dist/components/image.js +90 -0
- package/dist/components/image.js.map +1 -0
- package/dist/components/input.d.ts +48 -0
- package/dist/components/input.d.ts.map +1 -0
- package/dist/components/input.js +417 -0
- package/dist/components/input.js.map +1 -0
- package/dist/components/loader.d.ts +33 -0
- package/dist/components/loader.d.ts.map +1 -0
- package/dist/components/loader.js +76 -0
- package/dist/components/loader.js.map +1 -0
- package/dist/components/markdown.d.ts +103 -0
- package/dist/components/markdown.d.ts.map +1 -0
- package/dist/components/markdown.js +858 -0
- package/dist/components/markdown.js.map +1 -0
- package/dist/components/mouse-region.d.ts +12 -0
- package/dist/components/mouse-region.d.ts.map +1 -0
- package/dist/components/mouse-region.js +21 -0
- package/dist/components/mouse-region.js.map +1 -0
- package/dist/components/scroll-view.d.ts +68 -0
- package/dist/components/scroll-view.d.ts.map +1 -0
- package/dist/components/scroll-view.js +199 -0
- package/dist/components/scroll-view.js.map +1 -0
- package/dist/components/select-list.d.ts +53 -0
- package/dist/components/select-list.d.ts.map +1 -0
- package/dist/components/select-list.js +206 -0
- package/dist/components/select-list.js.map +1 -0
- package/dist/components/settings-list.d.ts +60 -0
- package/dist/components/settings-list.d.ts.map +1 -0
- package/dist/components/settings-list.js +252 -0
- package/dist/components/settings-list.js.map +1 -0
- package/dist/components/spacer.d.ts +12 -0
- package/dist/components/spacer.d.ts.map +1 -0
- package/dist/components/spacer.js +23 -0
- package/dist/components/spacer.js.map +1 -0
- package/dist/components/stack.d.ts +32 -0
- package/dist/components/stack.d.ts.map +1 -0
- package/dist/components/stack.js +111 -0
- package/dist/components/stack.js.map +1 -0
- package/dist/components/text.d.ts +19 -0
- package/dist/components/text.d.ts.map +1 -0
- package/dist/components/text.js +90 -0
- package/dist/components/text.js.map +1 -0
- package/dist/components/truncated-text.d.ts +13 -0
- package/dist/components/truncated-text.d.ts.map +1 -0
- package/dist/components/truncated-text.js +51 -0
- package/dist/components/truncated-text.js.map +1 -0
- package/dist/components/v-stack.d.ts +8 -0
- package/dist/components/v-stack.d.ts.map +1 -0
- package/dist/components/v-stack.js +26 -0
- package/dist/components/v-stack.js.map +1 -0
- package/dist/components/virtual-list.d.ts +51 -0
- package/dist/components/virtual-list.d.ts.map +1 -0
- package/dist/components/virtual-list.js +170 -0
- package/dist/components/virtual-list.js.map +1 -0
- package/dist/editor-component.d.ts +39 -0
- package/dist/editor-component.d.ts.map +1 -0
- package/dist/editor-component.js +2 -0
- package/dist/editor-component.js.map +1 -0
- package/dist/fuzzy.d.ts +16 -0
- package/dist/fuzzy.d.ts.map +1 -0
- package/dist/fuzzy.js +110 -0
- package/dist/fuzzy.js.map +1 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +46 -0
- package/dist/index.js.map +1 -0
- package/dist/keybindings.d.ts +366 -0
- package/dist/keybindings.d.ts.map +1 -0
- package/dist/keybindings.js +331 -0
- package/dist/keybindings.js.map +1 -0
- package/dist/keys.d.ts +184 -0
- package/dist/keys.d.ts.map +1 -0
- package/dist/keys.js +1174 -0
- package/dist/keys.js.map +1 -0
- package/dist/kill-ring.d.ts +28 -0
- package/dist/kill-ring.d.ts.map +1 -0
- package/dist/kill-ring.js +44 -0
- package/dist/kill-ring.js.map +1 -0
- package/dist/latex.d.ts +10 -0
- package/dist/latex.d.ts.map +1 -0
- package/dist/latex.js +1285 -0
- package/dist/latex.js.map +1 -0
- package/dist/layout-node.d.ts +59 -0
- package/dist/layout-node.d.ts.map +1 -0
- package/dist/layout-node.js +12 -0
- package/dist/layout-node.js.map +1 -0
- package/dist/layout.d.ts +42 -0
- package/dist/layout.d.ts.map +1 -0
- package/dist/layout.js +404 -0
- package/dist/layout.js.map +1 -0
- package/dist/native-modifiers.d.ts +4 -0
- package/dist/native-modifiers.d.ts.map +1 -0
- package/dist/native-modifiers.js +13 -0
- package/dist/native-modifiers.js.map +1 -0
- package/dist/native-module-path.d.ts +7 -0
- package/dist/native-module-path.d.ts.map +1 -0
- package/dist/native-module-path.js +19 -0
- package/dist/native-module-path.js.map +1 -0
- package/dist/native-platform.d.ts +18 -0
- package/dist/native-platform.d.ts.map +1 -0
- package/dist/native-platform.js +42 -0
- package/dist/native-platform.js.map +1 -0
- package/dist/pty-host.d.ts +224 -0
- package/dist/pty-host.d.ts.map +1 -0
- package/dist/pty-host.js +347 -0
- package/dist/pty-host.js.map +1 -0
- package/dist/stdin-buffer.d.ts +56 -0
- package/dist/stdin-buffer.d.ts.map +1 -0
- package/dist/stdin-buffer.js +366 -0
- package/dist/stdin-buffer.js.map +1 -0
- package/dist/terminal-colors.d.ts +10 -0
- package/dist/terminal-colors.d.ts.map +1 -0
- package/dist/terminal-colors.js +59 -0
- package/dist/terminal-colors.js.map +1 -0
- package/dist/terminal-image.d.ts +118 -0
- package/dist/terminal-image.d.ts.map +1 -0
- package/dist/terminal-image.js +550 -0
- package/dist/terminal-image.js.map +1 -0
- package/dist/terminal.d.ts +123 -0
- package/dist/terminal.d.ts.map +1 -0
- package/dist/terminal.js +442 -0
- package/dist/terminal.js.map +1 -0
- package/dist/tui-alt-screen.d.ts +165 -0
- package/dist/tui-alt-screen.d.ts.map +1 -0
- package/dist/tui-alt-screen.js +1515 -0
- package/dist/tui-alt-screen.js.map +1 -0
- package/dist/tui-main-screen.d.ts +39 -0
- package/dist/tui-main-screen.d.ts.map +1 -0
- package/dist/tui-main-screen.js +594 -0
- package/dist/tui-main-screen.js.map +1 -0
- package/dist/tui.d.ts +431 -0
- package/dist/tui.d.ts.map +1 -0
- package/dist/tui.js +1142 -0
- package/dist/tui.js.map +1 -0
- package/dist/undo-stack.d.ts +17 -0
- package/dist/undo-stack.d.ts.map +1 -0
- package/dist/undo-stack.js +25 -0
- package/dist/undo-stack.js.map +1 -0
- package/dist/utils.d.ts +98 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +1200 -0
- package/dist/utils.js.map +1 -0
- package/dist/word-navigation.d.ts +25 -0
- package/dist/word-navigation.d.ts.map +1 -0
- package/dist/word-navigation.js +96 -0
- package/dist/word-navigation.js.map +1 -0
- package/native/clipboard.h +170 -0
- package/native/darwin/README.md +22 -0
- package/native/darwin/build.sh +69 -0
- package/native/darwin/prebuilds/darwin-arm64/darwin-platform.node +0 -0
- package/native/darwin/prebuilds/darwin-x64/darwin-platform.node +0 -0
- package/native/darwin/src/darwin-platform.m +93 -0
- package/native/linux/README.md +23 -0
- package/native/linux/build.sh +65 -0
- package/native/linux/prebuilds/linux-arm64/linux-platform-x11.node +0 -0
- package/native/linux/prebuilds/linux-x64/linux-platform-x11.node +0 -0
- package/native/linux/src/clipboard-worker.h +70 -0
- package/native/linux/src/linux-platform-x11.c +274 -0
- package/native/napi.h +89 -0
- package/native/win32/README.md +31 -0
- package/native/win32/build.mjs +232 -0
- package/native/win32/prebuilds/win32-arm64/win32-platform.node +0 -0
- package/native/win32/prebuilds/win32-x64/win32-platform.node +0 -0
- package/native/win32/src/win32-platform.c +241 -0
- package/package.json +62 -0
package/dist/tui.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tui.js","sourceRoot":"","sources":["../src/tui.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAElE,OAAO,EACN,8BAA8B,EAC9B,yBAAyB,EACzB,8BAA8B,GAG9B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACtF,OAAO,EAAE,eAAe,EAAE,uBAAuB,EAAE,aAAa,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AA6DnH;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,SAAoB,EAAE,KAAoB,EAAsC;IAClH,MAAM,MAAM,GAAG,SAAS,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC;IAC9C,IAAI,CAAC,MAAM;QAAE,OAAO,SAAS,CAAC;IAC9B,IAAI,QAAQ,IAAI,MAAM;QAAE,OAAO,MAAgC,CAAC;IAChE,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK;QAAE,OAAO,SAAS,CAAC;IAC1E,OAAO;Q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port { performance } from \"node:perf_hooks\";\nimport { getKeybindings } from \"./keybindings.ts\";\nimport { isKeyRelease, isKeyRepeat, matchesKey } from \"./keys.ts\";\nimport type { Terminal } from \"./terminal.ts\";\nimport {\n\tisOsc11BackgroundColorResponse,\n\tparseOsc11BackgroundColor,\n\tparseTerminalColorSchemeReport,\n\ttype RgbColor,\n\ttype TerminalColorScheme,\n} from \"./terminal-colors.ts\";\nimport { getCapabilities, isImageLine, setCellDimensions } from \"./terminal-image.ts\";\nimport { extractSegments, normalizeTerminalOutput, sliceByColumn, sliceWithWidth, visibleWidth } from \"./utils.ts\";\n\n/**\n * Component interface - all components must implement this\n */\nexport type TuiMouseEventType = \"press\" | \"release\" | \"move\" | \"drag\" | \"click\" | \"wheel\";\nexport type TuiMouseButton = \"left\" | \"middle\" | \"right\" | \"none\";\n\n/** Normalized cell-based mouse event. Coordinates are zero-based. */\nexport interface TuiMouseEvent {\n\ttype: TuiMouseEventType;\n\tbutton: TuiMouseButton;\n\t/** Coordinates local to the receiving component. */\n\tx: number;\n\ty: number;\n\t/** Absolute terminal coordinates. */\n\tscreenX: number;\n\tscreenY: number;\n\t/** Current component bounds. */\n\twidth: number;\n\theight: number;\n\tshift: boolean;\n\talt: boolean;\n\tctrl: boolean;\n\t/** Logical lines. Negative values scroll up. */\n\twheelDelta?: number;\n\t/** Consecutive click count when type is click. */\n\tclickCount?: number;\n}\n\nexport interface TuiMouseEventResult {\n\t/** Stop propagation and suppress renderer-level fallback behavior. */\n\thandled?: boolean;\n\t/** Route subsequent drag/release events to this component. Implies handled. */\n\tcapture?: boolean;\n\t/** Give keyboard focus to this component. Implies handled. */\n\tfocus?: boolean;\n\t/**\n\t * Explicitly request or suppress a render. Move and release default to false;\n\t * press, click, drag, and wheel default to true.\n\t */\n\trender?: boolean;\n}\n\n/** Internal target metadata used by containers and alternate-screen dispatch. */\nexport interface TuiMouseDispatchTarget {\n\tcomponent: Component;\n\toriginX: number;\n\toriginY: number;\n\twidth: number;\n\theight: number;\n}\n\n/** Result of dispatching to a concrete component. */\nexport interface TuiMouseDispatchResult extends TuiMouseEventResult {\n\thandled: true;\n\ttarget: TuiMouseDispatchTarget;\n\t/** Keyboard focus target, which may be a delegating parent container. */\n\tfocusTarget?: Component;\n}\n\n/**\n * Dispatch an event to a component and retain the exact target and coordinate\n * transform. Containers use this when forwarding events to nested children.\n */\nexport function dispatchMouseEvent(component: Component, event: TuiMouseEvent): TuiMouseDispatchResult | undefined {\n\tconst result = component.handleMouse?.(event);\n\tif (!result) return undefined;\n\tif (\"target\" in result) return result as TuiMouseDispatchResult;\n\tif (!result.handled && !result.capture && !result.focus) return undefined;\n\treturn {\n\t\t...result,\n\t\thandled: true,\n\t\t...(result.focus ? { focusTarget: component } : {}),\n\t\ttarget: {\n\t\t\tcomponent,\n\t\t\toriginX: event.screenX - event.x,\n\t\t\toriginY: event.screenY - event.y,\n\t\t\twidth: event.width,\n\t\t\theight: event.height,\n\t\t},\n\t};\n}\n\n/** Recreate local coordinates for a previously dispatched mouse target. */\nexport function retargetMouseEvent(event: TuiMouseEvent, target: TuiMouseDispatchTarget): TuiMouseEvent {\n\treturn {\n\t\t...event,\n\t\tx: event.screenX - target.originX,\n\t\ty: event.screenY - target.originY,\n\t\twidth: target.width,\n\t\theight: target.height,\n\t};\n}\n\nexport interface Component {\n\t/**\n\t * Render the component to lines for the given viewport width\n\t * @param width - Current viewport width\n\t * @returns Array of strings, each representing a line\n\t */\n\trender(width: number): string[];\n\n\t/** Optional handler for keyboard input when component has focus. */\n\thandleInput?(data: string): void;\n\n\t/** Optional normalized mouse handler. */\n\thandleMouse?(event: TuiMouseEvent): TuiMouseEventResult | undefined;\n\n\t/**\n\t * If true, component receives key release events (Kitty protocol).\n\t * Default is false - release events are filtered out.\n\t */\n\twantsKeyRelease?: boolean;\n\n\t/**\n\t * Invalidate any cached rendering state.\n\t * Called when theme changes or when component needs to re-render from scratch.\n\t */\n\tinvalidate(): void;\n}\n\nexport type TuiInputListenerResult = { consume?: boolean; data?: string } | undefined;\nexport type TuiInputListener = (data: string) => TuiInputListenerResult;\ntype PendingOsc11BackgroundQuery = {\n\tsettled: boolean;\n\tresolve: ((rgb: RgbColor | undefined) => void) | undefined;\n\ttimer: NodeJS.Timeout | undefined;\n};\n\n/**\n * Interface for components that can receive focus and display a hardware cursor.\n * When focused, the component should emit CURSOR_MARKER at the cursor position\n * in its render output. TUI will find this marker and position the hardware\n * cursor there for proper IME candidate window positioning.\n */\nexport interface Focusable {\n\t/** Set by TUI when focus changes. Component should emit CURSOR_MARKER when true. */\n\tfocused: boolean;\n}\n\n/** Type guard to check if a component implements Focusable */\nexport function isFocusable(component: Component | null): component is Component & Focusable {\n\treturn component !== null && \"focused\" in component;\n}\n\n/**\n * Structural interface for components hosting a dismissable inline layer (e.g.\n * the editor autocomplete dropdown). Escape unwinding consults the focused\n * component through this interface before touching overlay layers, so one press\n * dismisses the inline layer without leaking to the layer below.\n */\nexport interface AutocompleteHost extends Component {\n\t/** Whether the inline layer (e.g. autocomplete dropdown) is currently open. */\n\tisShowingAutocomplete(): boolean;\n\t/** Dismiss the inline layer. Returns true when a layer was open. */\n\tdismissAutocomplete(): boolean;\n}\n\n/** Type guard to check if a component implements AutocompleteHost */\nexport function isAutocompleteHost(component: Component | null): component is Component & AutocompleteHost {\n\tif (component === null) return false;\n\tconst host = component as Partial<AutocompleteHost>;\n\treturn typeof host.isShowingAutocomplete === \"function\" && typeof host.dismissAutocomplete === \"function\";\n}\n\n/** Options for an explicit keyboard-focus transition. */\nexport interface FocusTransitionOptions {\n\t/** Machine-readable reason recorded for the transition (e.g. `overlay-show`). */\n\treason?: string;\n}\n\n/** Last explicit keyboard-focus transition. Exactly one component owns focus. */\nexport interface FocusTransition {\n\tfrom: Component | null;\n\tto: Component | null;\n\treason: string;\n}\n\n/**\n * Cursor position marker - APC (Application Program Command) sequence.\n * This is a zero-width escape sequence that terminals ignore.\n * Components emit this at the cursor position when focused.\n * TUI finds and strips this marker, then positions the hardware cursor there.\n */\nexport const CURSOR_MARKER = \"\\x1b_pi:c\\x07\";\n\nexport { visibleWidth };\n\n/**\n * Anchor position for overlays\n */\nexport type OverlayAnchor =\n\t| \"center\"\n\t| \"top-left\"\n\t| \"top-right\"\n\t| \"bottom-left\"\n\t| \"bottom-right\"\n\t| \"top-center\"\n\t| \"bottom-center\"\n\t| \"left-center\"\n\t| \"right-center\";\n\n/**\n * Margin configuration for overlays\n */\nexport interface OverlayMargin {\n\ttop?: number;\n\tright?: number;\n\tbottom?: number;\n\tleft?: number;\n}\n\n/** Value that can be absolute (number) or percentage (string like \"50%\") */\nexport type SizeValue = number | `${number}%`;\n\n/** Parse a SizeValue into absolute value given a reference size */\nfunction parseSizeValue(value: SizeValue | undefined, referenceSize: number): number | undefined {\n\tif (value === undefined) return undefined;\n\tif (typeof value === \"number\") return value;\n\t// Parse percentage string like \"50%\"\n\tconst match = value.match(/^(\\d+(?:\\.\\d+)?)%$/);\n\tif (match) {\n\t\treturn Math.floor((referenceSize * parseFloat(match[1])) / 100);\n\t}\n\treturn undefined;\n}\n\n/**\n * Options for overlay positioning and sizing.\n * Values can be absolute numbers or percentage strings (e.g., \"50%\").\n */\nexport interface OverlayOptions {\n\t// === Sizing ===\n\t/** Width in columns, or percentage of terminal width (e.g., \"50%\") */\n\twidth?: SizeValue;\n\t/** Minimum width in columns */\n\tminWidth?: number;\n\t/** Maximum height in rows, or percentage of terminal height (e.g., \"50%\") */\n\tmaxHeight?: SizeValue;\n\n\t// === Positioning - anchor-based ===\n\t/** Anchor point for positioning (default: 'center') */\n\tanchor?: OverlayAnchor;\n\t/** Horizontal offset from anchor position (positive = right) */\n\toffsetX?: number;\n\t/** Vertical offset from anchor position (positive = down) */\n\toffsetY?: number;\n\n\t// === Positioning - percentage or absolute ===\n\t/** Row position: absolute number, or percentage (e.g., \"25%\" = 25% from top) */\n\trow?: SizeValue;\n\t/** Column position: absolute number, or percentage (e.g., \"50%\" = centered horizontally) */\n\tcol?: SizeValue;\n\n\t// === Margin from terminal edges ===\n\t/** Margin from terminal edges. Number applies to all sides. */\n\tmargin?: OverlayMargin | number;\n\n\t// === Visibility ===\n\t/**\n\t * Control overlay visibility based on terminal dimensions.\n\t * If provided, overlay is only rendered when this returns true.\n\t * Called each render cycle with current terminal dimensions.\n\t */\n\tvisible?: (termWidth: number, termHeight: number) => boolean;\n\t/** If true, don't capture keyboard focus when shown */\n\tnonCapturing?: boolean;\n}\n\n/** Options for {@link OverlayHandle.unfocus}. */\nexport interface OverlayUnfocusOptions {\n\t/** Explicit target to focus after releasing this overlay. */\n\ttarget: Component | null;\n}\n\n/** Last rendered terminal-relative overlay rectangle. */\nexport interface OverlayBounds {\n\trow: number;\n\tcol: number;\n\twidth: number;\n\theight: number;\n}\n\n/**\n * Handle returned by showOverlay for controlling the overlay\n */\nexport interface OverlayHandle {\n\t/** Permanently remove the overlay (cannot be shown again) */\n\thide(): void;\n\t/** Temporarily hide or show the overlay */\n\tsetHidden(hidden: boolean): void;\n\t/** Check if overlay is temporarily hidden */\n\tisHidden(): boolean;\n\t/** Focus this overlay and bring it to the visual front */\n\tfocus(): void;\n\t/** Release focus to the next visible capturing overlay or previous target, or to an explicit target when provided */\n\tunfocus(options?: OverlayUnfocusOptions): void;\n\t/** Check if this overlay currently has focus */\n\tisFocused(): boolean;\n\t/** Get the most recent rendered bounds for a visible overlay. */\n\tgetBounds(): OverlayBounds | undefined;\n}\n\ntype OverlayStackEntry = {\n\tcomponent: Component;\n\toptions?: OverlayOptions;\n\tpreFocus: Component | null;\n\thidden: boolean;\n\tfocusOrder: number;\n\tbounds?: OverlayBounds;\n};\n\ntype RenderedOverlayLayout = {\n\tentry: OverlayStackEntry;\n\trow: number;\n\tcol: number;\n\twidth: number;\n\theight: number;\n};\n\ntype OverlayBlockedFocusResume = { status: \"restore-overlay\" } | { status: \"focus-target\"; target: Component | null };\ntype EligibleOverlayFocusRestoreState = { status: \"eligible\"; overlay: OverlayStackEntry };\ntype BlockedOverlayFocusRestoreState = {\n\tstatus: \"blocked\";\n\toverlay: OverlayStackEntry;\n\tblockedBy: Component;\n\tresume: OverlayBlockedFocusResume;\n};\ntype ActiveOverlayFocusRestoreState = EligibleOverlayFocusRestoreState | BlockedOverlayFocusRestoreState;\ntype OverlayFocusRestoreState = { status: \"inactive\" } | ActiveOverlayFocusRestoreState;\ntype OverlayFocusRestorePolicy = \"clear\" | \"preserve\";\n\n/**\n * Container - a component that contains other components\n */\nexport class Container implements Component {\n\tchildren: Component[] = [];\n\tprivate mouseLayout?: { width: number; children: Array<{ component: Component; height: number }> };\n\n\taddChild(component: Component): void {\n\t\tthis.children.push(component);\n\t}\n\n\tremoveChild(component: Component): void {\n\t\tconst index = this.children.indexOf(component);\n\t\tif (index !== -1) {\n\t\t\tthis.children.splice(index, 1);\n\t\t}\n\t}\n\n\tclear(): void {\n\t\tthis.children = [];\n\t}\n\n\tinvalidate(): void {\n\t\tfor (const child of this.children) {\n\t\t\tchild.invalidate?.();\n\t\t}\n\t}\n\n\thandleMouse(event: TuiMouseEvent): TuiMouseDispatchResult | undefined {\n\t\tif (event.y < 0 || event.y >= event.height) return undefined;\n\t\tconst mouseChildren =\n\t\t\tthis.mouseLayout?.width === event.width\n\t\t\t\t? this.mouseLayout.children\n\t\t\t\t: this.children.map((component) => ({ component, height: component.render(event.width).length }));\n\t\tlet childY = 0;\n\t\tfor (const { component: child, height: childHeight } of mouseChildren) {\n\t\t\tif (event.y >= childY && event.y < childY + childHeight) {\n\t\t\t\tconst result = dispatchMouseEvent(child, {\n\t\t\t\t\t...event,\n\t\t\t\t\ty: event.y - childY,\n\t\t\t\t\theight: childHeight,\n\t\t\t\t});\n\t\t\t\tif (result?.focus && (this as Component).handleInput) return { ...result, focusTarget: this };\n\t\t\t\treturn result;\n\t\t\t}\n\t\t\tchildY += childHeight;\n\t\t}\n\t\treturn undefined;\n\t}\n\n\trender(width: number): string[] {\n\t\tconst lines: string[] = [];\n\t\tconst mouseChildren: Array<{ component: Component; height: number }> = [];\n\t\tfor (const child of this.children) {\n\t\t\tconst childLines = child.render(width);\n\t\t\tmouseChildren.push({ component: child, height: childLines.length });\n\t\t\tfor (const line of childLines) {\n\t\t\t\tlines.push(line);\n\t\t\t}\n\t\t}\n\t\tthis.mouseLayout = { width, children: mouseChildren };\n\t\treturn lines;\n\t}\n}\n\n/**\n * TUI - Main class for managing terminal UI with differential rendering\n */\nconst SEGMENT_RESET = \"\\x1b[0m\\x1b]8;;\\x07\";\n\n/** Composite overlay content into a terminal line at a fixed column. */\nexport function compositeTuiLine(\n\tbaseLine: string,\n\toverlayLine: string,\n\tstartCol: number,\n\toverlayWidth: number,\n\ttotalWidth: number,\n): string {\n\tif (isImageLine(baseLine)) return baseLine;\n\n\tconst afterStart = startCol + overlayWidth;\n\tconst base = extractSegments(baseLine, startCol, afterStart, totalWidth - afterStart, true);\n\tconst overlay = sliceWithWidth(overlayLine, 0, overlayWidth, true);\n\tconst beforePad = Math.max(0, startCol - base.beforeWidth);\n\tconst overlayPad = Math.max(0, overlayWidth - overlay.width);\n\tconst actualBeforeWidth = Math.max(startCol, base.beforeWidth);\n\tconst actualOverlayWidth = Math.max(overlayWidth, overlay.width);\n\tconst afterTarget = Math.max(0, totalWidth - actualBeforeWidth - actualOverlayWidth);\n\tconst afterPad = Math.max(0, afterTarget - base.afterWidth);\n\tconst result =\n\t\tbase.before +\n\t\t\" \".repeat(beforePad) +\n\t\tSEGMENT_RESET +\n\t\toverlay.text +\n\t\t\" \".repeat(overlayPad) +\n\t\tSEGMENT_RESET +\n\t\tbase.after +\n\t\t\" \".repeat(afterPad);\n\n\treturn visibleWidth(result) <= totalWidth ? result : sliceByColumn(result, 0, totalWidth, true);\n}\n\nexport type TuiMode = \"regular\" | \"fullscreen\";\n\nexport interface TuiStopOptions {\n\t/** Leave renderer output in place for another TUI taking over the same terminal. */\n\tpreserveScreen?: boolean;\n}\n\nexport interface TUI extends Component {\n\treadonly mode: TuiMode;\n\tchildren: Component[];\n\tterminal: Terminal;\n\tonDebug?: () => void;\n\treadonly fullRedraws: number;\n\taddChild(component: Component): void;\n\tremoveChild(component: Component): void;\n\tclear(): void;\n\tgetShowHardwareCursor(): boolean;\n\tsetShowHardwareCursor(enabled: boolean): void;\n\tgetClearOnShrink(): boolean;\n\tsetClearOnShrink(enabled: boolean): void;\n\tsetFocus(component: Component | null): void;\n\tshowOverlay(component: Component, options?: OverlayOptions): OverlayHandle;\n\thideOverlay(): void;\n\thasOverlay(): boolean;\n\tstart(): void;\n\tstop(options?: TuiStopOptions): void;\n\trenderNow(force?: boolean): void;\n\trequestRender(force?: boolean): void;\n\taddInputListener(listener: TuiInputListener): () => void;\n\tremoveInputListener(listener: TuiInputListener): void;\n\tonTerminalColorSchemeChange(listener: (scheme: TerminalColorScheme) => void): () => void;\n\tsetTerminalColorSchemeNotifications(enabled: boolean): void;\n\tqueryTerminalBackgroundColor(options: { timeoutMs: number }): Promise<RgbColor | undefined>;\n\tqueryTerminalColorScheme(options: { timeoutMs: number }): Promise<TerminalColorScheme | undefined>;\n}\n\nexport const VIEWPORT_TUI = Symbol.for(\"@m4ike1/ion-tui/viewport\");\n\nexport interface ViewportTUI extends TUI {\n\treadonly [VIEWPORT_TUI]: true;\n\tsetLayoutRoot(component: Component | undefined): void;\n}\n\nexport function isViewportTUI(tui: TUI): tui is ViewportTUI {\n\treturn (tui as Partial<ViewportTUI>)[VIEWPORT_TUI] === true;\n}\n\nexport abstract class TuiBase extends Container implements TUI {\n\tabstract readonly mode: TuiMode;\n\tpublic terminal: Terminal;\n\tprivate focusedComponent: Component | null = null;\n\tprivate inputListeners = new Set<TuiInputListener>();\n\n\t/** Global callback for debug key (Shift+Ctrl+D). Called before input is forwarded to focused component. */\n\tpublic onDebug?: () => void;\n\tprivate renderRequested = false;\n\tprivate immediateRenderScheduled = false;\n\tprivate renderTimer: NodeJS.Timeout | undefined;\n\tprivate lastRenderAt = 0;\n\tprivate static readonly MIN_RENDER_INTERVAL_MS = 16;\n\tprivate showHardwareCursor = false;\n\tprivate clearOnShrink = false;\n\tprotected fullRedrawCount = 0;\n\tprotected stopped = false;\n\tprivate pendingOsc11BackgroundReplies = 0;\n\tprivate pendingOsc11BackgroundQueries: PendingOsc11BackgroundQuery[] = [];\n\tprivate terminalColorSchemeListeners = new Set<(scheme: TerminalColorScheme) => void>();\n\tprivate terminalColorSchemeNotificationsEnabled = false;\n\t/** Directory for debug/crash logs. When undefined, debug logging is disabled and crash dumps fall back to the OS temp directory. */\n\tprotected readonly logDirectory: string | undefined;\n\n\t// Overlay stack for modal components rendered on top of base content\n\tprivate focusOrderCounter = 0;\n\tprivate overlayStack: OverlayStackEntry[] = [];\n\tprivate renderedOverlayLayouts: RenderedOverlayLayout[] = [];\n\tprivate lastFocusTransition: FocusTransition | undefined;\n\n\tget hasOverlayEntries(): boolean {\n\t\treturn this.overlayStack.length > 0;\n\t}\n\tprivate overlayFocusRestore: OverlayFocusRestoreState = { status: \"inactive\" };\n\n\tconstructor(terminal: Terminal, showHardwareCursor?: boolean, logDirectory?: string) {\n\t\tsuper();\n\t\tthis.terminal = terminal;\n\t\tthis.logDirectory = logDirectory;\n\t\tif (showHardwareCursor !== undefined) {\n\t\t\tthis.showHardwareCursor = showHardwareCursor;\n\t\t}\n\t}\n\n\tprotected abstract doRender(): void;\n\n\tprotected resetRenderState(): void {}\n\n\tprotected beforeTerminalStart(): void {}\n\n\tprotected afterTerminalStart(): void {}\n\n\tprotected beforeTerminalStop(_options: TuiStopOptions): void {}\n\n\tprotected afterTerminalStop(_options: TuiStopOptions): void {}\n\n\tget fullRedraws(): number {\n\t\treturn this.fullRedrawCount;\n\t}\n\n\tgetShowHardwareCursor(): boolean {\n\t\treturn this.showHardwareCursor;\n\t}\n\n\tsetShowHardwareCursor(enabled: boolean): void {\n\t\tif (this.showHardwareCursor === enabled) return;\n\t\tthis.showHardwareCursor = enabled;\n\t\tif (!enabled) {\n\t\t\tthis.terminal.hideCursor();\n\t\t}\n\t\tthis.requestRender();\n\t}\n\n\tgetClearOnShrink(): boolean {\n\t\treturn this.clearOnShrink;\n\t}\n\n\t/**\n\t * Set whether to trigger full re-render when content shrinks.\n\t * When true, empty rows are cleared when content shrinks.\n\t * When false (default), empty rows remain (reduces redraws on slower terminals).\n\t */\n\tsetClearOnShrink(enabled: boolean): void {\n\t\tthis.clearOnShrink = enabled;\n\t}\n\n\tgetFocusedComponent(): Component | null {\n\t\treturn this.focusedComponent;\n\t}\n\n\t/** Last explicit focus transition, for debugging focus-stealing reports. */\n\tgetLastFocusTransition(): FocusTransition | undefined {\n\t\treturn this.lastFocusTransition;\n\t}\n\n\tsetFocus(component: Component | null, options?: FocusTransitionOptions): void {\n\t\tthis.setFocusInternal({ component, overlayFocusRestore: \"clear\", reason: options?.reason ?? \"explicit\" });\n\t}\n\n\tprivate setFocusInternal({\n\t\tcomponent,\n\t\toverlayFocusRestore,\n\t\treason,\n\t}: {\n\t\tcomponent: Component | null;\n\t\toverlayFocusRestore: OverlayFocusRestorePolicy;\n\t\treason: string;\n\t}): void {\n\t\tconst previousFocus = this.focusedComponent;\n\t\tlet nextFocus = component;\n\t\tconst previousFocusedOverlay = previousFocus\n\t\t\t? this.overlayStack.find((entry) => entry.component === previousFocus && this.isOverlayVisible(entry))\n\t\t\t: undefined;\n\t\tconst nextFocusIsOverlay = nextFocus ? this.overlayStack.some((entry) => entry.component === nextFocus) : false;\n\t\tconst restoreState = this.getVisibleOverlayFocusRestore();\n\t\tif (nextFocus && !nextFocusIsOverlay) {\n\t\t\tif (restoreState.status === \"blocked\" && restoreState.blockedBy === previousFocus) {\n\t\t\t\tif (restoreState.resume.status === \"focus-target\" || !this.isComponentMounted(restoreState.blockedBy)) {\n\t\t\t\t\tnextFocus = this.resolveBlockedOverlayFocusResume(restoreState);\n\t\t\t\t} else {\n\t\t\t\t\tthis.overlayFocusRestore = {\n\t\t\t\t\t\tstatus: \"blocked\",\n\t\t\t\t\t\toverlay: restoreState.overlay,\n\t\t\t\t\t\tblockedBy: nextFocus,\n\t\t\t\t\t\tresume: restoreState.resume,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\tpreviousFocusedOverlay &&\n\t\t\t\trestoreState.status !== \"inactive\" &&\n\t\t\t\trestoreState.overlay === previousFocusedOverlay &&\n\t\t\t\t!this.isOverlayFocusAncestor(previousFocusedOverlay, nextFocus)\n\t\t\t) {\n\t\t\t\tthis.overlayFocusRestore = {\n\t\t\t\t\tstatus: \"blocked\",\n\t\t\t\t\toverlay: previousFocusedOverlay,\n\t\t\t\t\tblockedBy: nextFocus,\n\t\t\t\t\tresume: { status: \"restore-overlay\" },\n\t\t\t\t};\n\t\t\t}\n\t\t} else if (nextFocus === null) {\n\t\t\tif (restoreState.status === \"blocked\" && restoreState.blockedBy === previousFocus) {\n\t\t\t\tnextFocus = this.resolveBlockedOverlayFocusResume(restoreState);\n\t\t\t} else if (overlayFocusRestore === \"clear\") {\n\t\t\t\tthis.clearOverlayFocusRestore();\n\t\t\t}\n\t\t}\n\n\t\tif (isFocusable(this.focusedComponent)) {\n\t\t\tthis.focusedComponent.focused = false;\n\t\t}\n\n\t\tthis.focusedComponent = nextFocus;\n\n\t\tif (isFocusable(nextFocus)) {\n\t\t\tnextFocus.focused = true;\n\t\t}\n\n\t\tthis.lastFocusTransition = { from: previousFocus, to: nextFocus, reason };\n\n\t\tconst focusedOverlay = nextFocus\n\t\t\t? this.overlayStack.find((entry) => entry.component === nextFocus && this.isOverlayVisible(entry))\n\t\t\t: undefined;\n\t\tif (focusedOverlay) {\n\t\t\tthis.overlayFocusRestore = { status: \"eligible\", overlay: focusedOverlay };\n\t\t}\n\t}\n\n\tprivate clearOverlayFocusRestore(): void {\n\t\tthis.overlayFocusRestore = { status: \"inactive\" };\n\t}\n\n\tprivate clearOverlayFocusRestoreFor(overlay: OverlayStackEntry): void {\n\t\tif (this.overlayFocusRestore.status !== \"inactive\" && this.overlayFocusRestore.overlay === overlay) {\n\t\t\tthis.clearOverlayFocusRestore();\n\t\t}\n\t}\n\n\tprivate resolveBlockedOverlayFocusResume(restoreState: BlockedOverlayFocusRestoreState): Component | null {\n\t\tif (restoreState.resume.status === \"restore-overlay\") return restoreState.overlay.component;\n\t\tthis.clearOverlayFocusRestore();\n\t\treturn restoreState.resume.target;\n\t}\n\n\tprivate getVisibleOverlayFocusRestore(): OverlayFocusRestoreState {\n\t\tconst restoreState = this.overlayFocusRestore;\n\t\tif (restoreState.status === \"inactive\") return restoreState;\n\t\tif (!this.overlayStack.includes(restoreState.overlay) || !this.isOverlayVisible(restoreState.overlay)) {\n\t\t\treturn { status: \"inactive\" };\n\t\t}\n\t\treturn restoreState;\n\t}\n\n\tprivate isOverlayFocusAncestor(entry: OverlayStackEntry, component: Component): boolean {\n\t\tconst visited = new Set<Component>();\n\t\tlet current = entry.preFocus;\n\t\twhile (current && !visited.has(current)) {\n\t\t\tvisited.add(current);\n\t\t\tif (current === component) return true;\n\t\t\tcurrent = this.overlayStack.find((overlay) => overlay.component === current)?.preFocus ?? null;\n\t\t}\n\t\treturn false;\n\t}\n\n\tprivate retargetOverlayPreFocus(removed: OverlayStackEntry): void {\n\t\tfor (const overlay of this.overlayStack) {\n\t\t\tif (overlay !== removed && overlay.preFocus === removed.component) {\n\t\t\t\toverlay.preFocus = removed.preFocus;\n\t\t\t}\n\t\t}\n\t}\n\n\tprotected getMountedRoots(): readonly Component[] {\n\t\treturn this.children;\n\t}\n\n\tprivate isComponentMounted(component: Component): boolean {\n\t\treturn this.getMountedRoots().some((child) => this.containsComponent(child, component));\n\t}\n\n\tprivate containsComponent(root: Component, target: Component): boolean {\n\t\tif (root === target) return true;\n\t\tif (!(root instanceof Container)) return false;\n\t\treturn root.children.some((child) => this.containsComponent(child, target));\n\t}\n\n\t/**\n\t * Show an overlay component with configurable positioning and sizing.\n\t * Returns a handle to control the overlay's visibility.\n\t */\n\tshowOverlay(component: Component, options?: OverlayOptions): OverlayHandle {\n\t\tconst entry: OverlayStackEntry = {\n\t\t\tcomponent,\n\t\t\t...(options === undefined ? {} : { options }),\n\t\t\tpreFocus: this.focusedComponent,\n\t\t\thidden: false,\n\t\t\tfocusOrder: ++this.focusOrderCounter,\n\t\t};\n\t\tthis.overlayStack.push(entry);\n\t\t// Only focus if overlay is actually visible\n\t\tif (!options?.nonCapturing && this.isOverlayVisible(entry)) {\n\t\t\tthis.setFocus(component, { reason: \"overlay-show\" });\n\t\t}\n\t\tthis.terminal.hideCursor();\n\t\tthis.requestRender();\n\n\t\t// Return handle for controlling this overlay\n\t\treturn {\n\t\t\thide: () => {\n\t\t\t\tconst index = this.overlayStack.indexOf(entry);\n\t\t\t\tif (index !== -1) {\n\t\t\t\t\tthis.clearOverlayFocusRestoreFor(entry);\n\t\t\t\t\tthis.retargetOverlayPreFocus(entry);\n\t\t\t\t\tthis.overlayStack.splice(index, 1);\n\t\t\t\t\t// Restore focus if this overlay had focus\n\t\t\t\t\tif (this.focusedComponent === component) {\n\t\t\t\t\t\tconst topVisible = this.getTopmostVisibleOverlay();\n\t\t\t\t\t\tthis.setFocus(topVisible?.component ?? entry.preFocus, { reason: \"overlay-hide\" });\n\t\t\t\t\t}\n\t\t\t\t\tif (this.overlayStack.length === 0) this.terminal.hideCursor();\n\t\t\t\t\tthis.requestRender();\n\t\t\t\t}\n\t\t\t},\n\t\t\tsetHidden: (hidden: boolean) => {\n\t\t\t\tif (entry.hidden === hidden) return;\n\t\t\t\tentry.hidden = hidden;\n\t\t\t\t// Update focus when hiding/showing\n\t\t\t\tif (hidden) {\n\t\t\t\t\tthis.clearOverlayFocusRestoreFor(entry);\n\t\t\t\t\t// If this overlay had focus, move focus to next visible or preFocus\n\t\t\t\t\tif (this.focusedComponent === component) {\n\t\t\t\t\t\tconst topVisible = this.getTopmostVisibleOverlay();\n\t\t\t\t\t\tthis.setFocus(topVisible?.component ?? entry.preFocus, { reason: \"overlay-hide\" });\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// Restore focus to this overlay when showing (if it's actually visible)\n\t\t\t\t\tif (!options?.nonCapturing && this.isOverlayVisible(entry)) {\n\t\t\t\t\t\tentry.focusOrder = ++this.focusOrderCounter;\n\t\t\t\t\t\tthis.setFocus(component, { reason: \"overlay-visibility\" });\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tthis.requestRender();\n\t\t\t},\n\t\t\tisHidden: () => entry.hidden,\n\t\t\tfocus: () => {\n\t\t\t\tif (!this.overlayStack.includes(entry) || !this.isOverlayVisible(entry)) return;\n\t\t\t\tentry.focusOrder = ++this.focusOrderCounter;\n\t\t\t\tthis.setFocus(component, { reason: \"overlay-focus\" });\n\t\t\t\tthis.requestRender();\n\t\t\t},\n\t\t\tunfocus: (unfocusOptions) => {\n\t\t\t\tconst isFocused = this.focusedComponent === component;\n\t\t\t\tconst restoreState = this.overlayFocusRestore;\n\t\t\t\tconst hasPendingRestore = restoreState.status !== \"inactive\" && restoreState.overlay === entry;\n\t\t\t\tif (!isFocused && !hasPendingRestore) return;\n\t\t\t\tif (\n\t\t\t\t\trestoreState.status === \"blocked\" &&\n\t\t\t\t\trestoreState.overlay === entry &&\n\t\t\t\t\tthis.focusedComponent === restoreState.blockedBy\n\t\t\t\t) {\n\t\t\t\t\tif (unfocusOptions) {\n\t\t\t\t\t\tthis.overlayFocusRestore = {\n\t\t\t\t\t\t\tstatus: \"blocked\",\n\t\t\t\t\t\t\toverlay: entry,\n\t\t\t\t\t\t\tblockedBy: restoreState.blockedBy,\n\t\t\t\t\t\t\tresume: { status: \"focus-target\", target: unfocusOptions.target },\n\t\t\t\t\t\t};\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.clearOverlayFocusRestore();\n\t\t\t\t\t}\n\t\t\t\t\tthis.requestRender();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tthis.clearOverlayFocusRestoreFor(entry);\n\t\t\t\tif (isFocused || unfocusOptions) {\n\t\t\t\t\tconst topVisible = this.getTopmostVisibleOverlay();\n\t\t\t\t\tconst fallbackTarget = topVisible && topVisible !== entry ? topVisible.component : entry.preFocus;\n\t\t\t\t\tthis.setFocus(unfocusOptions ? unfocusOptions.target : fallbackTarget, { reason: \"overlay-unfocus\" });\n\t\t\t\t}\n\t\t\t\tthis.requestRender();\n\t\t\t},\n\t\t\tisFocused: () => this.focusedComponent === component,\n\t\t\tgetBounds: () => {\n\t\t\t\tif (!this.overlayStack.includes(entry) || !this.isOverlayVisible(entry) || !entry.bounds) return undefined;\n\t\t\t\treturn { ...entry.bounds };\n\t\t\t},\n\t\t};\n\t}\n\n\t/** Hide the topmost overlay and restore previous focus. */\n\thideOverlay(): void {\n\t\tconst overlay = this.overlayStack[this.overlayStack.length - 1];\n\t\tif (!overlay) return;\n\t\tthis.clearOverlayFocusRestoreFor(overlay);\n\t\tthis.retargetOverlayPreFocus(overlay);\n\t\tthis.overlayStack.pop();\n\t\tif (this.focusedComponent === overlay.component) {\n\t\t\t// Find topmost visible overlay, or fall back to preFocus\n\t\t\tconst topVisible = this.getTopmostVisibleOverlay();\n\t\t\tthis.setFocus(topVisible?.component ?? overlay.preFocus, { reason: \"overlay-hide\" });\n\t\t}\n\t\tif (this.overlayStack.length === 0) this.terminal.hideCursor();\n\t\tthis.requestRender();\n\t}\n\n\t/** Check if there are any visible overlays */\n\thasOverlay(): boolean {\n\t\treturn this.overlayStack.some((o) => this.isOverlayVisible(o));\n\t}\n\n\t/** Check if the focused component is a visible overlay */\n\tprotected isOverlayFocused(): boolean {\n\t\treturn this.overlayStack.some(\n\t\t\t(entry) => entry.component === this.focusedComponent && this.isOverlayVisible(entry),\n\t\t);\n\t}\n\n\t/**\n\t * Dismiss the innermost Escape-dismissable layer. Order: open autocomplete\n\t * on the focused component first, then (in subclasses) viewport layers such\n\t * as transcript search, then forward to the topmost capturing overlay when\n\t * focus drifted outside the overlay stack. Returns true when exactly one\n\t * layer consumed the press; callers must not forward it further.\n\t */\n\tpublic dismissInnermostLayer(data: string): boolean {\n\t\tconst focused = this.focusedComponent;\n\t\tif (isAutocompleteHost(focused) && focused.isShowingAutocomplete()) {\n\t\t\tfocused.dismissAutocomplete();\n\t\t\treturn true;\n\t\t}\n\t\t// Focus drifted outside the overlay stack while a capturing layer is\n\t\t// open: the topmost layer owns Escape, so deliver it there instead of\n\t\t// leaking the press to the unfocused base component below.\n\t\tif (!this.isFocusInVisibleOverlay()) {\n\t\t\tconst topmost = this.getTopmostVisibleCapturingOverlay();\n\t\t\tif (topmost?.handleInput) {\n\t\t\t\ttopmost.handleInput(data);\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\t/** Topmost visible capturing overlay component, if any. */\n\tprotected getTopmostVisibleCapturingOverlay(): Component | undefined {\n\t\treturn this.getTopmostVisibleOverlay()?.component;\n\t}\n\n\t/**\n\t * Whether a component lives inside a visible overlay. With `capturingOnly`,\n\t * non-capturing overlays do not count.\n\t */\n\tprotected isComponentInVisibleOverlay(component: Component, capturingOnly = false): boolean {\n\t\treturn this.overlayStack.some(\n\t\t\t(entry) =>\n\t\t\t\tthis.isOverlayVisible(entry) &&\n\t\t\t\t(!capturingOnly || !entry.options?.nonCapturing) &&\n\t\t\t\t(entry.component === component || this.containsComponent(entry.component, component)),\n\t\t);\n\t}\n\n\t/** Whether keyboard focus currently sits inside a visible overlay. */\n\tprotected isFocusInVisibleOverlay(capturingOnly = false): boolean {\n\t\treturn this.focusedComponent !== null && this.isComponentInVisibleOverlay(this.focusedComponent, capturingOnly);\n\t}\n\n\t/** Keep overlay containers as keyboard focus owners when a nested control is clicked. */\n\tprotected resolveMouseFocusTarget(component: Component): Component {\n\t\tfor (let index = this.overlayStack.length - 1; index >= 0; index--) {\n\t\t\tconst overlay = this.overlayStack[index]!;\n\t\t\tif (this.isOverlayVisible(overlay) && this.containsComponent(overlay.component, component)) {\n\t\t\t\treturn overlay.component;\n\t\t\t}\n\t\t}\n\t\treturn component;\n\t}\n\n\t/** Dispatch to the visually topmost overlay under the pointer. */\n\tprotected dispatchMouseToOverlay(event: TuiMouseEvent): { hit: boolean; result?: TuiMouseDispatchResult } {\n\t\tfor (let index = this.renderedOverlayLayouts.length - 1; index >= 0; index--) {\n\t\t\tconst layout = this.renderedOverlayLayouts[index]!;\n\t\t\tif (\n\t\t\t\tevent.screenX < layout.col ||\n\t\t\t\tevent.screenX >= layout.col + layout.width ||\n\t\t\t\tevent.screenY < layout.row ||\n\t\t\t\tevent.screenY >= layout.row + layout.height\n\t\t\t) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst result = dispatchMouseEvent(layout.entry.component, {\n\t\t\t\t...event,\n\t\t\t\tx: event.screenX - layout.col,\n\t\t\t\ty: event.screenY - layout.row,\n\t\t\t\twidth: layout.width,\n\t\t\t\theight: layout.height,\n\t\t\t});\n\t\t\treturn result\n\t\t\t\t? {\n\t\t\t\t\t\thit: true,\n\t\t\t\t\t\tresult: result.focus ? { ...result, focusTarget: layout.entry.component } : result,\n\t\t\t\t\t}\n\t\t\t\t: { hit: true };\n\t\t}\n\t\treturn { hit: false };\n\t}\n\n\t/** Check if an overlay entry is currently visible */\n\tprivate isOverlayVisible(entry: OverlayStackEntry): boolean {\n\t\tif (entry.hidden) return false;\n\t\tif (entry.options?.visible) {\n\t\t\treturn entry.options.visible(this.terminal.columns, this.terminal.rows);\n\t\t}\n\t\treturn true;\n\t}\n\n\t/** Find the visual-frontmost visible capturing overlay, if any */\n\tprivate getTopmostVisibleOverlay(): OverlayStackEntry | undefined {\n\t\tlet topmost: OverlayStackEntry | undefined;\n\t\tfor (const overlay of this.overlayStack) {\n\t\t\tif (overlay.options?.nonCapturing || !this.isOverlayVisible(overlay)) continue;\n\t\t\tif (!topmost || overlay.focusOrder > topmost.focusOrder) {\n\t\t\t\ttopmost = overlay;\n\t\t\t}\n\t\t}\n\t\treturn topmost;\n\t}\n\n\toverride invalidate(): void {\n\t\tfor (const root of this.getMountedRoots()) root.invalidate();\n\t\tfor (const overlay of this.overlayStack) overlay.component.invalidate();\n\t}\n\n\tstart(): void {\n\t\tthis.stopped = false;\n\t\tthis.beforeTerminalStart();\n\t\tthis.terminal.start(\n\t\t\t(data) => this.handleTerminalInput(data),\n\t\t\t() => this.requestRender(),\n\t\t);\n\t\tthis.afterTerminalStart();\n\t\tthis.terminal.hideCursor();\n\t\tif (this.terminalColorSchemeNotificationsEnabled) {\n\t\t\tthis.terminal.write(\"\\x1b[?2031h\");\n\t\t}\n\t\tthis.queryCellSize();\n\t\tthis.requestRender();\n\t}\n\n\taddInputListener(listener: TuiInputListener): () => void {\n\t\tthis.inputListeners.add(listener);\n\t\treturn () => {\n\t\t\tthis.inputListeners.delete(listener);\n\t\t};\n\t}\n\n\tremoveInputListener(listener: TuiInputListener): void {\n\t\tthis.inputListeners.delete(listener);\n\t}\n\n\tonTerminalColorSchemeChange(listener: (scheme: TerminalColorScheme) => void): () => void {\n\t\tthis.terminalColorSchemeListeners.add(listener);\n\t\treturn () => {\n\t\t\tthis.terminalColorSchemeListeners.delete(listener);\n\t\t};\n\t}\n\n\tsetTerminalColorSchemeNotifications(enabled: boolean): void {\n\t\tif (this.terminalColorSchemeNotificationsEnabled === enabled) {\n\t\t\treturn;\n\t\t}\n\t\tthis.terminalColorSchemeNotificationsEnabled = enabled;\n\t\tif (!this.stopped) {\n\t\t\tthis.terminal.write(enabled ? \"\\x1b[?2031h\" : \"\\x1b[?2031l\");\n\t\t}\n\t}\n\n\tprivate queryCellSize(): void {\n\t\t// Only query if terminal supports images (cell size is only used for image rendering)\n\t\tif (!getCapabilities().images) {\n\t\t\treturn;\n\t\t}\n\t\t// Query terminal for cell size in pixels: CSI 16 t\n\t\t// Response format: CSI 6 ; height ; width t\n\t\tthis.terminal.write(\"\\x1b[16t\");\n\t}\n\n\tstop(options: TuiStopOptions = {}): void {\n\t\tthis.stopped = true;\n\t\tthis.cancelRenderTimer();\n\t\tif (this.terminalColorSchemeNotificationsEnabled) {\n\t\t\tthis.terminal.write(\"\\x1b[?2031l\");\n\t\t}\n\t\tthis.beforeTerminalStop(options);\n\t\tthis.terminal.showCursor();\n\t\tthis.terminal.stop();\n\t\tthis.afterTerminalStop(options);\n\t}\n\n\trenderNow(force = false): void {\n\t\tif (force) this.resetRenderState();\n\t\tthis.renderRequested = false;\n\t\tthis.cancelRenderTimer();\n\t\tthis.lastRenderAt = performance.now();\n\t\tthis.doRender();\n\t}\n\n\trequestRender(force = false): void {\n\t\tif (force) {\n\t\t\tthis.resetRenderState();\n\t\t\tthis.requestImmediateRender();\n\t\t\treturn;\n\t\t}\n\t\tif (this.renderRequested) return;\n\t\tthis.renderRequested = true;\n\t\tprocess.nextTick(() => this.scheduleRender());\n\t}\n\n\tprivate requestImmediateRender(): void {\n\t\tthis.cancelRenderTimer();\n\t\tthis.renderRequested = true;\n\t\tif (this.immediateRenderScheduled) return;\n\t\tthis.immediateRenderScheduled = true;\n\t\tprocess.nextTick(() => {\n\t\t\tthis.immediateRenderScheduled = false;\n\t\t\tif (this.stopped || !this.renderRequested) return;\n\t\t\t// A previously queued scheduleRender() can create a timer before this\n\t\t\t// callback runs. User input must preempt that throttled frame.\n\t\t\tthis.cancelRenderTimer();\n\t\t\tthis.renderRequested = false;\n\t\t\tthis.lastRenderAt = performance.now();\n\t\t\tthis.doRender();\n\t\t});\n\t}\n\n\tprivate cancelRenderTimer(): void {\n\t\tif (!this.renderTimer) return;\n\t\tclearTimeout(this.renderTimer);\n\t\tthis.renderTimer = undefined;\n\t}\n\n\tprivate scheduleRender(): void {\n\t\tif (this.stopped || this.renderTimer || !this.renderRequested) {\n\t\t\treturn;\n\t\t}\n\t\tconst elapsed = performance.now() - this.lastRenderAt;\n\t\tconst delay = Math.max(0, TuiBase.MIN_RENDER_INTERVAL_MS - elapsed);\n\t\tthis.renderTimer = setTimeout(() => {\n\t\t\tthis.renderTimer = undefined;\n\t\t\tif (this.stopped || !this.renderRequested) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthis.renderRequested = false;\n\t\t\tthis.lastRenderAt = performance.now();\n\t\t\tthis.doRender();\n\t\t\tif (this.renderRequested) {\n\t\t\t\tthis.scheduleRender();\n\t\t\t}\n\t\t}, delay);\n\t}\n\n\tprivate handleTerminalInput(data: string): void {\n\t\tif (this.consumeOsc11BackgroundResponse(data)) {\n\t\t\treturn;\n\t\t}\n\t\tif (this.consumeTerminalColorSchemeReport(data)) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.inputListeners.size > 0) {\n\t\t\tlet current = data;\n\t\t\tfor (const listener of this.inputListeners) {\n\t\t\t\tconst result = listener(current);\n\t\t\t\tif (result?.consume) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (result?.data !== undefined) {\n\t\t\t\t\tcurrent = result.data;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (current.length === 0) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tdata = current;\n\t\t}\n\n\t\t// Consume terminal cell size responses without blocking unrelated input.\n\t\tif (this.consumeCellSizeResponse(data)) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Global debug key handler (Shift+Ctrl+D)\n\t\tif (matchesKey(data, \"shift+ctrl+d\") && this.onDebug) {\n\t\t\tthis.onDebug();\n\t\t\treturn;\n\t\t}\n\n\t\t// If focused component is an overlay, verify it's still visible\n\t\t// (visibility can change due to terminal resize or visible() callback)\n\t\tconst focusedOverlay = this.overlayStack.find((o) => o.component === this.focusedComponent);\n\t\tif (focusedOverlay && !this.isOverlayVisible(focusedOverlay)) {\n\t\t\t// Focused overlay is no longer visible, redirect to topmost visible overlay\n\t\t\tconst topVisible = this.getTopmostVisibleOverlay();\n\t\t\tif (topVisible) {\n\t\t\t\tthis.setFocus(topVisible.component, { reason: \"overlay-visibility\" });\n\t\t\t} else {\n\t\t\t\tthis.setFocusInternal({\n\t\t\t\t\tcomponent: focusedOverlay.preFocus,\n\t\t\t\t\toverlayFocusRestore: \"preserve\",\n\t\t\t\t\treason: \"overlay-visibility\",\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tconst focusIsOverlay = this.overlayStack.some((o) => o.component === this.focusedComponent);\n\t\t// Escape unwinds exactly one layer per press, innermost first, and a\n\t\t// consumed press never leaks to the layer below. Presses only: repeats\n\t\t// must not blow through stacked layers while the key is held.\n\t\tconst isEscapePress =\n\t\t\t!isKeyRelease(data) &&\n\t\t\t!isKeyRepeat(data) &&\n\t\t\t(matchesKey(data, \"escape\") || getKeybindings().matches(data, \"tui.altScreen.searchClose\"));\n\t\tif (isEscapePress) {\n\t\t\t// The focused layer gets first refusal before overlay restoration\n\t\t\t// runs, so an autocomplete dropdown open above a dialog closes\n\t\t\t// first and the next press reaches the dialog.\n\t\t\tconst focused = this.focusedComponent;\n\t\t\tif (isAutocompleteHost(focused) && focused.isShowingAutocomplete()) {\n\t\t\t\tfocused.dismissAutocomplete();\n\t\t\t\t// Keyboard input is latency-sensitive. Avoid the throttled timer\n\t\t\t\t// path, where even setTimeout(0) can take a full 16 ms tick on Windows.\n\t\t\t\tthis.requestImmediateRender();\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tif (!focusIsOverlay) {\n\t\t\tconst restoreState = this.getVisibleOverlayFocusRestore();\n\t\t\tif (restoreState.status === \"eligible\") {\n\t\t\t\tthis.setFocus(restoreState.overlay.component, { reason: \"overlay-restore\" });\n\t\t\t} else if (restoreState.status === \"blocked\" && restoreState.blockedBy !== this.focusedComponent) {\n\t\t\t\tif (restoreState.resume.status === \"restore-overlay\") {\n\t\t\t\t\tthis.setFocus(restoreState.overlay.component, { reason: \"overlay-restore\" });\n\t\t\t\t} else {\n\t\t\t\t\tthis.clearOverlayFocusRestore();\n\t\t\t\t\tthis.setFocus(restoreState.resume.target, { reason: \"overlay-restore\" });\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Escape unwinds exactly one layer per press, innermost first, and a\n\t\t// consumed press never leaks to the layer below.\n\t\tif (isEscapePress && this.dismissInnermostLayer(data)) {\n\t\t\t// Keyboard input is latency-sensitive. Avoid the throttled timer path,\n\t\t\t// where even setTimeout(0) can take a full 16 ms tick on Windows.\n\t\t\tthis.requestImmediateRender();\n\t\t\treturn;\n\t\t}\n\n\t\t// Pass input to focused component (including Ctrl+C)\n\t\t// The focused component can decide how to handle Ctrl+C\n\t\tif (this.focusedComponent?.handleInput) {\n\t\t\t// Filter out key release events unless component opts in\n\t\t\tif (isKeyRelease(data) && !this.focusedComponent.wantsKeyRelease) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthis.focusedComponent.handleInput(data);\n\t\t\t// Keyboard input is latency-sensitive. Avoid the throttled timer path,\n\t\t\t// where even setTimeout(0) can take a full 16 ms tick on Windows.\n\t\t\tthis.requestImmediateRender();\n\t\t}\n\t}\n\n\tprivate consumeOsc11BackgroundResponse(data: string): boolean {\n\t\tif (this.pendingOsc11BackgroundReplies <= 0) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif (!isOsc11BackgroundColorResponse(data)) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst rgb = parseOsc11BackgroundColor(data);\n\t\tthis.pendingOsc11BackgroundReplies -= 1;\n\t\tconst query = this.pendingOsc11BackgroundQueries.shift();\n\t\tif (query && !query.settled) {\n\t\t\tquery.settled = true;\n\t\t\tif (query.timer) {\n\t\t\t\tclearTimeout(query.timer);\n\t\t\t\tquery.timer = undefined;\n\t\t\t}\n\t\t\tquery.resolve?.(rgb);\n\t\t\tquery.resolve = undefined;\n\t\t}\n\t\treturn true;\n\t}\n\n\tprivate consumeTerminalColorSchemeReport(data: string): boolean {\n\t\tconst scheme = parseTerminalColorSchemeReport(data);\n\t\tif (!scheme) {\n\t\t\treturn false;\n\t\t}\n\n\t\tfor (const listener of this.terminalColorSchemeListeners) {\n\t\t\tlistener(scheme);\n\t\t}\n\t\treturn true;\n\t}\n\n\tprivate consumeCellSizeResponse(data: string): boolean {\n\t\t// Response format: ESC [ 6 ; height ; width t\n\t\tconst match = data.match(/^\\x1b\\[6;(\\d+);(\\d+)t$/);\n\t\tif (!match) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst heightPx = parseInt(match[1], 10);\n\t\tconst widthPx = parseInt(match[2], 10);\n\t\tif (heightPx <= 0 || widthPx <= 0) {\n\t\t\treturn true;\n\t\t}\n\n\t\tsetCellDimensions({ widthPx, heightPx });\n\t\t// Invalidate all components so images re-render with correct dimensions.\n\t\tthis.invalidate();\n\t\tthis.requestRender();\n\t\treturn true;\n\t}\n\n\t/**\n\t * Resolve overlay layout from options.\n\t * Returns { width, row, col, maxHeight } for rendering.\n\t */\n\tprivate resolveOverlayLayout(\n\t\toptions: OverlayOptions | undefined,\n\t\toverlayHeight: number,\n\t\ttermWidth: number,\n\t\ttermHeight: number,\n\t): { width: number; row: number; col: number; maxHeight: number | undefined } {\n\t\tconst opt = options ?? {};\n\n\t\t// Parse margin (clamp to non-negative)\n\t\tconst margin =\n\t\t\ttypeof opt.margin === \"number\"\n\t\t\t\t? { top: opt.margin, right: opt.margin, bottom: opt.margin, left: opt.margin }\n\t\t\t\t: (opt.margin ?? {});\n\t\tconst marginTop = Math.max(0, margin.top ?? 0);\n\t\tconst marginRight = Math.max(0, margin.right ?? 0);\n\t\tconst marginBottom = Math.max(0, margin.bottom ?? 0);\n\t\tconst marginLeft = Math.max(0, margin.left ?? 0);\n\n\t\t// Available space after margins\n\t\tconst availWidth = Math.max(1, termWidth - marginLeft - marginRight);\n\t\tconst availHeight = Math.max(1, termHeight - marginTop - marginBottom);\n\n\t\t// === Resolve width ===\n\t\tlet width = parseSizeValue(opt.width, termWidth) ?? Math.min(80, availWidth);\n\t\t// Apply minWidth\n\t\tif (opt.minWidth !== undefined) {\n\t\t\twidth = Math.max(width, opt.minWidth);\n\t\t}\n\t\t// Clamp to available space\n\t\twidth = Math.max(1, Math.min(width, availWidth));\n\n\t\t// === Resolve maxHeight ===\n\t\tlet maxHeight = parseSizeValue(opt.maxHeight, termHeight);\n\t\t// Clamp to available space\n\t\tif (maxHeight !== undefined) {\n\t\t\tmaxHeight = Math.max(1, Math.min(maxHeight, availHeight));\n\t\t}\n\n\t\t// Effective overlay height (may be clamped by maxHeight)\n\t\tconst effectiveHeight = maxHeight !== undefined ? Math.min(overlayHeight, maxHeight) : overlayHeight;\n\n\t\t// === Resolve position ===\n\t\tlet row: number;\n\t\tlet col: number;\n\n\t\tif (opt.row !== undefined) {\n\t\t\tif (typeof opt.row === \"string\") {\n\t\t\t\t// Percentage: 0% = top, 100% = bottom (overlay stays within bounds)\n\t\t\t\tconst match = opt.row.match(/^(\\d+(?:\\.\\d+)?)%$/);\n\t\t\t\tif (match) {\n\t\t\t\t\tconst maxRow = Math.max(0, availHeight - effectiveHeight);\n\t\t\t\t\tconst percent = parseFloat(match[1]) / 100;\n\t\t\t\t\trow = marginTop + Math.floor(maxRow * percent);\n\t\t\t\t} else {\n\t\t\t\t\t// Invalid format, fall back to center\n\t\t\t\t\trow = this.resolveAnchorRow(\"center\", effectiveHeight, availHeight, marginTop);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Absolute row position\n\t\t\t\trow = opt.row;\n\t\t\t}\n\t\t} else {\n\t\t\t// Anchor-based (default: center)\n\t\t\tconst anchor = opt.anchor ?? \"center\";\n\t\t\trow = this.resolveAnchorRow(anchor, effectiveHeight, availHeight, marginTop);\n\t\t}\n\n\t\tif (opt.col !== undefined) {\n\t\t\tif (typeof opt.col === \"string\") {\n\t\t\t\t// Percentage: 0% = left, 100% = right (overlay stays within bounds)\n\t\t\t\tconst match = opt.col.match(/^(\\d+(?:\\.\\d+)?)%$/);\n\t\t\t\tif (match) {\n\t\t\t\t\tconst maxCol = Math.max(0, availWidth - width);\n\t\t\t\t\tconst percent = parseFloat(match[1]) / 100;\n\t\t\t\t\tcol = marginLeft + Math.floor(maxCol * percent);\n\t\t\t\t} else {\n\t\t\t\t\t// Invalid format, fall back to center\n\t\t\t\t\tcol = this.resolveAnchorCol(\"center\", width, availWidth, marginLeft);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Absolute column position\n\t\t\t\tcol = opt.col;\n\t\t\t}\n\t\t} else {\n\t\t\t// Anchor-based (default: center)\n\t\t\tconst anchor = opt.anchor ?? \"center\";\n\t\t\tcol = this.resolveAnchorCol(anchor, width, availWidth, marginLeft);\n\t\t}\n\n\t\t// Apply offsets\n\t\tif (opt.offsetY !== undefined) row += opt.offsetY;\n\t\tif (opt.offsetX !== undefined) col += opt.offsetX;\n\n\t\t// Clamp to terminal bounds (respecting margins)\n\t\trow = Math.max(marginTop, Math.min(row, termHeight - marginBottom - effectiveHeight));\n\t\tcol = Math.max(marginLeft, Math.min(col, termWidth - marginRight - width));\n\n\t\treturn { width, row, col, maxHeight };\n\t}\n\n\tprivate resolveAnchorRow(anchor: OverlayAnchor, height: number, availHeight: number, marginTop: number): number {\n\t\tswitch (anchor) {\n\t\t\tcase \"top-left\":\n\t\t\tcase \"top-center\":\n\t\t\tcase \"top-right\":\n\t\t\t\treturn marginTop;\n\t\t\tcase \"bottom-left\":\n\t\t\tcase \"bottom-center\":\n\t\t\tcase \"bottom-right\":\n\t\t\t\treturn marginTop + availHeight - height;\n\t\t\tcase \"left-center\":\n\t\t\tcase \"center\":\n\t\t\tcase \"right-center\":\n\t\t\t\treturn marginTop + Math.floor((availHeight - height) / 2);\n\t\t}\n\t}\n\n\tprivate resolveAnchorCol(anchor: OverlayAnchor, width: number, availWidth: number, marginLeft: number): number {\n\t\tswitch (anchor) {\n\t\t\tcase \"top-left\":\n\t\t\tcase \"left-center\":\n\t\t\tcase \"bottom-left\":\n\t\t\t\treturn marginLeft;\n\t\t\tcase \"top-right\":\n\t\t\tcase \"right-center\":\n\t\t\tcase \"bottom-right\":\n\t\t\t\treturn marginLeft + availWidth - width;\n\t\t\tcase \"top-center\":\n\t\t\tcase \"center\":\n\t\t\tcase \"bottom-center\":\n\t\t\t\treturn marginLeft + Math.floor((availWidth - width) / 2);\n\t\t}\n\t}\n\n\t/** Composite all overlays into content lines (sorted by focusOrder, higher = on top). */\n\tprotected compositeOverlays(lines: string[], termWidth: number, termHeight: number): string[] {\n\t\tif (this.overlayStack.length === 0) {\n\t\t\tthis.renderedOverlayLayouts = [];\n\t\t\treturn lines;\n\t\t}\n\t\tconst result = [...lines];\n\n\t\tfor (const entry of this.overlayStack) entry.bounds = undefined;\n\n\t\t// Pre-render all visible overlays and calculate positions\n\t\tconst rendered: { entry: OverlayStackEntry; overlayLines: string[]; row: number; col: number; w: number }[] = [];\n\t\tlet minLinesNeeded = result.length;\n\n\t\tconst visibleEntries = this.overlayStack.filter((e) => this.isOverlayVisible(e));\n\t\tvisibleEntries.sort((a, b) => a.focusOrder - b.focusOrder);\n\t\tfor (const entry of visibleEntries) {\n\t\t\tconst { component, options } = entry;\n\n\t\t\t// Get layout with height=0 first to determine width and maxHeight\n\t\t\t// (width and maxHeight don't depend on overlay height)\n\t\t\tconst { width, maxHeight } = this.resolveOverlayLayout(options, 0, termWidth, termHeight);\n\n\t\t\t// Render component at calculated width\n\t\t\tlet overlayLines = component.render(width);\n\n\t\t\t// Apply maxHeight if specified\n\t\t\tif (maxHeight !== undefined && overlayLines.length > maxHeight) {\n\t\t\t\toverlayLines = overlayLines.slice(0, maxHeight);\n\t\t\t}\n\n\t\t\t// Get final row/col with actual overlay height\n\t\t\tconst { row, col } = this.resolveOverlayLayout(options, overlayLines.length, termWidth, termHeight);\n\t\t\tentry.bounds = { row, col, width, height: overlayLines.length };\n\n\t\t\trendered.push({ entry, overlayLines, row, col, w: width });\n\t\t\tminLinesNeeded = Math.max(minLinesNeeded, row + overlayLines.length);\n\t\t}\n\t\tthis.renderedOverlayLayouts = rendered.map(({ entry, row, col, w, overlayLines }) => ({\n\t\t\tentry,\n\t\t\trow,\n\t\t\tcol,\n\t\t\twidth: w,\n\t\t\theight: overlayLines.length,\n\t\t}));\n\n\t\t// Pad to at least terminal height so overlays have screen-relative positions.\n\t\t// Excludes maxLinesRendered: the historical high-water mark caused self-reinforcing\n\t\t// inflation that pushed content into scrollback on terminal widen.\n\t\tconst workingHeight = Math.max(result.length, termHeight, minLinesNeeded);\n\n\t\t// Extend result with empty lines if content is too short for overlay placement or working area\n\t\twhile (result.length < workingHeight) {\n\t\t\tresult.push(\"\");\n\t\t}\n\n\t\tconst viewportStart = Math.max(0, workingHeight - termHeight);\n\n\t\t// Composite each overlay\n\t\tfor (const { overlayLines, row, col, w } of rendered) {\n\t\t\tfor (let i = 0; i < overlayLines.length; i++) {\n\t\t\t\tconst idx = viewportStart + row + i;\n\t\t\t\tif (idx >= 0 && idx < result.length) {\n\t\t\t\t\t// Defensive: truncate overlay line to declared width before compositing\n\t\t\t\t\t// (components should already respect width, but this ensures it)\n\t\t\t\t\tconst truncatedOverlayLine =\n\t\t\t\t\t\tvisibleWidth(overlayLines[i]) > w ? sliceByColumn(overlayLines[i], 0, w, true) : overlayLines[i];\n\t\t\t\t\tresult[idx] = this.compositeLineAt(result[idx], truncatedOverlayLine, col, w, termWidth);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn result;\n\t}\n\n\tprotected applyLineResets(lines: string[]): string[] {\n\t\tconst reset = SEGMENT_RESET;\n\t\tfor (let i = 0; i < lines.length; i++) {\n\t\t\tconst line = lines[i];\n\t\t\tif (!isImageLine(line)) {\n\t\t\t\tlines[i] = normalizeTerminalOutput(line) + reset;\n\t\t\t}\n\t\t}\n\t\treturn lines;\n\t}\n\n\tprivate compositeLineAt(\n\t\tbaseLine: string,\n\t\toverlayLine: string,\n\t\tstartCol: number,\n\t\toverlayWidth: number,\n\t\ttotalWidth: number,\n\t): string {\n\t\treturn compositeTuiLine(baseLine, overlayLine, startCol, overlayWidth, totalWidth);\n\t}\n\n\t/**\n\t * Find and extract cursor position from rendered lines.\n\t * Searches for CURSOR_MARKER, calculates its position, and strips it from the output.\n\t * Only scans the bottom terminal height lines (visible viewport).\n\t * @param lines - Rendered lines to search\n\t * @param height - Terminal height (visible viewport size)\n\t * @returns Cursor position { row, col } or null if no marker found\n\t */\n\tprotected extractCursorPosition(lines: string[], height: number): { row: number; col: number } | null {\n\t\t// Only scan the bottom `height` lines (visible viewport)\n\t\tconst viewportTop = Math.max(0, lines.length - height);\n\t\tfor (let row = lines.length - 1; row >= viewportTop; row--) {\n\t\t\tconst line = lines[row];\n\t\t\tconst markerIndex = line.indexOf(CURSOR_MARKER);\n\t\t\tif (markerIndex !== -1) {\n\t\t\t\t// Calculate visual column (width of text before marker)\n\t\t\t\tconst beforeMarker = line.slice(0, markerIndex);\n\t\t\t\tconst col = visibleWidth(beforeMarker);\n\n\t\t\t\t// Strip marker from the line\n\t\t\t\tlines[row] = line.slice(0, markerIndex) + line.slice(markerIndex + CURSOR_MARKER.length);\n\n\t\t\t\treturn { row, col };\n\t\t\t}\n\t\t}\n\t\treturn null;\n\t}\n\n\t/**\n\t * Query the terminal's default background color with OSC 11 (`ESC ] 11 ; ? BEL`).\n\t * @param timeoutMs Query timeout in milliseconds.\n\t * @returns Promise containing the parsed RGB color, or undefined if it times out or fails to parse.\n\t */\n\tqueryTerminalBackgroundColor({ timeoutMs }: { timeoutMs: number }): Promise<RgbColor | undefined> {\n\t\treturn new Promise((resolve) => {\n\t\t\tconst query: PendingOsc11BackgroundQuery = {\n\t\t\t\tsettled: false,\n\t\t\t\tresolve,\n\t\t\t\ttimer: undefined,\n\t\t\t};\n\n\t\t\tquery.timer = setTimeout(() => {\n\t\t\t\tif (query.settled) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tquery.settled = true;\n\t\t\t\tquery.timer = undefined;\n\t\t\t\tquery.resolve?.(undefined);\n\t\t\t\tquery.resolve = undefined;\n\t\t\t}, timeoutMs);\n\t\t\tthis.pendingOsc11BackgroundQueries.push(query);\n\t\t\tthis.pendingOsc11BackgroundReplies += 1;\n\t\t\tthis.terminal.write(\"\\x1b]11;?\\x07\");\n\t\t});\n\t}\n\n\t/**\n\t * Query the terminal's color-scheme preference with DSR (`CSI ? 996 n`).\n\t * Terminals that support the color palette notification protocol reply with\n\t * `CSI ? 997 ; 1 n` for dark or `CSI ? 997 ; 2 n` for light.\n\t */\n\tqueryTerminalColorScheme({ timeoutMs }: { timeoutMs: number }): Promise<TerminalColorScheme | undefined> {\n\t\treturn new Promise((resolve) => {\n\t\t\tlet settled = false;\n\t\t\tlet timer: NodeJS.Timeout | undefined;\n\t\t\tlet unsubscribe: () => void = () => {};\n\t\t\tconst settle = (scheme: TerminalColorScheme | undefined) => {\n\t\t\t\tif (settled) return;\n\t\t\t\tsettled = true;\n\t\t\t\tif (timer) {\n\t\t\t\t\tclearTimeout(timer);\n\t\t\t\t\ttimer = undefined;\n\t\t\t\t}\n\t\t\t\tunsubscribe();\n\t\t\t\tresolve(scheme);\n\t\t\t};\n\n\t\t\tunsubscribe = this.onTerminalColorSchemeChange(settle);\n\t\t\ttimer = setTimeout(() => settle(undefined), timeoutMs);\n\t\t\tthis.terminal.write(\"\\x1b[?996n\");\n\t\t});\n\t}\n}\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic undo stack with clone-on-push semantics.
|
|
3
|
+
*
|
|
4
|
+
* Stores deep clones of state snapshots. Popped snapshots are returned
|
|
5
|
+
* directly (no re-cloning) since they are already detached.
|
|
6
|
+
*/
|
|
7
|
+
export declare class UndoStack<S> {
|
|
8
|
+
private stack;
|
|
9
|
+
/** Push a deep clone of the given state onto the stack. */
|
|
10
|
+
push(state: S): void;
|
|
11
|
+
/** Pop and return the most recent snapshot, or undefined if empty. */
|
|
12
|
+
pop(): S | undefined;
|
|
13
|
+
/** Remove all snapshots. */
|
|
14
|
+
clear(): void;
|
|
15
|
+
get length(): number;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=undo-stack.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"undo-stack.d.ts","sourceRoot":"","sources":["../src/undo-stack.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,qBAAa,SAAS,CAAC,CAAC;IACvB,OAAO,CAAC,KAAK,CAAW;IAExB,2DAA2D;IAC3D,IAAI,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,CAEnB;IAED,sEAAsE;IACtE,GAAG,IAAI,CAAC,GAAG,SAAS,CAEnB;IAED,4BAA4B;IAC5B,KAAK,IAAI,IAAI,CAEZ;IAED,IAAI,MAAM,IAAI,MAAM,CAEnB;CACD","sourcesContent":["/**\n * Generic undo stack with clone-on-push semantics.\n *\n * Stores deep clones of state snapshots. Popped snapshots are returned\n * directly (no re-cloning) since they are already detached.\n */\nexport class UndoStack<S> {\n\tprivate stack: S[] = [];\n\n\t/** Push a deep clone of the given state onto the stack. */\n\tpush(state: S): void {\n\t\tthis.stack.push(structuredClone(state));\n\t}\n\n\t/** Pop and return the most recent snapshot, or undefined if empty. */\n\tpop(): S | undefined {\n\t\treturn this.stack.pop();\n\t}\n\n\t/** Remove all snapshots. */\n\tclear(): void {\n\t\tthis.stack.length = 0;\n\t}\n\n\tget length(): number {\n\t\treturn this.stack.length;\n\t}\n}\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic undo stack with clone-on-push semantics.
|
|
3
|
+
*
|
|
4
|
+
* Stores deep clones of state snapshots. Popped snapshots are returned
|
|
5
|
+
* directly (no re-cloning) since they are already detached.
|
|
6
|
+
*/
|
|
7
|
+
export class UndoStack {
|
|
8
|
+
stack = [];
|
|
9
|
+
/** Push a deep clone of the given state onto the stack. */
|
|
10
|
+
push(state) {
|
|
11
|
+
this.stack.push(structuredClone(state));
|
|
12
|
+
}
|
|
13
|
+
/** Pop and return the most recent snapshot, or undefined if empty. */
|
|
14
|
+
pop() {
|
|
15
|
+
return this.stack.pop();
|
|
16
|
+
}
|
|
17
|
+
/** Remove all snapshots. */
|
|
18
|
+
clear() {
|
|
19
|
+
this.stack.length = 0;
|
|
20
|
+
}
|
|
21
|
+
get length() {
|
|
22
|
+
return this.stack.length;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=undo-stack.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"undo-stack.js","sourceRoot":"","sources":["../src/undo-stack.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,OAAO,SAAS;IACb,KAAK,GAAQ,EAAE,CAAC;IAExB,2DAA2D;IAC3D,IAAI,CAAC,KAAQ,EAAQ;QACpB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC;IAAA,CACxC;IAED,sEAAsE;IACtE,GAAG,GAAkB;QACpB,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;IAAA,CACxB;IAED,4BAA4B;IAC5B,KAAK,GAAS;QACb,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;IAAA,CACtB;IAED,IAAI,MAAM,GAAW;QACpB,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;IAAA,CACzB;CACD","sourcesContent":["/**\n * Generic undo stack with clone-on-push semantics.\n *\n * Stores deep clones of state snapshots. Popped snapshots are returned\n * directly (no re-cloning) since they are already detached.\n */\nexport class UndoStack<S> {\n\tprivate stack: S[] = [];\n\n\t/** Push a deep clone of the given state onto the stack. */\n\tpush(state: S): void {\n\t\tthis.stack.push(structuredClone(state));\n\t}\n\n\t/** Pop and return the most recent snapshot, or undefined if empty. */\n\tpop(): S | undefined {\n\t\treturn this.stack.pop();\n\t}\n\n\t/** Remove all snapshots. */\n\tclear(): void {\n\t\tthis.stack.length = 0;\n\t}\n\n\tget length(): number {\n\t\treturn this.stack.length;\n\t}\n}\n"]}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the shared grapheme segmenter instance.
|
|
3
|
+
*/
|
|
4
|
+
export declare function getGraphemeSegmenter(): Intl.Segmenter;
|
|
5
|
+
/**
|
|
6
|
+
* Get the shared word segmenter instance.
|
|
7
|
+
*/
|
|
8
|
+
export declare function getWordSegmenter(): Intl.Segmenter;
|
|
9
|
+
export declare const cjkBreakRegex: RegExp;
|
|
10
|
+
/**
|
|
11
|
+
* Calculate the visible width of a string in terminal columns.
|
|
12
|
+
*/
|
|
13
|
+
export declare function visibleWidth(str: string): number;
|
|
14
|
+
/** Remove ANSI, OSC, and APC control sequences while preserving visible text. */
|
|
15
|
+
export declare function stripTerminalSequences(str: string): string;
|
|
16
|
+
interface GraphemeCellRange {
|
|
17
|
+
start: number;
|
|
18
|
+
end: number;
|
|
19
|
+
}
|
|
20
|
+
/** Return the terminal-cell range occupied by the grapheme at a visible column. */
|
|
21
|
+
export declare function getGraphemeCellRange(line: string, column: number): GraphemeCellRange | undefined;
|
|
22
|
+
/** Return the OSC 8 hyperlink covering a visible terminal column. */
|
|
23
|
+
export declare function getOsc8LinkAtColumn(line: string, column: number): string | undefined;
|
|
24
|
+
export declare function normalizeTerminalOutput(str: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* Extract ANSI escape sequences from a string at the given position.
|
|
27
|
+
*/
|
|
28
|
+
export declare function extractAnsiCode(str: string, pos: number): {
|
|
29
|
+
code: string;
|
|
30
|
+
length: number;
|
|
31
|
+
} | null;
|
|
32
|
+
/** Return only the background color active at the end of an ANSI-styled string. */
|
|
33
|
+
export declare function getActiveBackgroundAnsi(text: string): string;
|
|
34
|
+
/**
|
|
35
|
+
* Wrap text with ANSI codes preserved.
|
|
36
|
+
*
|
|
37
|
+
* ONLY does word wrapping - NO padding, NO background colors.
|
|
38
|
+
* Returns lines where each line is <= width visible chars.
|
|
39
|
+
* Active ANSI codes are preserved across line breaks.
|
|
40
|
+
*
|
|
41
|
+
* @param text - Text to wrap (may contain ANSI codes and newlines)
|
|
42
|
+
* @param width - Maximum visible width per line
|
|
43
|
+
* @returns Array of wrapped lines (NOT padded to width)
|
|
44
|
+
*/
|
|
45
|
+
export declare function wrapTextWithAnsi(text: string, width: number): string[];
|
|
46
|
+
export declare const PUNCTUATION_REGEX: RegExp;
|
|
47
|
+
/**
|
|
48
|
+
* Check if a character is whitespace.
|
|
49
|
+
*/
|
|
50
|
+
export declare function isWhitespaceChar(char: string): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Check if a character is punctuation.
|
|
53
|
+
*/
|
|
54
|
+
export declare function isPunctuationChar(char: string): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Apply background color to a line, padding to full width.
|
|
57
|
+
*
|
|
58
|
+
* @param line - Line of text (may contain ANSI codes)
|
|
59
|
+
* @param width - Total width to pad to
|
|
60
|
+
* @param bgFn - Background color function
|
|
61
|
+
* @returns Line with background applied and padded to width
|
|
62
|
+
*/
|
|
63
|
+
export declare function applyBackgroundToLine(line: string, width: number, bgFn: (text: string) => string): string;
|
|
64
|
+
/**
|
|
65
|
+
* Truncate text to fit within a maximum visible width, adding ellipsis if needed.
|
|
66
|
+
* Optionally pad with spaces to reach exactly maxWidth.
|
|
67
|
+
* Properly handles ANSI escape codes (they don't count toward width).
|
|
68
|
+
*
|
|
69
|
+
* @param text - Text to truncate (may contain ANSI codes)
|
|
70
|
+
* @param maxWidth - Maximum visible width
|
|
71
|
+
* @param ellipsis - Ellipsis string to append when truncating (default: "...")
|
|
72
|
+
* @param pad - If true, pad result with spaces to exactly maxWidth (default: false)
|
|
73
|
+
* @returns Truncated text, optionally padded to exactly maxWidth
|
|
74
|
+
*/
|
|
75
|
+
export declare function truncateToWidth(text: string, maxWidth: number, ellipsis?: string, pad?: boolean): string;
|
|
76
|
+
/**
|
|
77
|
+
* Extract a range of visible columns from a line. Handles ANSI codes and wide chars.
|
|
78
|
+
* @param strict - If true, exclude wide chars at boundary that would extend past the range
|
|
79
|
+
*/
|
|
80
|
+
export declare function sliceByColumn(line: string, startCol: number, length: number, strict?: boolean): string;
|
|
81
|
+
/** Like sliceByColumn but also returns the actual visible width of the result. */
|
|
82
|
+
export declare function sliceWithWidth(line: string, startCol: number, length: number, strict?: boolean): {
|
|
83
|
+
text: string;
|
|
84
|
+
width: number;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Extract "before" and "after" segments from a line in a single pass.
|
|
88
|
+
* Used for overlay compositing where we need content before and after the overlay region.
|
|
89
|
+
* Preserves styling from before the overlay that should affect content after it.
|
|
90
|
+
*/
|
|
91
|
+
export declare function extractSegments(line: string, beforeEnd: number, afterStart: number, afterLen: number, strictAfter?: boolean): {
|
|
92
|
+
before: string;
|
|
93
|
+
beforeWidth: number;
|
|
94
|
+
after: string;
|
|
95
|
+
afterWidth: number;
|
|
96
|
+
};
|
|
97
|
+
export {};
|
|
98
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,IAAI,CAAC,SAAS,CAErD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAAC,SAAS,CAEjD;AAmCD,eAAO,MAAM,aAAa,QAC2H,CAAC;AAsLtJ;;GAEG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAuDhD;AAED,iFAAiF;AACjF,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAc1D;AAED,UAAU,iBAAiB;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACZ;AAED,mFAAmF;AACnF,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,iBAAiB,GAAG,SAAS,CAqBhG;AAED,qEAAqE;AACrE,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAsBpF;AAaD,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAsB3D;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG;I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E,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,WAAW,UAAQ,GACjB;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAiE5E","sourcesContent":["import { eastAsianWidth } from \"get-east-asian-width\";\n\n// segmenters (shared instance)\nconst graphemeSegmenter = new Intl.Segmenter(undefined, { granularity: \"grapheme\" });\nconst wordSegmenter = new Intl.Segmenter(undefined, { granularity: \"word\" });\n\n/**\n * Get the shared grapheme segmenter instance.\n */\nexport function getGraphemeSegmenter(): Intl.Segmenter {\n\treturn graphemeSegmenter;\n}\n\n/**\n * Get the shared word segmenter instance.\n */\nexport function getWordSegmenter(): Intl.Segmenter {\n\treturn wordSegmenter;\n}\n\n/**\n * Check if a grapheme cluster (after segmentation) could possibly be an RGI emoji.\n * This is a fast heuristic to avoid the expensive rgiEmojiRegex test.\n * The tested Unicode blocks are deliberately broad to account for future\n * Unicode additions.\n */\nfunction couldBeEmoji(segment: string): boolean {\n\tconst cp = segment.codePointAt(0)!;\n\treturn (\n\t\t(cp >= 0x1f000 && cp <= 0x1fbff) || // Emoji and Pictograph\n\t\t(cp >= 0x2300 && cp <= 0x23ff) || // Misc technical\n\t\t(cp >= 0x2600 && cp <= 0x27bf) || // Misc symbols, dingbats\n\t\t(cp >= 0x2b50 && cp <= 0x2b55) || // Specific stars/circles\n\t\tsegment.includes(\"\\uFE0F\") || // Contains VS16 (emoji presentation selector)\n\t\tsegment.length > 2 // Multi-codepoint sequences (ZWJ, skin tones, etc.)\n\t);\n}\n\n// Regexes for character classification (same as string-width library)\nconst zeroWidthRegex = /^(?:\\p{Default_Ignorable_Code_Point}|\\p{Control}|\\p{Mark}|\\p{Surrogate})+$/v;\nconst leadingNonPrintingRegex = /^[\\p{Default_Ignorable_Code_Point}\\p{Control}\\p{Format}\\p{Mark}\\p{Surrogate}]+/v;\nconst nonPrintingCharRegex = /^(?:\\p{Default_Ignorable_Code_Point}|\\p{Control}|\\p{Format}|\\p{Mark}|\\p{Surrogate})$/v;\nconst markCharRegex = /^\\p{Mark}$/v;\n// Marks that terminals allocate cells for when attached to a base character.\n// This includes Unicode spacing marks and non-spacing exceptions in legacy wcwidth tables.\nconst terminalSpacingMarkRegex =\n\t/^(?:[\\p{Spacing_Mark}--[\\u1734\\u302E\\u302F]]|[\\u065F\\u0F7F\\u102B\\u102C\\u1031\\u1033-\\u1035\\u1038\\u103A-\\u103E])+$/v;\nconst rgiEmojiRegex = /^\\p{RGI_Emoji}$/v;\n\n// Cache for non-ASCII strings\nconst WIDTH_CACHE_SIZE = 512;\nconst widthCache = new Map<string, number>();\n\nexport const cjkBreakRegex =\n\t/[\\p{Script_Extensions=Han}\\p{Script_Extensions=Hiragana}\\p{Script_Extensions=Katakana}\\p{Script_Extensions=Hangul}\\p{Script_Extensions=Bopomofo}]/u;\n\nfunction isPrintableAscii(str: string): boolean {\n\tfor (let i = 0; i < str.length; i++) {\n\t\tconst code = str.charCodeAt(i);\n\t\tif (code < 0x20 || code > 0x7e) {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n\nfunction truncateFragmentToWidth(text: string, maxWidth: number): { text: string; width: number } {\n\tif (maxWidth <= 0 || text.length === 0) {\n\t\treturn { text: \"\", width: 0 };\n\t}\n\n\tif (isPrintableAscii(text)) {\n\t\tconst clipped = text.slice(0, maxWidth);\n\t\treturn { text: clipped, width: clipped.length };\n\t}\n\n\tconst hasAnsi = text.includes(\"\\x1b\");\n\tconst hasTabs = text.includes(\"\\t\");\n\tif (!hasAnsi && !hasTabs) {\n\t\tlet result = \"\";\n\t\tlet width = 0;\n\t\tfor (const { segment } of graphemeSegmenter.segment(text)) {\n\t\t\tconst w = graphemeWidth(segment);\n\t\t\tif (width + w > maxWidth) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tresult += segment;\n\t\t\twidth += w;\n\t\t}\n\t\treturn { text: result, width };\n\t}\n\n\tlet result = \"\";\n\tlet width = 0;\n\tlet i = 0;\n\tlet pendingAnsi = \"\";\n\n\twhile (i < text.length) {\n\t\tconst ansi = extractAnsiCode(text, i);\n\t\tif (ansi) {\n\t\t\tpendingAnsi += ansi.code;\n\t\t\ti += ansi.length;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (text[i] === \"\\t\") {\n\t\t\tif (width + 3 > maxWidth) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (pendingAnsi) {\n\t\t\t\tresult += pendingAnsi;\n\t\t\t\tpendingAnsi = \"\";\n\t\t\t}\n\t\t\tresult += \"\\t\";\n\t\t\twidth += 3;\n\t\t\ti++;\n\t\t\tcontinue;\n\t\t}\n\n\t\tlet end = i;\n\t\twhile (end < text.length && text[end] !== \"\\t\") {\n\t\t\tconst nextAnsi = extractAnsiCode(text, end);\n\t\t\tif (nextAnsi) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tend++;\n\t\t}\n\n\t\tfor (const { segment } of graphemeSegmenter.segment(text.slice(i, end))) {\n\t\t\tconst w = graphemeWidth(segment);\n\t\t\tif (width + w > maxWidth) {\n\t\t\t\treturn { text: result, width };\n\t\t\t}\n\t\t\tif (pendingAnsi) {\n\t\t\t\tresult += pendingAnsi;\n\t\t\t\tpendingAnsi = \"\";\n\t\t\t}\n\t\t\tresult += segment;\n\t\t\twidth += w;\n\t\t}\n\t\ti = end;\n\t}\n\n\treturn { text: result, width };\n}\n\nfunction finalizeTruncatedResult(\n\tprefix: string,\n\tprefixWidth: number,\n\tellipsis: string,\n\tellipsisWidth: number,\n\tmaxWidth: number,\n\tpad: boolean,\n): string {\n\tconst reset = \"\\x1b[0m\";\n\tconst hyperlinkClose = getActiveOsc8Close(prefix);\n\tconst visibleWidth = prefixWidth + ellipsisWidth;\n\tlet result: string;\n\n\tif (ellipsis.length > 0) {\n\t\tresult = `${prefix}${hyperlinkClose}${reset}${ellipsis}${reset}`;\n\t} else {\n\t\tresult = `${prefix}${hyperlinkClose}${reset}`;\n\t}\n\n\treturn pad ? result + \" \".repeat(Math.max(0, maxWidth - visibleWidth)) : result;\n}\n\n/**\n * Calculate the terminal width of a single grapheme cluster.\n * Based on code from the string-width library, but includes a possible-emoji\n * check to avoid running the RGI_Emoji regex unnecessarily.\n */\nfunction graphemeWidth(segment: string): number {\n\tif (segment === \"\\t\") {\n\t\treturn 3;\n\t}\n\n\t// Some marks occupy cells even without a base character.\n\tif (terminalSpacingMarkRegex.test(segment)) {\n\t\treturn [...segment].length;\n\t}\n\n\t// Zero-width clusters\n\tif (zeroWidthRegex.test(segment)) {\n\t\treturn 0;\n\t}\n\n\t// Emoji check with pre-filter\n\tif (couldBeEmoji(segment) && rgiEmojiRegex.test(segment)) {\n\t\treturn 2;\n\t}\n\n\t// Get base visible codepoint\n\tconst base = segment.replace(leadingNonPrintingRegex, \"\");\n\tconst cp = base.codePointAt(0);\n\tif (cp === undefined) {\n\t\treturn 0;\n\t}\n\n\t// Regional indicator symbols (U+1F1E6..U+1F1FF) are often rendered as\n\t// full-width emoji in terminals, even when isolated during streaming.\n\t// Keep width conservative (2) to avoid terminal auto-wrap drift artifacts.\n\tif (cp >= 0x1f1e6 && cp <= 0x1f1ff) {\n\t\treturn 2;\n\t}\n\n\tlet width = eastAsianWidth(cp);\n\n\t// Intl.Segmenter can group multiple terminal-spacing code points into one\n\t// grapheme. Count trailing visible code points that terminals may allocate\n\t// cells for: Indic consonants after marks, halfwidth/fullwidth forms, and\n\t// Thai/Lao AM vowels.\n\tlet followsMark = false;\n\tconst chars = [...base];\n\tfor (const char of chars.slice(1)) {\n\t\tif (terminalSpacingMarkRegex.test(char)) {\n\t\t\twidth += 1;\n\t\t\tfollowsMark = false;\n\t\t} else if (markCharRegex.test(char)) {\n\t\t\tfollowsMark = true;\n\t\t} else if (!nonPrintingCharRegex.test(char)) {\n\t\t\tconst c = char.codePointAt(0)!;\n\t\t\tif (followsMark || (c >= 0xff00 && c <= 0xffef)) {\n\t\t\t\t// halfwidth + fullwidth forms\n\t\t\t\twidth += eastAsianWidth(c);\n\t\t\t} else if (c === 0x0e33 || c === 0x0eb3) {\n\t\t\t\twidth += 1;\n\t\t\t}\n\t\t\tfollowsMark = false;\n\t\t}\n\t}\n\n\treturn width;\n}\n\n/**\n * Calculate the visible width of a string in terminal columns.\n */\nexport function visibleWidth(str: string): number {\n\tif (str.length === 0) {\n\t\treturn 0;\n\t}\n\n\t// Fast path: pure ASCII printable\n\tif (isPrintableAscii(str)) {\n\t\treturn str.length;\n\t}\n\n\t// Check cache\n\tconst cached = widthCache.get(str);\n\tif (cached !== undefined) {\n\t\treturn cached;\n\t}\n\n\t// Normalize: tabs to 3 spaces, strip ANSI escape codes\n\tlet clean = str;\n\tif (str.includes(\"\\t\")) {\n\t\tclean = clean.replace(/\\t/g, \" \");\n\t}\n\tif (clean.includes(\"\\x1b\")) {\n\t\t// Strip supported ANSI/OSC/APC escape sequences in one pass.\n\t\t// This covers CSI styling/cursor codes, OSC hyperlinks and prompt markers,\n\t\t// and APC sequences like CURSOR_MARKER.\n\t\tlet stripped = \"\";\n\t\tlet i = 0;\n\t\twhile (i < clean.length) {\n\t\t\tconst ansi = extractAnsiCode(clean, i);\n\t\t\tif (ansi) {\n\t\t\t\ti += ansi.length;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tstripped += clean[i];\n\t\t\ti++;\n\t\t}\n\t\tclean = stripped;\n\t}\n\n\t// Calculate width\n\tlet width = 0;\n\tfor (const { segment } of graphemeSegmenter.segment(clean)) {\n\t\twidth += graphemeWidth(segment);\n\t}\n\n\t// Cache result\n\tif (widthCache.size >= WIDTH_CACHE_SIZE) {\n\t\tconst firstKey = widthCache.keys().next().value;\n\t\tif (firstKey !== undefined) {\n\t\t\twidthCache.delete(firstKey);\n\t\t}\n\t}\n\twidthCache.set(str, width);\n\n\treturn width;\n}\n\n/** Remove ANSI, OSC, and APC control sequences while preserving visible text. */\nexport function stripTerminalSequences(str: string): string {\n\tif (!str.includes(\"\\x1b\")) return str;\n\tlet result = \"\";\n\tlet i = 0;\n\twhile (i < str.length) {\n\t\tconst ansi = extractAnsiCode(str, i);\n\t\tif (ansi) {\n\t\t\ti += ansi.length;\n\t\t\tcontinue;\n\t\t}\n\t\tresult += str[i];\n\t\ti++;\n\t}\n\treturn result;\n}\n\ninterface GraphemeCellRange {\n\tstart: number;\n\tend: number;\n}\n\n/** Return the terminal-cell range occupied by the grapheme at a visible column. */\nexport function getGraphemeCellRange(line: string, column: number): GraphemeCellRange | undefined {\n\tlet currentCol = 0;\n\tlet i = 0;\n\twhile (i < line.length) {\n\t\tconst ansi = extractAnsiCode(line, i);\n\t\tif (ansi) {\n\t\t\ti += ansi.length;\n\t\t\tcontinue;\n\t\t}\n\t\tlet textEnd = i;\n\t\twhile (textEnd < line.length && !extractAnsiCode(line, textEnd)) textEnd++;\n\t\tfor (const { segment } of graphemeSegmenter.segment(line.slice(i, textEnd))) {\n\t\t\tconst width = graphemeWidth(segment);\n\t\t\tif (width > 0 && column >= currentCol && column < currentCol + width) {\n\t\t\t\treturn { start: currentCol, end: currentCol + width };\n\t\t\t}\n\t\t\tcurrentCol += width;\n\t\t}\n\t\ti = textEnd;\n\t}\n\treturn undefined;\n}\n\n/** Return the OSC 8 hyperlink covering a visible terminal column. */\nexport function getOsc8LinkAtColumn(line: string, column: number): string | undefined {\n\tlet activeUrl: string | undefined;\n\tlet currentCol = 0;\n\tlet i = 0;\n\twhile (i < line.length) {\n\t\tconst ansi = extractAnsiCode(line, i);\n\t\tif (ansi) {\n\t\t\tconst hyperlink = /^\\x1b\\]8;[^;]*;([^\\x07\\x1b]*)(?:\\x07|\\x1b\\\\)$/.exec(ansi.code);\n\t\t\tif (hyperlink) activeUrl = hyperlink[1] || undefined;\n\t\t\ti += ansi.length;\n\t\t\tcontinue;\n\t\t}\n\t\tlet textEnd = i;\n\t\twhile (textEnd < line.length && !extractAnsiCode(line, textEnd)) textEnd++;\n\t\tfor (const { segment } of graphemeSegmenter.segment(line.slice(i, textEnd))) {\n\t\t\tconst width = segment === \"\\t\" ? 3 : graphemeWidth(segment);\n\t\t\tif (column >= currentCol && column < currentCol + width) return activeUrl;\n\t\t\tcurrentCol += width;\n\t\t}\n\t\ti = textEnd;\n\t}\n\treturn undefined;\n}\n\n/**\n * Normalize text for terminal output without changing logical editor content.\n * Some terminals render precomposed Thai/Lao AM vowels inconsistently during\n * differential repaint. Their compatibility decompositions have the same cell\n * width but avoid stale-cell artifacts in terminal renderers. Visible tabs are\n * expanded to the fixed width used by layout so terminal tab stops cannot wrap\n * a logical line, while tabs inside terminal string sequences stay untouched.\n */\nconst THAI_LAO_AM_REGEX = /[\\u0e33\\u0eb3]/;\nconst THAI_LAO_AM_GLOBAL_REGEX = /[\\u0e33\\u0eb3]/g;\n\nexport function normalizeTerminalOutput(str: string): string {\n\tlet normalized = str;\n\tif (THAI_LAO_AM_REGEX.test(normalized)) {\n\t\tnormalized = normalized.replace(THAI_LAO_AM_GLOBAL_REGEX, (char) =>\n\t\t\tchar === \"\\u0e33\" ? \"\\u0e4d\\u0e32\" : \"\\u0ecd\\u0eb2\",\n\t\t);\n\t}\n\tif (!normalized.includes(\"\\t\")) return normalized;\n\n\tlet result = \"\";\n\tlet i = 0;\n\twhile (i < normalized.length) {\n\t\tconst ansi = extractAnsiCode(normalized, i);\n\t\tif (ansi) {\n\t\t\tresult += ansi.code;\n\t\t\ti += ansi.length;\n\t\t\tcontinue;\n\t\t}\n\t\tresult += normalized[i] === \"\\t\" ? \" \" : normalized[i];\n\t\ti++;\n\t}\n\treturn result;\n}\n\n/**\n * Extract ANSI escape sequences from a string at the given position.\n */\nexport function extractAnsiCode(str: string, pos: number): { code: string; length: number } | null {\n\tif (pos >= str.length || str[pos] !== \"\\x1b\") return null;\n\n\tconst next = str[pos + 1];\n\n\t// CSI sequence: ESC [ ... m/G/K/H/J\n\tif (next === \"[\") {\n\t\tlet j = pos + 2;\n\t\twhile (j < str.length && !/[mGKHJ]/.test(str[j]!)) j++;\n\t\tif (j < str.length) return { code: str.substring(pos, j + 1), length: j + 1 - pos };\n\t\treturn null;\n\t}\n\n\t// OSC sequence: ESC ] ... BEL or ESC ] ... ST (ESC \\)\n\t// Used for hyperlinks (OSC 8), window titles, etc.\n\tif (next === \"]\") {\n\t\tlet j = pos + 2;\n\t\twhile (j < str.length) {\n\t\t\tif (str[j] === \"\\x07\") return { code: str.substring(pos, j + 1), length: j + 1 - pos };\n\t\t\tif (str[j] === \"\\x1b\" && str[j + 1] === \"\\\\\") return { code: str.substring(pos, j + 2), length: j + 2 - pos };\n\t\t\tj++;\n\t\t}\n\t\treturn null;\n\t}\n\n\t// APC sequence: ESC _ ... BEL or ESC _ ... ST (ESC \\)\n\t// Used for cursor marker and application-specific commands\n\tif (next === \"_\") {\n\t\tlet j = pos + 2;\n\t\twhile (j < str.length) {\n\t\t\tif (str[j] === \"\\x07\") return { code: str.substring(pos, j + 1), length: j + 1 - pos };\n\t\t\tif (str[j] === \"\\x1b\" && str[j + 1] === \"\\\\\") return { code: str.substring(pos, j + 2), length: j + 2 - pos };\n\t\t\tj++;\n\t\t}\n\t\treturn null;\n\t}\n\n\treturn null;\n}\n\ntype Osc8Terminator = \"\\x07\" | \"\\x1b\\\\\";\n\ninterface ActiveHyperlink {\n\tparams: string;\n\turl: string;\n\tterminator: Osc8Terminator;\n}\n\nfunction parseOsc8Hyperlink(ansiCode: string): ActiveHyperlink | null | undefined {\n\tif (!ansiCode.startsWith(\"\\x1b]8;\")) {\n\t\treturn undefined;\n\t}\n\n\tconst terminator: Osc8Terminator = ansiCode.endsWith(\"\\x07\") ? \"\\x07\" : \"\\x1b\\\\\";\n\tconst body = ansiCode.slice(4, terminator === \"\\x07\" ? -1 : -2);\n\tconst separatorIndex = body.indexOf(\";\");\n\tif (separatorIndex === -1) {\n\t\treturn undefined;\n\t}\n\n\tconst params = body.slice(0, separatorIndex);\n\tconst url = body.slice(separatorIndex + 1);\n\tif (!url) {\n\t\treturn null;\n\t}\n\treturn { params, url, terminator };\n}\n\nfunction formatOsc8Hyperlink(hyperlink: ActiveHyperlink): string {\n\treturn `\\x1b]8;${hyperlink.params};${hyperlink.url}${hyperlink.terminator}`;\n}\n\nfunction formatOsc8Close(terminator: Osc8Terminator): string {\n\treturn `\\x1b]8;;${terminator}`;\n}\n\nfunction getActiveOsc8Close(prefix: string): string {\n\tif (!prefix.includes(\"\\x1b]8;\")) {\n\t\treturn \"\";\n\t}\n\n\tlet activeHyperlink: ActiveHyperlink | null = null;\n\tlet i = 0;\n\twhile (i < prefix.length) {\n\t\tconst ansi = extractAnsiCode(prefix, i);\n\t\tif (ansi) {\n\t\t\tconst hyperlink = parseOsc8Hyperlink(ansi.code);\n\t\t\tif (hyperlink !== undefined) {\n\t\t\t\tactiveHyperlink = hyperlink;\n\t\t\t}\n\t\t\ti += ansi.length;\n\t\t} else {\n\t\t\ti++;\n\t\t}\n\t}\n\treturn activeHyperlink ? formatOsc8Close(activeHyperlink.terminator) : \"\";\n}\n\n/**\n * Track active ANSI SGR codes to preserve styling across line breaks.\n */\nclass AnsiCodeTracker {\n\t// Track individual attributes separately so we can reset them specifically\n\tprivate bold = false;\n\tprivate dim = false;\n\tprivate italic = false;\n\tprivate underline = false;\n\tprivate blink = false;\n\tprivate inverse = false;\n\tprivate hidden = false;\n\tprivate strikethrough = false;\n\tprivate fgColor: string | null = null; // Stores the full code like \"31\" or \"38;5;240\"\n\tprivate bgColor: string | null = null; // Stores the full code like \"41\" or \"48;5;240\"\n\tprivate activeHyperlink: ActiveHyperlink | null = null;\n\n\tprocess(ansiCode: string): void {\n\t\t// OSC 8 hyperlink: \\x1b]8;;<url>\\x1b\\\\ (open) or \\x1b]8;;\\x1b\\\\ (close).\n\t\t// Preserve the original terminator because some terminals only make BEL-terminated\n\t\t// links clickable. OAuth login URLs use BEL, so reopening wrapped lines with ST\n\t\t// made only the first physical line clickable in those terminals.\n\t\tconst hyperlink = parseOsc8Hyperlink(ansiCode);\n\t\tif (hyperlink !== undefined) {\n\t\t\tthis.activeHyperlink = hyperlink;\n\t\t\treturn;\n\t\t}\n\n\t\tif (!ansiCode.endsWith(\"m\")) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Extract the parameters between \\x1b[ and m\n\t\tconst match = ansiCode.match(/\\x1b\\[([\\d;]*)m/);\n\t\tif (!match) return;\n\n\t\tconst params = match[1];\n\t\tif (params === \"\" || params === \"0\") {\n\t\t\t// Full reset\n\t\t\tthis.reset();\n\t\t\treturn;\n\t\t}\n\n\t\t// Parse parameters (can be semicolon-separated)\n\t\tconst parts = params.split(\";\");\n\t\tlet i = 0;\n\t\twhile (i < parts.length) {\n\t\t\tconst code = Number.parseInt(parts[i], 10);\n\n\t\t\t// Handle 256-color and RGB codes which consume multiple parameters\n\t\t\tif (code === 38 || code === 48) {\n\t\t\t\t// 38;5;N (256 color fg) or 38;2;R;G;B (RGB fg)\n\t\t\t\t// 48;5;N (256 color bg) or 48;2;R;G;B (RGB bg)\n\t\t\t\tif (parts[i + 1] === \"5\" && parts[i + 2] !== undefined) {\n\t\t\t\t\t// 256 color: 38;5;N or 48;5;N\n\t\t\t\t\tconst colorCode = `${parts[i]};${parts[i + 1]};${parts[i + 2]}`;\n\t\t\t\t\tif (code === 38) {\n\t\t\t\t\t\tthis.fgColor = colorCode;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.bgColor = colorCode;\n\t\t\t\t\t}\n\t\t\t\t\ti += 3;\n\t\t\t\t\tcontinue;\n\t\t\t\t} else if (parts[i + 1] === \"2\" && parts[i + 4] !== undefined) {\n\t\t\t\t\t// RGB color: 38;2;R;G;B or 48;2;R;G;B\n\t\t\t\t\tconst colorCode = `${parts[i]};${parts[i + 1]};${parts[i + 2]};${parts[i + 3]};${parts[i + 4]}`;\n\t\t\t\t\tif (code === 38) {\n\t\t\t\t\t\tthis.fgColor = colorCode;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.bgColor = colorCode;\n\t\t\t\t\t}\n\t\t\t\t\ti += 5;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Standard SGR codes\n\t\t\tswitch (code) {\n\t\t\t\tcase 0:\n\t\t\t\t\tthis.reset();\n\t\t\t\t\tbreak;\n\t\t\t\tcase 1:\n\t\t\t\t\tthis.bold = true;\n\t\t\t\t\tbreak;\n\t\t\t\tcase 2:\n\t\t\t\t\tthis.dim = true;\n\t\t\t\t\tbreak;\n\t\t\t\tcase 3:\n\t\t\t\t\tthis.italic = true;\n\t\t\t\t\tbreak;\n\t\t\t\tcase 4:\n\t\t\t\t\tthis.underline = true;\n\t\t\t\t\tbreak;\n\t\t\t\tcase 5:\n\t\t\t\t\tthis.blink = true;\n\t\t\t\t\tbreak;\n\t\t\t\tcase 7:\n\t\t\t\t\tthis.inverse = true;\n\t\t\t\t\tbreak;\n\t\t\t\tcase 8:\n\t\t\t\t\tthis.hidden = true;\n\t\t\t\t\tbreak;\n\t\t\t\tcase 9:\n\t\t\t\t\tthis.strikethrough = true;\n\t\t\t\t\tbreak;\n\t\t\t\tcase 21:\n\t\t\t\t\tthis.bold = false;\n\t\t\t\t\tbreak; // Some terminals\n\t\t\t\tcase 22:\n\t\t\t\t\tthis.bold = false;\n\t\t\t\t\tthis.dim = false;\n\t\t\t\t\tbreak;\n\t\t\t\tcase 23:\n\t\t\t\t\tthis.italic = false;\n\t\t\t\t\tbreak;\n\t\t\t\tcase 24:\n\t\t\t\t\tthis.underline = false;\n\t\t\t\t\tbreak;\n\t\t\t\tcase 25:\n\t\t\t\t\tthis.blink = false;\n\t\t\t\t\tbreak;\n\t\t\t\tcase 27:\n\t\t\t\t\tthis.inverse = false;\n\t\t\t\t\tbreak;\n\t\t\t\tcase 28:\n\t\t\t\t\tthis.hidden = false;\n\t\t\t\t\tbreak;\n\t\t\t\tcase 29:\n\t\t\t\t\tthis.strikethrough = false;\n\t\t\t\t\tbreak;\n\t\t\t\tcase 39:\n\t\t\t\t\tthis.fgColor = null;\n\t\t\t\t\tbreak; // Default fg\n\t\t\t\tcase 49:\n\t\t\t\t\tthis.bgColor = null;\n\t\t\t\t\tbreak; // Default bg\n\t\t\t\tdefault:\n\t\t\t\t\t// Standard foreground colors 30-37, 90-97\n\t\t\t\t\tif ((code >= 30 && code <= 37) || (code >= 90 && code <= 97)) {\n\t\t\t\t\t\tthis.fgColor = String(code);\n\t\t\t\t\t}\n\t\t\t\t\t// Standard background colors 40-47, 100-107\n\t\t\t\t\telse if ((code >= 40 && code <= 47) || (code >= 100 && code <= 107)) {\n\t\t\t\t\t\tthis.bgColor = String(code);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\ti++;\n\t\t}\n\t}\n\n\tprivate reset(): void {\n\t\tthis.bold = false;\n\t\tthis.dim = false;\n\t\tthis.italic = false;\n\t\tthis.underline = false;\n\t\tthis.blink = false;\n\t\tthis.inverse = false;\n\t\tthis.hidden = false;\n\t\tthis.strikethrough = false;\n\t\tthis.fgColor = null;\n\t\tthis.bgColor = null;\n\t\t// SGR reset does not affect OSC 8 hyperlink state\n\t}\n\n\t/** Clear all state for reuse. */\n\tclear(): void {\n\t\tthis.reset();\n\t\tthis.activeHyperlink = null;\n\t}\n\n\tgetActiveCodes(): string {\n\t\tconst codes: string[] = [];\n\t\tif (this.bold) codes.push(\"1\");\n\t\tif (this.dim) codes.push(\"2\");\n\t\tif (this.italic) codes.push(\"3\");\n\t\tif (this.underline) codes.push(\"4\");\n\t\tif (this.blink) codes.push(\"5\");\n\t\tif (this.inverse) codes.push(\"7\");\n\t\tif (this.hidden) codes.push(\"8\");\n\t\tif (this.strikethrough) codes.push(\"9\");\n\t\tif (this.fgColor) codes.push(this.fgColor);\n\t\tif (this.bgColor) codes.push(this.bgColor);\n\n\t\tlet result = codes.length > 0 ? `\\x1b[${codes.join(\";\")}m` : \"\";\n\t\tif (this.activeHyperlink) {\n\t\t\tresult += formatOsc8Hyperlink(this.activeHyperlink);\n\t\t}\n\t\treturn result;\n\t}\n\n\tgetActiveBackgroundCode(): string {\n\t\treturn this.bgColor ? `\\x1b[${this.bgColor}m` : \"\";\n\t}\n\n\thasActiveCodes(): boolean {\n\t\treturn (\n\t\t\tthis.bold ||\n\t\t\tthis.dim ||\n\t\t\tthis.italic ||\n\t\t\tthis.underline ||\n\t\t\tthis.blink ||\n\t\t\tthis.inverse ||\n\t\t\tthis.hidden ||\n\t\t\tthis.strikethrough ||\n\t\t\tthis.fgColor !== null ||\n\t\t\tthis.bgColor !== null ||\n\t\t\tthis.activeHyperlink !== null\n\t\t);\n\t}\n\n\t/**\n\t * Get reset codes for attributes that need to be turned off at line end.\n\t * Underline must be closed to prevent bleeding into padding.\n\t * Active OSC 8 hyperlinks must be closed and re-opened on the next line.\n\t * Returns empty string if no attributes need closing.\n\t */\n\tgetLineEndReset(): string {\n\t\tlet result = \"\";\n\t\tif (this.underline) {\n\t\t\tresult += \"\\x1b[24m\"; // Underline off only\n\t\t}\n\t\tif (this.activeHyperlink) {\n\t\t\tresult += formatOsc8Close(this.activeHyperlink.terminator); // Re-opened at line start via getActiveCodes()\n\t\t}\n\t\treturn result;\n\t}\n}\n\nfunction updateTrackerFromText(text: string, tracker: AnsiCodeTracker): void {\n\tlet i = 0;\n\twhile (i < text.length) {\n\t\tconst ansiResult = extractAnsiCode(text, i);\n\t\tif (ansiResult) {\n\t\t\ttracker.process(ansiResult.code);\n\t\t\ti += ansiResult.length;\n\t\t} else {\n\t\t\ti++;\n\t\t}\n\t}\n}\n\n/** Return only the background color active at the end of an ANSI-styled string. */\nexport function getActiveBackgroundAnsi(text: string): string {\n\tconst tracker = new AnsiCodeTracker();\n\tupdateTrackerFromText(text, tracker);\n\treturn tracker.getActiveBackgroundCode();\n}\n\n/**\n * Split text into words while keeping ANSI codes attached.\n */\nfunction splitIntoTokensWithAnsi(text: string): string[] {\n\tconst tokens: string[] = [];\n\tlet current = \"\";\n\tlet pendingAnsi = \"\"; // ANSI codes waiting to be attached to next visible content\n\tlet currentKind: \"space\" | \"word\" | null = null;\n\tlet i = 0;\n\n\tconst flushCurrent = (): void => {\n\t\tif (!current) {\n\t\t\treturn;\n\t\t}\n\t\ttokens.push(current);\n\t\tcurrent = \"\";\n\t\tcurrentKind = null;\n\t};\n\n\twhile (i < text.length) {\n\t\tconst ansiResult = extractAnsiCode(text, i);\n\t\tif (ansiResult) {\n\t\t\t// Hold ANSI codes separately - they'll be attached to the next visible char\n\t\t\tpendingAnsi += ansiResult.code;\n\t\t\ti += ansiResult.length;\n\t\t\tcontinue;\n\t\t}\n\n\t\tlet end = i;\n\t\twhile (end < text.length && !extractAnsiCode(text, end)) {\n\t\t\tend++;\n\t\t}\n\n\t\tfor (const { segment } of graphemeSegmenter.segment(text.slice(i, end))) {\n\t\t\tconst segmentIsSpace = segment === \" \";\n\t\t\tif (!segmentIsSpace && cjkBreakRegex.test(segment)) {\n\t\t\t\tflushCurrent();\n\t\t\t\tconst token = pendingAnsi + segment;\n\t\t\t\tpendingAnsi = \"\";\n\t\t\t\ttokens.push(token);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst segmentKind = segmentIsSpace ? \"space\" : \"word\";\n\t\t\tif (current && currentKind !== segmentKind) {\n\t\t\t\tflushCurrent();\n\t\t\t}\n\n\t\t\t// Attach any pending ANSI codes to this visible character\n\t\t\tif (pendingAnsi) {\n\t\t\t\tcurrent += pendingAnsi;\n\t\t\t\tpendingAnsi = \"\";\n\t\t\t}\n\n\t\t\tcurrentKind = segmentKind;\n\t\t\tcurrent += segment;\n\t\t}\n\n\t\ti = end;\n\t}\n\n\t// Handle any remaining pending ANSI codes (attach to last token)\n\tif (pendingAnsi) {\n\t\tif (current) {\n\t\t\tcurrent += pendingAnsi;\n\t\t} else if (tokens.length > 0) {\n\t\t\ttokens[tokens.length - 1] += pendingAnsi;\n\t\t} else {\n\t\t\tcurrent = pendingAnsi;\n\t\t}\n\t}\n\n\tif (current) {\n\t\ttokens.push(current);\n\t}\n\n\treturn tokens;\n}\n\n/**\n * Wrap text with ANSI codes preserved.\n *\n * ONLY does word wrapping - NO padding, NO background colors.\n * Returns lines where each line is <= width visible chars.\n * Active ANSI codes are preserved across line breaks.\n *\n * @param text - Text to wrap (may contain ANSI codes and newlines)\n * @param width - Maximum visible width per line\n * @returns Array of wrapped lines (NOT padded to width)\n */\nexport function wrapTextWithAnsi(text: string, width: number): string[] {\n\tif (!text) {\n\t\treturn [\"\"];\n\t}\n\n\t// Handle newlines by processing each line separately\n\t// Track ANSI state across lines so styles carry over after literal newlines\n\tconst inputLines = text.split(/\\r\\n|\\r|\\n/);\n\tconst result: string[] = [];\n\tconst tracker = new AnsiCodeTracker();\n\n\tfor (const inputLine of inputLines) {\n\t\t// Prepend active ANSI codes from previous lines (except for first line)\n\t\tconst prefix = result.length > 0 ? tracker.getActiveCodes() : \"\";\n\t\tconst wrappedLines = wrapSingleLine(prefix + inputLine, width);\n\t\tfor (const wrappedLine of wrappedLines) {\n\t\t\tresult.push(wrappedLine);\n\t\t}\n\t\t// Update tracker with codes from this line for next iteration\n\t\tupdateTrackerFromText(inputLine, tracker);\n\t}\n\n\treturn result.length > 0 ? result : [\"\"];\n}\n\nfunction wrapSingleLine(line: string, width: number): string[] {\n\tif (!line) {\n\t\treturn [\"\"];\n\t}\n\n\tconst visibleLength = visibleWidth(line);\n\tif (visibleLength <= width) {\n\t\treturn [line];\n\t}\n\n\tconst wrapped: string[] = [];\n\tconst tracker = new AnsiCodeTracker();\n\tconst tokens = splitIntoTokensWithAnsi(line);\n\n\tlet currentLine = \"\";\n\tlet currentVisibleLength = 0;\n\n\tfor (const token of tokens) {\n\t\tconst tokenVisibleLength = visibleWidth(token);\n\t\tconst isWhitespace = token.trim() === \"\";\n\n\t\t// Token itself is too long - break it character by character\n\t\tif (tokenVisibleLength > width && !isWhitespace) {\n\t\t\tif (currentLine) {\n\t\t\t\t// Add specific reset for underline only (preserves background)\n\t\t\t\tconst lineEndReset = tracker.getLineEndReset();\n\t\t\t\tif (lineEndReset) {\n\t\t\t\t\tcurrentLine += lineEndReset;\n\t\t\t\t}\n\t\t\t\twrapped.push(currentLine);\n\t\t\t\tcurrentLine = \"\";\n\t\t\t\tcurrentVisibleLength = 0;\n\t\t\t}\n\n\t\t\t// Break long token - breakLongWord handles its own resets\n\t\t\tconst broken = breakLongWord(token, width, tracker);\n\t\t\tfor (let i = 0; i < broken.length - 1; i++) {\n\t\t\t\twrapped.push(broken[i]!);\n\t\t\t}\n\t\t\tcurrentLine = broken[broken.length - 1];\n\t\t\tcurrentVisibleLength = visibleWidth(currentLine);\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Check if adding this token would exceed width\n\t\tconst totalNeeded = currentVisibleLength + tokenVisibleLength;\n\n\t\tif (totalNeeded > width && currentVisibleLength > 0) {\n\t\t\t// Trim trailing whitespace, then add underline reset (not full reset, to preserve background)\n\t\t\tlet lineToWrap = currentLine.trimEnd();\n\t\t\tconst lineEndReset = tracker.getLineEndReset();\n\t\t\tif (lineEndReset) {\n\t\t\t\tlineToWrap += lineEndReset;\n\t\t\t}\n\t\t\twrapped.push(lineToWrap);\n\t\t\tif (isWhitespace) {\n\t\t\t\t// Don't start new line with whitespace\n\t\t\t\tcurrentLine = tracker.getActiveCodes();\n\t\t\t\tcurrentVisibleLength = 0;\n\t\t\t} else {\n\t\t\t\tcurrentLine = tracker.getActiveCodes() + token;\n\t\t\t\tcurrentVisibleLength = tokenVisibleLength;\n\t\t\t}\n\t\t} else {\n\t\t\t// Add to current line\n\t\t\tcurrentLine += token;\n\t\t\tcurrentVisibleLength += tokenVisibleLength;\n\t\t}\n\n\t\tupdateTrackerFromText(token, tracker);\n\t}\n\n\tif (currentLine) {\n\t\t// No reset at end of final line - let caller handle it\n\t\twrapped.push(currentLine);\n\t}\n\n\t// Trailing whitespace can cause lines to exceed the requested width\n\treturn wrapped.length > 0 ? wrapped.map((line) => line.trimEnd()) : [\"\"];\n}\n\nexport const PUNCTUATION_REGEX = /[(){}[\\]<>.,;:'\"!?+\\-=*/\\\\|&%^$#@~`]/;\n\n/**\n * Check if a character is whitespace.\n */\nexport function isWhitespaceChar(char: string): boolean {\n\treturn /\\s/.test(char);\n}\n\n/**\n * Check if a character is punctuation.\n */\nexport function isPunctuationChar(char: string): boolean {\n\treturn PUNCTUATION_REGEX.test(char);\n}\n\nfunction breakLongWord(word: string, width: number, tracker: AnsiCodeTracker): string[] {\n\tconst lines: string[] = [];\n\tlet currentLine = tracker.getActiveCodes();\n\tlet currentWidth = 0;\n\n\t// First, separate ANSI codes from visible content\n\t// We need to handle ANSI codes specially since they're not graphemes\n\tlet i = 0;\n\tconst segments: Array<{ type: \"ansi\" | \"grapheme\"; value: string }> = [];\n\n\twhile (i < word.length) {\n\t\tconst ansiResult = extractAnsiCode(word, i);\n\t\tif (ansiResult) {\n\t\t\tsegments.push({ type: \"ansi\", value: ansiResult.code });\n\t\t\ti += ansiResult.length;\n\t\t} else {\n\t\t\t// Find the next ANSI code or end of string\n\t\t\tlet end = i;\n\t\t\twhile (end < word.length) {\n\t\t\t\tconst nextAnsi = extractAnsiCode(word, end);\n\t\t\t\tif (nextAnsi) break;\n\t\t\t\tend++;\n\t\t\t}\n\t\t\t// Segment this non-ANSI portion into graphemes\n\t\t\tconst textPortion = word.slice(i, end);\n\t\t\tfor (const seg of graphemeSegmenter.segment(textPortion)) {\n\t\t\t\tsegments.push({ type: \"grapheme\", value: seg.segment });\n\t\t\t}\n\t\t\ti = end;\n\t\t}\n\t}\n\n\t// Now process segments\n\tfor (const seg of segments) {\n\t\tif (seg.type === \"ansi\") {\n\t\t\tcurrentLine += seg.value;\n\t\t\ttracker.process(seg.value);\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst grapheme = seg.value;\n\t\t// Skip empty graphemes to avoid issues with string-width calculation\n\t\tif (!grapheme) continue;\n\n\t\tconst graphemeWidth = visibleWidth(grapheme);\n\n\t\tif (currentWidth + graphemeWidth > width) {\n\t\t\t// Add specific reset for underline only (preserves background)\n\t\t\tconst lineEndReset = tracker.getLineEndReset();\n\t\t\tif (lineEndReset) {\n\t\t\t\tcurrentLine += lineEndReset;\n\t\t\t}\n\t\t\tlines.push(currentLine);\n\t\t\tcurrentLine = tracker.getActiveCodes();\n\t\t\tcurrentWidth = 0;\n\t\t}\n\n\t\tcurrentLine += grapheme;\n\t\tcurrentWidth += graphemeWidth;\n\t}\n\n\tif (currentLine) {\n\t\t// No reset at end of final segment - caller handles continuation\n\t\tlines.push(currentLine);\n\t}\n\n\treturn lines.length > 0 ? lines : [\"\"];\n}\n\n/**\n * Apply background color to a line, padding to full width.\n *\n * @param line - Line of text (may contain ANSI codes)\n * @param width - Total width to pad to\n * @param bgFn - Background color function\n * @returns Line with background applied and padded to width\n */\nexport function applyBackgroundToLine(line: string, width: number, bgFn: (text: string) => string): string {\n\t// Calculate padding needed\n\tconst visibleLen = visibleWidth(line);\n\tconst paddingNeeded = Math.max(0, width - visibleLen);\n\tconst padding = \" \".repeat(paddingNeeded);\n\n\t// Apply background to content + padding\n\tconst withPadding = line + padding;\n\treturn bgFn(withPadding);\n}\n\n/**\n * Truncate text to fit within a maximum visible width, adding ellipsis if needed.\n * Optionally pad with spaces to reach exactly maxWidth.\n * Properly handles ANSI escape codes (they don't count toward width).\n *\n * @param text - Text to truncate (may contain ANSI codes)\n * @param maxWidth - Maximum visible width\n * @param ellipsis - Ellipsis string to append when truncating (default: \"...\")\n * @param pad - If true, pad result with spaces to exactly maxWidth (default: false)\n * @returns Truncated text, optionally padded to exactly maxWidth\n */\nexport function truncateToWidth(\n\ttext: string,\n\tmaxWidth: number,\n\tellipsis: string = \"...\",\n\tpad: boolean = false,\n): string {\n\tif (maxWidth <= 0) {\n\t\treturn \"\";\n\t}\n\n\tif (text.length === 0) {\n\t\treturn pad ? \" \".repeat(maxWidth) : \"\";\n\t}\n\n\tconst ellipsisWidth = visibleWidth(ellipsis);\n\tif (ellipsisWidth >= maxWidth) {\n\t\tconst textWidth = visibleWidth(text);\n\t\tif (textWidth <= maxWidth) {\n\t\t\treturn pad ? text + \" \".repeat(maxWidth - textWidth) : text;\n\t\t}\n\n\t\tconst clippedEllipsis = truncateFragmentToWidth(ellipsis, maxWidth);\n\t\tif (clippedEllipsis.width === 0) {\n\t\t\treturn pad ? \" \".repeat(maxWidth) : \"\";\n\t\t}\n\t\treturn finalizeTruncatedResult(\"\", 0, clippedEllipsis.text, clippedEllipsis.width, maxWidth, pad);\n\t}\n\n\tif (isPrintableAscii(text)) {\n\t\tif (text.length <= maxWidth) {\n\t\t\treturn pad ? text + \" \".repeat(maxWidth - text.length) : text;\n\t\t}\n\t\tconst targetWidth = maxWidth - ellipsisWidth;\n\t\treturn finalizeTruncatedResult(text.slice(0, targetWidth), targetWidth, ellipsis, ellipsisWidth, maxWidth, pad);\n\t}\n\n\tconst targetWidth = maxWidth - ellipsisWidth;\n\tlet result = \"\";\n\tlet pendingAnsi = \"\";\n\tlet visibleSoFar = 0;\n\tlet keptWidth = 0;\n\tlet keepContiguousPrefix = true;\n\tlet overflowed = false;\n\tlet exhaustedInput = false;\n\tconst hasAnsi = text.includes(\"\\x1b\");\n\tconst hasTabs = text.includes(\"\\t\");\n\n\tif (!hasAnsi && !hasTabs) {\n\t\tfor (const { segment } of graphemeSegmenter.segment(text)) {\n\t\t\tconst width = graphemeWidth(segment);\n\t\t\tif (keepContiguousPrefix && keptWidth + width <= targetWidth) {\n\t\t\t\tresult += segment;\n\t\t\t\tkeptWidth += width;\n\t\t\t} else {\n\t\t\t\tkeepContiguousPrefix = false;\n\t\t\t}\n\t\t\tvisibleSoFar += width;\n\t\t\tif (visibleSoFar > maxWidth) {\n\t\t\t\toverflowed = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\texhaustedInput = !overflowed;\n\t} else {\n\t\tlet i = 0;\n\t\twhile (i < text.length) {\n\t\t\tconst ansi = extractAnsiCode(text, i);\n\t\t\tif (ansi) {\n\t\t\t\tpendingAnsi += ansi.code;\n\t\t\t\ti += ansi.length;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (text[i] === \"\\t\") {\n\t\t\t\tif (keepContiguousPrefix && keptWidth + 3 <= targetWidth) {\n\t\t\t\t\tif (pendingAnsi) {\n\t\t\t\t\t\tresult += pendingAnsi;\n\t\t\t\t\t\tpendingAnsi = \"\";\n\t\t\t\t\t}\n\t\t\t\t\tresult += \"\\t\";\n\t\t\t\t\tkeptWidth += 3;\n\t\t\t\t} else {\n\t\t\t\t\tkeepContiguousPrefix = false;\n\t\t\t\t\tpendingAnsi = \"\";\n\t\t\t\t}\n\t\t\t\tvisibleSoFar += 3;\n\t\t\t\tif (visibleSoFar > maxWidth) {\n\t\t\t\t\toverflowed = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\ti++;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tlet end = i;\n\t\t\twhile (end < text.length && text[end] !== \"\\t\") {\n\t\t\t\tconst nextAnsi = extractAnsiCode(text, end);\n\t\t\t\tif (nextAnsi) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tend++;\n\t\t\t}\n\n\t\t\tfor (const { segment } of graphemeSegmenter.segment(text.slice(i, end))) {\n\t\t\t\tconst width = graphemeWidth(segment);\n\t\t\t\tif (keepContiguousPrefix && keptWidth + width <= targetWidth) {\n\t\t\t\t\tif (pendingAnsi) {\n\t\t\t\t\t\tresult += pendingAnsi;\n\t\t\t\t\t\tpendingAnsi = \"\";\n\t\t\t\t\t}\n\t\t\t\t\tresult += segment;\n\t\t\t\t\tkeptWidth += width;\n\t\t\t\t} else {\n\t\t\t\t\tkeepContiguousPrefix = false;\n\t\t\t\t\tpendingAnsi = \"\";\n\t\t\t\t}\n\n\t\t\t\tvisibleSoFar += width;\n\t\t\t\tif (visibleSoFar > maxWidth) {\n\t\t\t\t\toverflowed = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (overflowed) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\ti = end;\n\t\t}\n\t\texhaustedInput = i >= text.length;\n\t}\n\n\tif (!overflowed && exhaustedInput) {\n\t\treturn pad ? text + \" \".repeat(Math.max(0, maxWidth - visibleSoFar)) : text;\n\t}\n\n\treturn finalizeTruncatedResult(result, keptWidth, ellipsis, ellipsisWidth, maxWidth, pad);\n}\n\n/**\n * Extract a range of visible columns from a line. Handles ANSI codes and wide chars.\n * @param strict - If true, exclude wide chars at boundary that would extend past the range\n */\nexport function sliceByColumn(line: string, startCol: number, length: number, strict = false): string {\n\treturn sliceWithWidth(line, startCol, length, strict).text;\n}\n\n/** Like sliceByColumn but also returns the actual visible width of the result. */\nexport function sliceWithWidth(\n\tline: string,\n\tstartCol: number,\n\tlength: number,\n\tstrict = false,\n): { text: string; width: number } {\n\tif (length <= 0) return { text: \"\", width: 0 };\n\tconst endCol = startCol + length;\n\tlet result = \"\",\n\t\tresultWidth = 0,\n\t\tcurrentCol = 0,\n\t\ti = 0,\n\t\tpendingAnsi = \"\";\n\n\twhile (i < line.length) {\n\t\tconst ansi = extractAnsiCode(line, i);\n\t\tif (ansi) {\n\t\t\tif (currentCol >= startCol && currentCol < endCol) result += ansi.code;\n\t\t\telse if (currentCol < startCol) pendingAnsi += ansi.code;\n\t\t\ti += ansi.length;\n\t\t\tcontinue;\n\t\t}\n\n\t\tlet textEnd = i;\n\t\twhile (textEnd < line.length && !extractAnsiCode(line, textEnd)) textEnd++;\n\n\t\tfor (const { segment } of graphemeSegmenter.segment(line.slice(i, textEnd))) {\n\t\t\tconst w = graphemeWidth(segment);\n\t\t\tconst inRange = currentCol >= startCol && currentCol < endCol;\n\t\t\tconst fits = !strict || currentCol + w <= endCol;\n\t\t\tif (inRange && fits) {\n\t\t\t\tif (pendingAnsi) {\n\t\t\t\t\tresult += pendingAnsi;\n\t\t\t\t\tpendingAnsi = \"\";\n\t\t\t\t}\n\t\t\t\tresult += segment;\n\t\t\t\tresultWidth += w;\n\t\t\t}\n\t\t\tcurrentCol += w;\n\t\t\tif (currentCol >= endCol) break;\n\t\t}\n\t\ti = textEnd;\n\t\tif (currentCol >= endCol) break;\n\t}\n\treturn { text: result, width: resultWidth };\n}\n\n// Pooled tracker instance for extractSegments (avoids allocation per call)\nconst pooledStyleTracker = new AnsiCodeTracker();\n\n/**\n * Extract \"before\" and \"after\" segments from a line in a single pass.\n * Used for overlay compositing where we need content before and after the overlay region.\n * Preserves styling from before the overlay that should affect content after it.\n */\nexport function extractSegments(\n\tline: string,\n\tbeforeEnd: number,\n\tafterStart: number,\n\tafterLen: number,\n\tstrictAfter = false,\n): { before: string; beforeWidth: number; after: string; afterWidth: number } {\n\tlet before = \"\",\n\t\tbeforeWidth = 0,\n\t\tafter = \"\",\n\t\tafterWidth = 0;\n\tlet currentCol = 0,\n\t\ti = 0;\n\tlet pendingAnsiBefore = \"\";\n\tlet afterStarted = false;\n\tconst afterEnd = afterStart + afterLen;\n\n\t// Track styling state so \"after\" inherits styling from before the overlay\n\tpooledStyleTracker.clear();\n\n\twhile (i < line.length) {\n\t\tconst ansi = extractAnsiCode(line, i);\n\t\tif (ansi) {\n\t\t\t// Track all SGR codes to know styling state at afterStart\n\t\t\tpooledStyleTracker.process(ansi.code);\n\t\t\t// Include ANSI codes in their respective segments\n\t\t\tif (currentCol < beforeEnd) {\n\t\t\t\tpendingAnsiBefore += ansi.code;\n\t\t\t} else if (currentCol >= afterStart && currentCol < afterEnd && afterStarted) {\n\t\t\t\t// Only include after we've started \"after\" (styling already prepended)\n\t\t\t\tafter += ansi.code;\n\t\t\t}\n\t\t\ti += ansi.length;\n\t\t\tcontinue;\n\t\t}\n\n\t\tlet textEnd = i;\n\t\twhile (textEnd < line.length && !extractAnsiCode(line, textEnd)) textEnd++;\n\n\t\tfor (const { segment } of graphemeSegmenter.segment(line.slice(i, textEnd))) {\n\t\t\tconst w = graphemeWidth(segment);\n\n\t\t\tif (currentCol < beforeEnd && currentCol + w <= beforeEnd) {\n\t\t\t\tif (pendingAnsiBefore) {\n\t\t\t\t\tbefore += pendingAnsiBefore;\n\t\t\t\t\tpendingAnsiBefore = \"\";\n\t\t\t\t}\n\t\t\t\tbefore += segment;\n\t\t\t\tbeforeWidth += w;\n\t\t\t} else if (currentCol >= afterStart && currentCol < afterEnd) {\n\t\t\t\tconst fits = !strictAfter || currentCol + w <= afterEnd;\n\t\t\t\tif (fits) {\n\t\t\t\t\t// On first \"after\" grapheme, prepend inherited styling from before overlay\n\t\t\t\t\tif (!afterStarted) {\n\t\t\t\t\t\tafter += pooledStyleTracker.getActiveCodes();\n\t\t\t\t\t\tafterStarted = true;\n\t\t\t\t\t}\n\t\t\t\t\tafter += segment;\n\t\t\t\t\tafterWidth += w;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tcurrentCol += w;\n\t\t\t// Early exit: done with \"before\" only, or done with both segments\n\t\t\tif (afterLen <= 0 ? currentCol >= beforeEnd : currentCol >= afterEnd) break;\n\t\t}\n\t\ti = textEnd;\n\t\tif (afterLen <= 0 ? currentCol >= beforeEnd : currentCol >= afterEnd) break;\n\t}\n\n\treturn { before, beforeWidth, after, afterWidth };\n}\n"]}
|