![]() |
libghostty-vt 0.0.0
|
Point at a cell, read it, and keep track of it as the terminal scrolls. More...
Point at a cell, read it, and keep track of it as the terminal scrolls.
A grid reference points at one cell in the terminal.
An untracked reference is a snapshot that is only valid until the next change to the terminal. A tracked reference follows its cell. Use one to read particular cells. They aren't fast enough to draw a frame, so use Render State for that.
Full program: c-vt-grid-traverse/src/main.c
The Grid guide covers coordinates, both kinds of reference, and when each one dies.
Typedefs | |
| typedef struct GhosttyTrackedGridRefImpl * | GhosttyTrackedGridRef |
Data Structures | |
| struct | GhosttyGridRef |
| typedef struct GhosttyTrackedGridRefImpl* GhosttyTrackedGridRef |
Opaque handle to a tracked grid reference.
A tracked grid reference is owned by you and must be freed with ghostty_tracked_grid_ref_free(). If the terminal that created it is freed first, the handle remains valid only for tracked-grid-ref APIs: it reports no value and can still be freed.
| GHOSTTY_API GhosttyResult ghostty_grid_ref_cell | ( | const GhosttyGridRef * | ref, |
| GhosttyCell * | out_cell ) |
Get the cell from a grid reference.
| ref | Pointer to the grid reference | |
| [out] | out_cell | On success, set to the cell at the ref's position (may be NULL) |
| GHOSTTY_API GhosttyResult ghostty_grid_ref_graphemes | ( | const GhosttyGridRef * | ref, |
| uint32_t * | buf, | ||
| size_t | buf_len, | ||
| size_t * | out_written ) |
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. Both buf_len and out_written count codepoints, not bytes.
If buf is too small, this returns GHOSTTY_OUT_OF_SPACE, sets out_written to the number of codepoints needed, and leaves buf unchanged. To get the count without copying anything, pass NULL for buf and 0 for buf_len. A cell with no text returns GHOSTTY_SUCCESS with out_written set to 0.
Most cells hold a single codepoint, so a small fixed buffer usually works. Fall back to a heap buffer for longer clusters:
| ref | Pointer to the grid reference | |
| buf | Buffer to write the codepoints into. May be NULL if buf_len is 0. | |
| buf_len | Number of uint32_t elements buf can hold | |
| [out] | out_written | The number of codepoints written, or the number needed if the result is GHOSTTY_OUT_OF_SPACE |
| GHOSTTY_API GhosttyResult ghostty_grid_ref_hyperlink_uri | ( | const GhosttyGridRef * | ref, |
| uint8_t * | buf, | ||
| size_t | buf_len, | ||
| size_t * | out_written ) |
Get the hyperlink URI for the cell at the grid reference's position.
Writes the URI bytes into the provided buffer.
The URI is not NUL-terminated.
If buf is too small, this returns GHOSTTY_OUT_OF_SPACE, sets out_written to the size needed, and leaves buf unchanged. To get the size without copying anything, pass NULL for buf and 0 for buf_len. A cell with no hyperlink returns GHOSTTY_SUCCESS with out_written set to 0.
URIs can be long, so asking for the size first is often simplest:
| ref | Pointer to the grid reference | |
| buf | Buffer to write the URI into. May be NULL if buf_len is 0. | |
| buf_len | Size of buf in bytes | |
| [out] | out_written | The number of bytes written, or the size needed if the result is GHOSTTY_OUT_OF_SPACE |
| GHOSTTY_API GhosttyResult ghostty_grid_ref_row | ( | const GhosttyGridRef * | ref, |
| GhosttyRow * | out_row ) |
Get the row from a grid reference.
| ref | Pointer to the grid reference | |
| [out] | out_row | On success, set to the row at the ref's position (may be NULL) |
| GHOSTTY_API GhosttyResult ghostty_grid_ref_style | ( | const GhosttyGridRef * | ref, |
| GhosttyStyle * | out_style ) |
Get the style of the cell at the grid reference's position.
| ref | Pointer to the grid reference | |
| [out] | out_style | On success, set to the cell's style (may be NULL) |
| GHOSTTY_API void ghostty_tracked_grid_ref_free | ( | GhosttyTrackedGridRef | ref | ) |
Tracked grid references are owned grid references that move with the terminal. See the Grid guide for how tracked and untracked references behave. Free a tracked grid reference.
Passing NULL is allowed and has no effect. A tracked reference may be freed after the terminal that created it is freed.
| ref | Tracked grid reference to free. |
| GHOSTTY_API bool ghostty_tracked_grid_ref_has_value | ( | GhosttyTrackedGridRef | ref | ) |
Return whether a tracked grid reference currently has a meaningful value.
If the terminal that created the tracked reference has been freed, this returns false.
| ref | Tracked grid reference. |
| GHOSTTY_API GhosttyResult ghostty_tracked_grid_ref_point | ( | GhosttyTrackedGridRef | ref, |
| GhosttyPointTag | tag, | ||
| GhosttyPointCoordinate * | out_point ) |
Convert a tracked grid reference to a point in the requested coordinate space.
This is the tracked equivalent of ghostty_terminal_point_from_grid_ref(). Unlike snapshotting, this does not expose an intermediate untracked GhosttyGridRef.
A tracked reference is resolved against the terminal screen/page-list that currently owns the reference. If the terminal has switched between primary and alternate screens since the reference was created or last set, this may be different from the terminal's currently active screen.
If the tracked reference no longer has a meaningful value, this returns GHOSTTY_NO_VALUE. GHOSTTY_NO_VALUE is also returned when the reference cannot be represented in the requested coordinate space, including after the terminal that created the tracked reference has been freed.
| ref | Tracked grid reference. | |
| tag | Coordinate space to convert into. | |
| [out] | out_point | On success, receives the coordinate. May be NULL. |
| GHOSTTY_API GhosttyResult ghostty_tracked_grid_ref_set | ( | GhosttyTrackedGridRef | ref, |
| GhosttyTerminal | terminal, | ||
| GhosttyPoint | point ) |
Move an existing tracked grid reference to a new terminal point.
On success, the tracked reference begins tracking the new point and any prior "no value" state is cleared. On GHOSTTY_OUT_OF_MEMORY, the original tracked reference is left unchanged.
The terminal must be the same terminal that created the tracked reference. The point is resolved against the terminal screen/page-list that is active at the time this function is called. If the terminal has switched between primary and alternate screens, this may move the tracked reference from one screen/page-list to the other.
| ref | Tracked grid reference. |
| terminal | Terminal instance that owns the reference. |
| point | New point to track. |
| GHOSTTY_API GhosttyResult ghostty_tracked_grid_ref_snapshot | ( | GhosttyTrackedGridRef | ref, |
| GhosttyGridRef * | out_ref ) |
Snapshot a tracked grid reference into a regular GhosttyGridRef.
The returned GhosttyGridRef is an untracked snapshot and has the same lifetime rules as ghostty_terminal_grid_ref(): it is only valid until the next terminal update. Snapshot immediately before calling ghostty_grid_ref_cell(), ghostty_grid_ref_row(), ghostty_grid_ref_graphemes(), ghostty_grid_ref_hyperlink_uri(), or ghostty_grid_ref_style().
If the tracked reference no longer has a meaningful value, this returns GHOSTTY_NO_VALUE. This includes references whose owning terminal has been freed.
| ref | Tracked grid reference. | |
| [out] | out_ref | On success, receives an untracked snapshot. May be NULL. |