MCPcopy Index your code
hub / github.com/callstack/agent-device / readLinuxTextAtPoint

Function readLinuxTextAtPoint

src/platforms/linux/snapshot.ts:38–62  ·  view source on GitHub ↗
(
  x: number,
  y: number,
  surface: SessionSurface | undefined,
)

Source from the content-addressed store, hash-verified

36}
37
38export async function readLinuxTextAtPoint(
39 x: number,
40 y: number,
41 surface: SessionSurface | undefined,
42): Promise<string> {
43 const { nodes } = await snapshotLinux(surface);
44 const matches = nodes
45 .filter((node) => {
46 const rect = node.rect;
47 if (!rect) return false;
48 return x >= rect.x && y >= rect.y && x <= rect.x + rect.width && y <= rect.y + rect.height;
49 })
50 .sort((left, right) => {
51 const leftDepth = left.depth ?? 0;
52 const rightDepth = right.depth ?? 0;
53 if (leftDepth !== rightDepth) return rightDepth - leftDepth;
54 return rectArea(left.rect) - rectArea(right.rect);
55 });
56
57 for (const node of matches) {
58 const text = extractReadText(node);
59 if (text.trim()) return text;
60 }
61 return '';
62}
63
64function rectArea(rect: RawSnapshotNode['rect']): number {
65 return (rect?.width ?? 0) * (rect?.height ?? 0);

Callers 1

handleReadCommandFunction · 0.85

Calls 3

snapshotLinuxFunction · 0.85
extractReadTextFunction · 0.85
rectAreaFunction · 0.70

Tested by

no test coverage detected