( x: number, y: number, surface: SessionSurface | undefined, )
| 36 | } |
| 37 | |
| 38 | export 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 | |
| 64 | function rectArea(rect: RawSnapshotNode['rect']): number { |
| 65 | return (rect?.width ?? 0) * (rect?.height ?? 0); |
no test coverage detected