libghostty: expose get/set active selection state

Add terminal set/get support for the active screen selection through the
existing option and data APIs. Setting a selection copies the C snapshot
into terminal-owned tracked state, while passing NULL clears the current
selection.

Getting the selection now returns an untracked GhosttySelection snapshot
or GHOSTTY_NO_VALUE when there is no selection. The C header documents
the different lifetimes for set and get so embedders know when input and
returned grid references remain valid.
This commit is contained in:
Mitchell Hashimoto
2026-05-23 14:54:34 -07:00
parent d5d8cef4d3
commit ae03d3cae4
3 changed files with 105 additions and 0 deletions

View File

@@ -19,6 +19,7 @@
#include <ghostty/vt/kitty_graphics.h>
#include <ghostty/vt/screen.h>
#include <ghostty/vt/point.h>
#include <ghostty/vt/selection.h>
#include <ghostty/vt/style.h>
#ifdef __cplusplus
@@ -592,6 +593,21 @@ typedef enum GHOSTTY_ENUM_TYPED {
* Input type: size_t*
*/
GHOSTTY_TERMINAL_OPT_APC_MAX_BYTES_KITTY = 20,
/**
* Set the active screen selection.
*
* The value must point to a GhosttySelection whose grid references are
* valid for this terminal's active screen at the time of the call. The
* terminal copies the selection immediately and converts it to
* terminal-owned tracked state, so the GhosttySelection struct and its
* untracked grid references do not need to outlive this call.
*
* Passing NULL clears the active screen selection.
*
* Input type: GhosttySelection*
*/
GHOSTTY_TERMINAL_OPT_SELECTION = 21,
GHOSTTY_TERMINAL_OPT_MAX_VALUE = GHOSTTY_ENUM_MAX_VALUE,
} GhosttyTerminalOption;
@@ -868,6 +884,23 @@ typedef enum GHOSTTY_ENUM_TYPED {
* Output type: GhosttyKittyGraphics *
*/
GHOSTTY_TERMINAL_DATA_KITTY_GRAPHICS = 30,
/**
* The active screen's current selection.
*
* On success, writes an untracked snapshot of the terminal-owned selection
* to the caller-provided GhosttySelection. The GhosttySelection struct is
* caller-owned and may be kept, but the grid references inside it are
* untracked borrowed references into the active screen. They are only valid
* until the next mutating terminal call, such as ghostty_terminal_set(),
* ghostty_terminal_vt_write(), ghostty_terminal_resize(), or
* ghostty_terminal_reset().
*
* Returns GHOSTTY_NO_VALUE when there is no active selection.
*
* Output type: GhosttySelection *
*/
GHOSTTY_TERMINAL_DATA_SELECTION = 31,
GHOSTTY_TERMINAL_DATA_MAX_VALUE = GHOSTTY_ENUM_MAX_VALUE,
} GhosttyTerminalData;