This example demonstrates how to traverse the entire terminal grid using grid refs to inspect cell codepoints, row wrap state, and cell styles.
#include <assert.h>
#include <stdio.h>
#include <string.h>
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;
}
GhosttyResult ghostty_grid_ref_row(const GhosttyGridRef *ref, GhosttyRow *out_row)
GhosttyResult ghostty_grid_ref_style(const GhosttyGridRef *ref, GhosttyStyle *out_style)
GhosttyResult ghostty_grid_ref_cell(const GhosttyGridRef *ref, GhosttyCell *out_cell)
@ GHOSTTY_POINT_TAG_ACTIVE
GhosttyResult ghostty_row_get(GhosttyRow row, GhosttyRowData data, void *out)
GhosttyResult ghostty_cell_get(GhosttyCell cell, GhosttyCellData data, void *out)
@ GHOSTTY_CELL_DATA_HAS_TEXT
@ GHOSTTY_CELL_DATA_CODEPOINT
struct GhosttyTerminal * GhosttyTerminal
GhosttyResult ghostty_terminal_new(const GhosttyAllocator *allocator, GhosttyTerminal *terminal, GhosttyTerminalOptions options)
GhosttyResult ghostty_terminal_grid_ref(GhosttyTerminal terminal, GhosttyPoint point, GhosttyGridRef *out_ref)
GhosttyResult ghostty_terminal_get(GhosttyTerminal terminal, GhosttyTerminalData data, void *out)
void ghostty_terminal_vt_write(GhosttyTerminal terminal, const uint8_t *data, size_t len)
void ghostty_terminal_free(GhosttyTerminal terminal)
@ GHOSTTY_TERMINAL_DATA_COLS
@ GHOSTTY_TERMINAL_DATA_ROWS
#define GHOSTTY_INIT_SIZED(type)