libghostty: terminal data, grid point and cell inspection APIs (#11676) master
This adds a complete set of APIs for inspecting individual cells and rows in the terminal grid from C. Callers can now resolve any point in the grid to a reference, then extract codepoints, grapheme clusters, styles, wide-character state, semantic prompt tags, and row-level metadata like wrap and dirty flags. This also adds a robust `ghostty_terminal_get` API for extracting information like rows, cols, active screen, cursor information, etc. from the terminal. ## Example ```c // Write bold red text via SGR sequences const char *text = "\033[1;31mHello\033[0m"; ghostty_terminal_vt_write(terminal, (const uint8_t *)text, strlen(text)); // Resolve cell (0,0) to a grid reference GhosttyGridRef ref = GHOSTTY_INIT_SIZED(GhosttyGridRef); GhosttyPoint pt = { .tag = GHOSTTY_POINT_TAG_ACTIVE, .value = { .coordinate = { .x = 0, .y = 0 } }, }; ghostty_terminal_grid_ref(terminal, pt, &ref); // Read the codepoint ('H') GhosttyCell cell; ghostty_grid_ref_cell(&ref, &cell); uint32_t codepoint = 0; ghostty_cell_get(cell, GHOSTTY_CELL_DATA_CODEPOINT, &codepoint); // Read the resolved style (bold=true, fg=red) GhosttyStyle style = GHOSTTY_INIT_SIZED(GhosttyStyle); ghostty_grid_ref_style(&ref, &style); assert(style.bold); ``` ## API Changes ### New Types | Type | Description | |------|-------------| | `GhosttyCell` | Opaque 64-bit cell value | | `GhosttyRow` | Opaque 64-bit row value | | `GhosttyCellData` | Enum for `ghostty_cell_get` data kinds (codepoint, content tag, wide, has_text, etc.) | | `GhosttyCellContentTag` | Cell content kind (codepoint, grapheme, bg color palette/RGB) | | `GhosttyCellWide` | Cell width (narrow, wide, spacer tail/head) | | `GhosttyCellSemanticContent` | Semantic content type (output, input, prompt) | | `GhosttyRowData` | Enum for `ghostty_row_get` data kinds (wrap, grapheme, styled, dirty, etc.) | | `GhosttyRowSemanticPrompt` | Row-level semantic prompt state | | `GhosttyGridRef` | Sized struct — resolved reference to a cell position in the page structure | | `GhosttyPoint` | Tagged union specifying a grid position in a given coordinate system | | `GhosttyPointTag` | Coordinate system tag: `ACTIVE`, `VIEWPORT`, `SCREEN`, `HISTORY` | | `GhosttyPointCoordinate` | x/y coordinate pair | | `GhosttyStyleId` | Style identifier type (uint16) | ### New Functions | Function | Description | |----------|-------------| | `ghostty_cell_get` | Extract typed data from a cell (codepoint, wide, style ID, etc.) | | `ghostty_row_get` | Extract typed data from a row (wrap, dirty, semantic prompt, etc.) | | `ghostty_terminal_grid_ref` | Resolve a `GhosttyPoint` to a `GhosttyGridRef` | | `ghostty_grid_ref_cell` | Extract the `GhosttyCell` from a grid ref | | `ghostty_grid_ref_row` | Extract the `GhosttyRow` from a grid ref | | `ghostty_grid_ref_graphemes` | Get the full grapheme cluster (codepoints) for the cell | | `ghostty_grid_ref_style` | Get the resolved `GhosttyStyle` for the cell |