bd44b5aa08
Test / build-libghostty-vt (x86_64-windows-gnu) (push) Has been cancelled
Test / build-libghostty-vt-macos (aarch64-ios) (push) Has been cancelled
Test / build-libghostty-vt-macos (aarch64-macos) (push) Has been cancelled
Test / build-libghostty-vt-macos (x86_64-macos) (push) Has been cancelled
Test / build-nix (namespace-profile-ghostty-md-arm64) (push) Has been cancelled
Test / build-dist (push) Has been cancelled
Test / GTK x11=true wayland=true (push) Has been cancelled
Test / Build -Dsimd=false (push) Has been cancelled
Test / Build -Dsimd=true (push) Has been cancelled
Test / Build -Dsentry=false (push) Has been cancelled
Test / Build -Dsentry=true (push) Has been cancelled
Test / zig-fmt (push) Has been cancelled
Test / GitHub Actions Pins (push) Has been cancelled
Test / prettier (push) Has been cancelled
Test / swiftlint (push) Has been cancelled
Test / alejandra (push) Has been cancelled
Test / typos (push) Has been cancelled
Nix / Required Checks: Nix (push) Has been cancelled
Nix / check-zig-cache-hash (push) Has been cancelled
Test / skip (push) Has been cancelled
Test / Required Checks: Test (push) Has been cancelled
Test / build-bench (push) Has been cancelled
Test / list-examples (push) Has been cancelled
Test / Example ${{ matrix.dir }} (Windows) (push) Has been cancelled
Test / build-cmake (push) Has been cancelled
Test / test-lib-vt-pkgconfig (push) Has been cancelled
Test / build-flatpak (push) Has been cancelled
Test / build-snap (push) Has been cancelled
Test / build-libghostty-vt (aarch64-linux) (push) Has been cancelled
Test / build-libghostty-vt (aarch64-macos) (push) Has been cancelled
Test / build-libghostty-vt (wasm32-freestanding) (push) Has been cancelled
Test / build-libghostty-vt (x86_64-linux) (push) Has been cancelled
Test / build-libghostty-vt (x86_64-linux-musl) (push) Has been cancelled
Test / build-libghostty-vt (x86_64-macos) (push) Has been cancelled
Test / build-libghostty-vt-android (aarch64-linux-android) (push) Has been cancelled
Test / build-libghostty-vt-android (arm-linux-androideabi) (push) Has been cancelled
Test / build-libghostty-vt-android (x86_64-linux-android) (push) Has been cancelled
Test / build-libghostty-vt-windows (push) Has been cancelled
Test / build-libghostty-windows-gnu (push) Has been cancelled
Test / build-linux (namespace-profile-ghostty-md) (push) Has been cancelled
Test / build-linux (namespace-profile-ghostty-md-arm64) (push) Has been cancelled
Test / build-linux-libghostty (push) Has been cancelled
Test / build-nix (namespace-profile-ghostty-md) (push) Has been cancelled
Test / build-dist-lib-vt (push) Has been cancelled
Test / trigger-snap (push) Has been cancelled
Test / trigger-flatpak (push) Has been cancelled
Test / build-macos (push) Has been cancelled
Test / build-macos-freetype (push) Has been cancelled
Test / test (push) Has been cancelled
Test / test-lib-vt (push) Has been cancelled
Test / GTK x11=false wayland=false (push) Has been cancelled
Test / GTK x11=true wayland=false (push) Has been cancelled
Test / GTK x11=false wayland=true (push) Has been cancelled
Test / test-macos (push) Has been cancelled
Test / test-windows (push) Has been cancelled
Test / Build -Di18n=false (push) Has been cancelled
Test / Build -Di18n=true (push) Has been cancelled
Test / Build test/fuzz-libghostty (push) Has been cancelled
Test / shellcheck (push) Has been cancelled
Test / translations (push) Has been cancelled
Test / blueprint-compiler (push) Has been cancelled
Test / Test pkg/wuffs (push) Has been cancelled
Test / Test build on Debian 13 (push) Has been cancelled
Test / valgrind (push) Has been cancelled
Test / Example ${{ matrix.dir }} (push) Has been cancelled
95 lines
3.1 KiB
C
95 lines
3.1 KiB
C
#include <assert.h>
|
|
#include <stdbool.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <ghostty/vt.h>
|
|
|
|
//! [grid-ref-tracked]
|
|
static uint32_t codepoint_at_tracked_ref(GhosttyTrackedGridRef tracked) {
|
|
GhosttyGridRef snapshot = GHOSTTY_INIT_SIZED(GhosttyGridRef);
|
|
GhosttyResult result = ghostty_tracked_grid_ref_snapshot(tracked, &snapshot);
|
|
assert(result == GHOSTTY_SUCCESS);
|
|
|
|
GhosttyCell cell;
|
|
result = ghostty_grid_ref_cell(&snapshot, &cell);
|
|
assert(result == GHOSTTY_SUCCESS);
|
|
|
|
bool has_text = false;
|
|
ghostty_cell_get(cell, GHOSTTY_CELL_DATA_HAS_TEXT, &has_text);
|
|
assert(has_text);
|
|
|
|
uint32_t codepoint = 0;
|
|
ghostty_cell_get(cell, GHOSTTY_CELL_DATA_CODEPOINT, &codepoint);
|
|
return codepoint;
|
|
}
|
|
|
|
int main() {
|
|
GhosttyTerminal terminal;
|
|
GhosttyTerminalOptions opts = {
|
|
.cols = 8,
|
|
.rows = 3,
|
|
.max_scrollback = 100,
|
|
};
|
|
GhosttyResult result = ghostty_terminal_new(NULL, &terminal, opts);
|
|
assert(result == GHOSTTY_SUCCESS);
|
|
|
|
const char *text = "alpha\r\n"
|
|
"bravo\r\n"
|
|
"charlie";
|
|
ghostty_terminal_vt_write(
|
|
terminal, (const uint8_t *)text, strlen(text));
|
|
|
|
GhosttyTrackedGridRef tracked = NULL;
|
|
GhosttyPoint alpha = {
|
|
.tag = GHOSTTY_POINT_TAG_ACTIVE,
|
|
.value = { .coordinate = { .x = 0, .y = 0 } },
|
|
};
|
|
result = ghostty_terminal_grid_ref_track(terminal, alpha, &tracked);
|
|
assert(result == GHOSTTY_SUCCESS);
|
|
|
|
// Writing another line scrolls the original "alpha" row into scrollback.
|
|
// The tracked ref still follows the same cell.
|
|
const char *more = "\r\ndelta";
|
|
ghostty_terminal_vt_write(
|
|
terminal, (const uint8_t *)more, strlen(more));
|
|
|
|
assert(ghostty_tracked_grid_ref_has_value(tracked));
|
|
printf("tracked codepoint after scroll: %c\n",
|
|
(char)codepoint_at_tracked_ref(tracked));
|
|
|
|
GhosttyPointCoordinate screen = {0};
|
|
result = ghostty_tracked_grid_ref_point(
|
|
tracked, GHOSTTY_POINT_TAG_SCREEN, &screen);
|
|
assert(result == GHOSTTY_SUCCESS);
|
|
printf("tracked screen point: %u,%u\n", screen.x, screen.y);
|
|
|
|
// Resetting the terminal discards the old grid contents. The tracked
|
|
// handle remains valid, but no longer has a meaningful location.
|
|
ghostty_terminal_reset(terminal);
|
|
assert(!ghostty_tracked_grid_ref_has_value(tracked));
|
|
|
|
GhosttyGridRef discarded = GHOSTTY_INIT_SIZED(GhosttyGridRef);
|
|
result = ghostty_tracked_grid_ref_snapshot(tracked, &discarded);
|
|
assert(result == GHOSTTY_NO_VALUE);
|
|
|
|
// The same handle can be moved to a new point after it loses its value.
|
|
const char *replacement = "echo";
|
|
ghostty_terminal_vt_write(
|
|
terminal, (const uint8_t *)replacement, strlen(replacement));
|
|
|
|
GhosttyPoint echo = {
|
|
.tag = GHOSTTY_POINT_TAG_ACTIVE,
|
|
.value = { .coordinate = { .x = 0, .y = 0 } },
|
|
};
|
|
result = ghostty_tracked_grid_ref_set(tracked, terminal, echo);
|
|
assert(result == GHOSTTY_SUCCESS);
|
|
assert(ghostty_tracked_grid_ref_has_value(tracked));
|
|
printf("tracked codepoint after reset/set: %c\n",
|
|
(char)codepoint_at_tracked_ref(tracked));
|
|
|
|
ghostty_tracked_grid_ref_free(tracked);
|
|
ghostty_terminal_free(terminal);
|
|
return 0;
|
|
}
|
|
//! [grid-ref-tracked]
|