This example demonstrates how to track a grid ref as the terminal scrolls, detect when it loses its value, and move it to a new point.
#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
bool has_text = false;
assert(has_text);
uint32_t codepoint = 0;
return codepoint;
}
int main() {
.cols = 8,
.rows = 3,
.max_scrollback = 100,
};
const char *text = "alpha\r\n"
"bravo\r\n"
"charlie";
terminal, (const uint8_t *)text, strlen(text));
.value = { .coordinate = { .x = 0, .y = 0 } },
};
const char *more = "\r\ndelta";
terminal, (const uint8_t *)more, strlen(more));
printf("tracked codepoint after scroll: %c\n",
(char)codepoint_at_tracked_ref(tracked));
printf(
"tracked screen point: %u,%u\n", screen.
x, screen.
y);
const char *replacement = "echo";
terminal, (const uint8_t *)replacement, strlen(replacement));
.value = { .coordinate = { .x = 0, .y = 0 } },
};
printf("tracked codepoint after reset/set: %c\n",
(char)codepoint_at_tracked_ref(tracked));
return 0;
}
GHOSTTY_API GhosttyResult ghostty_tracked_grid_ref_snapshot(GhosttyTrackedGridRef ref, GhosttyGridRef *out_ref)
GHOSTTY_API GhosttyResult ghostty_tracked_grid_ref_point(GhosttyTrackedGridRef ref, GhosttyPointTag tag, GhosttyPointCoordinate *out_point)
GHOSTTY_API bool ghostty_tracked_grid_ref_has_value(GhosttyTrackedGridRef ref)
GHOSTTY_API GhosttyResult ghostty_grid_ref_cell(const GhosttyGridRef *ref, GhosttyCell *out_cell)
GHOSTTY_API GhosttyResult ghostty_tracked_grid_ref_set(GhosttyTrackedGridRef ref, GhosttyTerminal terminal, GhosttyPoint point)
GHOSTTY_API void ghostty_tracked_grid_ref_free(GhosttyTrackedGridRef ref)
struct GhosttyTrackedGridRefImpl * GhosttyTrackedGridRef
@ GHOSTTY_POINT_TAG_ACTIVE
@ GHOSTTY_POINT_TAG_SCREEN
GHOSTTY_API GhosttyResult ghostty_cell_get(GhosttyCell cell, GhosttyCellData data, void *out)
@ GHOSTTY_CELL_DATA_HAS_TEXT
@ GHOSTTY_CELL_DATA_CODEPOINT
GHOSTTY_API void ghostty_terminal_reset(GhosttyTerminal terminal)
GHOSTTY_API GhosttyResult ghostty_terminal_grid_ref_track(GhosttyTerminal terminal, GhosttyPoint point, GhosttyTrackedGridRef *out_ref)
struct GhosttyTerminalImpl * GhosttyTerminal
GHOSTTY_API GhosttyResult ghostty_terminal_new(const GhosttyAllocator *allocator, GhosttyTerminal *terminal, GhosttyTerminalOptions options)
GHOSTTY_API void ghostty_terminal_free(GhosttyTerminal terminal)
GHOSTTY_API void ghostty_terminal_vt_write(GhosttyTerminal terminal, const uint8_t *data, size_t len)
#define GHOSTTY_INIT_SIZED(type)