libghostty-vt 0.0.0
Loading...
Searching...
No Matches
GhosttySelection Struct Reference

#include <ghostty/vt/selection.h>

Data Fields

GhosttyGridRef start
GhosttyGridRef end
bool rectangle

Detailed Description

A range of terminal content between two cells.

A selection is described by the two cells at its ends, start and end. Both ends are included in the selection. By default the selection is linear: it runs from start to end the way text flows, wrapping from the end of one row to the start of the next. Set rectangle to true to select a rectangular block instead, with start and end at opposite corners.

The ends keep the direction the user selected in. If the user dragged up or to the left, start comes after end in the terminal. Don't assume start is the top-left end. Use ghostty_terminal_selection_ordered() when you need the ends in order.

Both ends are untracked grid references, so a selection is only valid until the next call that changes the terminal. To keep a selection across changes, track its ends with GhosttyTrackedGridRef and build a new GhosttySelection from fresh snapshots when you need one.

Start with a zero-initialized value. The example below selects the first ten cells of the second row and makes that the terminal's active selection.

GhosttyPoint start_pt = {
.value = { .coordinate = { .x = 0, .y = 1 } },
};
GhosttyPoint end_pt = {
.value = { .coordinate = { .x = 9, .y = 1 } },
};
GhosttySelection selection = {0};
ghostty_terminal_grid_ref(terminal, start_pt, &selection.start);
ghostty_terminal_grid_ref(terminal, end_pt, &selection.end);
@ GHOSTTY_POINT_TAG_ACTIVE
Definition point.h:66
GHOSTTY_API GhosttyResult ghostty_terminal_set(GhosttyTerminal terminal, GhosttyTerminalOption option, const void *value)
GHOSTTY_API GhosttyResult ghostty_terminal_grid_ref(GhosttyTerminal terminal, GhosttyPoint point, GhosttyGridRef *out_ref)
@ GHOSTTY_TERMINAL_OPT_SELECTION
Definition terminal.h:2251
GhosttyGridRef end
Definition selection.h:123
GhosttyGridRef start
Definition selection.h:120

The layout of this struct is frozen. It is 40 bytes on 64-bit targets and 20 bytes on 32-bit targets such as wasm32. If it ever needs to hold more, that will be a new type.

Examples
c-vt-render/src/main.c, c-vt-search/src/main.c, c-vt-selection-gesture/src/main.c, and c-vt-selection/src/main.c.

Definition at line 118 of file selection.h.

Field Documentation

◆ end

The cell where the selection ends. It is included in the selection.

Examples
c-vt-render/src/main.c, and c-vt-selection/src/main.c.

Definition at line 123 of file selection.h.

◆ rectangle

bool rectangle

Whether this is a rectangular selection. When true, start and end are opposite corners of a block of cells.

Definition at line 129 of file selection.h.

◆ start

The cell where the selection starts. It is included in the selection.

Examples
c-vt-render/src/main.c, and c-vt-selection/src/main.c.

Definition at line 120 of file selection.h.


The documentation for this struct was generated from the following file: