MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / extractCursorPosition

Method extractCursorPosition

packages/pi-tui/src/tui.ts:1244–1262  ·  view source on GitHub ↗

* Find and extract cursor position from rendered lines. * Searches for CURSOR_MARKER, calculates its position, and strips it from the output. * Only scans the bottom terminal height lines (visible viewport). * @param lines - Rendered lines to search * @param height - Terminal height (visible

(lines: string[], height: number)

Source from the content-addressed store, hash-verified

1242 * @returns Cursor position { row, col } or null if no marker found
1243 */
1244 private extractCursorPosition(lines: string[], height: number): { row: number; col: number } | null {
1245 // Only scan the bottom `height` lines (visible viewport)
1246 const viewportTop = Math.max(0, lines.length - height);
1247 for (let row = lines.length - 1; row >= viewportTop; row--) {
1248 const line = lines[row]!;
1249 const markerIndex = line.indexOf(CURSOR_MARKER);
1250 if (markerIndex !== -1) {
1251 // Calculate visual column (width of text before marker)
1252 const beforeMarker = line.slice(0, markerIndex);
1253 const col = visibleWidth(beforeMarker);
1254
1255 // Strip marker from the line
1256 lines[row] = line.slice(0, markerIndex) + line.slice(markerIndex + CURSOR_MARKER.length);
1257
1258 return { row, col };
1259 }
1260 }
1261 return null;
1262 }
1263
1264 private doRender(): void {
1265 if (this.stopped) return;

Callers 1

doRenderMethod · 0.95

Calls 1

visibleWidthFunction · 0.90

Tested by

no test coverage detected