A grid reference is a resolved reference to a specific cell position in the terminal's internal page structure. Obtain a grid reference from ghostty_terminal_grid_ref(), then extract the cell or row via ghostty_grid_ref_cell() and ghostty_grid_ref_row().
A grid reference is only valid until the next update to the terminal instance. There is no guarantee that a grid reference will remain valid after ANY operation, even if a seemingly unrelated part of the grid is changed, so any information related to the grid reference should be read and cached immediately after obtaining the grid reference.
This API is not meant to be used as the core of render loop. It isn't built to sustain the framerates needed for rendering large screens. Use the render state API for that.
Example
int main() {
.cols = 10,
.rows = 3,
.max_scrollback = 0,
};
const char *text = "Hello!\r\n"
"World\r\n"
"\033[1mBold";
terminal, (const uint8_t *)text, strlen(text));
uint16_t cols, rows;
for (uint16_t row = 0; row < rows; row++) {
printf("Row %u: ", row);
for (uint16_t col = 0; col < cols; col++) {
.value = { .coordinate = { .x = col, .y = row } },
};
bool has_text = false;
if (has_text) {
uint32_t codepoint = 0;
printf("%c", (char)codepoint);
} else {
printf(".");
}
}
.value = { .coordinate = { .x = 0, .y = row } },
};
bool wrap = false;
printf(" (wrap=%s", wrap ? "true" : "false");
printf(", bold=%s)\n", style.bold ? "true" : "false");
}
return 0;
}
Get the grapheme cluster codepoints for the cell at the grid reference's position.
Writes the full grapheme cluster (the cell's primary codepoint followed by any combining codepoints) into the provided buffer. If the cell has no text, out_len is set to 0 and GHOSTTY_SUCCESS is returned.
If the buffer is too small (or NULL), the function returns GHOSTTY_OUT_OF_SPACE and writes the required number of codepoints to out_len. The caller can then retry with a sufficiently sized buffer.
- Parameters
-
| ref | Pointer to the grid reference |
| buf | Output buffer of uint32_t codepoints (may be NULL) |
| buf_len | Number of uint32_t elements in the buffer |
| [out] | out_len | On success, the number of codepoints written. On GHOSTTY_OUT_OF_SPACE, the required buffer size in codepoints. |
- Returns
- GHOSTTY_SUCCESS on success, GHOSTTY_INVALID_VALUE if the ref's node is NULL, GHOSTTY_OUT_OF_SPACE if the buffer is too small