mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-17 05:00:16 +00:00
perf(tui): scan only bottom terminal height lines in extractCursorPosition
This commit is contained in:
parent
9d47747ff6
commit
fb693fbc90
1 changed files with 4 additions and 6 deletions
|
|
@ -769,17 +769,15 @@ export class TUI extends Container {
|
||||||
/**
|
/**
|
||||||
* Find and extract cursor position from rendered lines.
|
* Find and extract cursor position from rendered lines.
|
||||||
* Searches for CURSOR_MARKER, calculates its position, and strips it from the output.
|
* 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 lines - Rendered lines to search
|
||||||
* @param height - Terminal height (to calculate viewport)
|
* @param height - Terminal height (visible viewport size)
|
||||||
* @returns Cursor position { row, col } or null if no marker found
|
* @returns Cursor position { row, col } or null if no marker found
|
||||||
*/
|
*/
|
||||||
private extractCursorPosition(lines: string[], height: number): { row: number; col: number } | null {
|
private extractCursorPosition(lines: string[], height: number): { row: number; col: number } | null {
|
||||||
|
// Only scan the bottom `height` lines (visible viewport)
|
||||||
const viewportTop = Math.max(0, lines.length - height);
|
const viewportTop = Math.max(0, lines.length - height);
|
||||||
for (let row = lines.length - 1; row >= 0; row--) {
|
for (let row = lines.length - 1; row >= viewportTop; row--) {
|
||||||
// Early out if above visible viewport
|
|
||||||
if (row < viewportTop) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
const line = lines[row];
|
const line = lines[row];
|
||||||
const markerIndex = line.indexOf(CURSOR_MARKER);
|
const markerIndex = line.indexOf(CURSOR_MARKER);
|
||||||
if (markerIndex !== -1) {
|
if (markerIndex !== -1) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue