libghostty: move selection functions to selection doxygen group

This commit is contained in:
Mitchell Hashimoto
2026-05-23 15:20:12 -07:00
parent 671c12fad9
commit 2512fad940
5 changed files with 229 additions and 214 deletions

View File

@@ -10,6 +10,7 @@
#include <stdbool.h>
#include <stddef.h>
#include <ghostty/vt/grid_ref.h>
#include <ghostty/vt/point.h>
#ifdef __cplusplus
extern "C" {
@@ -157,6 +158,118 @@ typedef enum GHOSTTY_ENUM_TYPED {
GHOSTTY_SELECTION_ADJUST_MAX_VALUE = GHOSTTY_ENUM_MAX_VALUE,
} GhosttySelectionAdjust;
/**
* Adjust a selection snapshot using terminal selection semantics.
*
* This mutates the caller-provided GhosttySelection in place. The logical end
* endpoint is always moved, regardless of whether the selection is forward or
* reversed visually. The input selection remains a snapshot: after adjustment,
* call ghostty_terminal_set() with GHOSTTY_TERMINAL_OPT_SELECTION to install it
* as the terminal-owned selection if desired.
*
* The selection's start and end grid refs must both be valid untracked
* snapshots for the given terminal's currently active screen. In practice,
* they must come from that terminal and screen, and no mutating terminal call
* may have occurred since the refs were produced or reconstructed from
* tracked refs. Passing refs from another terminal, another screen, or stale
* refs violates this precondition.
*
* @param terminal The terminal handle (NULL returns GHOSTTY_INVALID_VALUE)
* @param selection Selection snapshot to adjust in place
* @param adjustment The adjustment operation to apply
* @return GHOSTTY_SUCCESS on success, GHOSTTY_INVALID_VALUE if the terminal,
* selection, selection references, or adjustment are invalid
*
* @ingroup selection
*/
GHOSTTY_API GhosttyResult ghostty_terminal_selection_adjust(
GhosttyTerminal terminal,
GhosttySelection* selection,
GhosttySelectionAdjust adjustment);
/**
* Get the current endpoint ordering of a selection snapshot.
*
* The selection's start and end grid refs must both be valid untracked
* snapshots for the given terminal's currently active screen. In practice,
* they must come from that terminal and screen, and no mutating terminal call
* may have occurred since the refs were produced or reconstructed from
* tracked refs. Passing refs from another terminal, another screen, or stale
* refs violates this precondition.
*
* @param terminal The terminal handle (NULL returns GHOSTTY_INVALID_VALUE)
* @param selection Selection snapshot to inspect
* @param[out] out_order On success, receives the selection order
* @return GHOSTTY_SUCCESS on success, GHOSTTY_INVALID_VALUE if the terminal,
* selection, selection references, or output pointer are invalid
*
* @ingroup selection
*/
GHOSTTY_API GhosttyResult ghostty_terminal_selection_order(
GhosttyTerminal terminal,
const GhosttySelection* selection,
GhosttySelectionOrder* out_order);
/**
* Return a selection snapshot with endpoints ordered as requested.
*
* Use GHOSTTY_SELECTION_ORDER_FORWARD to get top-left to bottom-right bounds,
* and GHOSTTY_SELECTION_ORDER_REVERSE to get bottom-right to top-left bounds.
* Mirrored desired orders are accepted but normalized the same as forward.
* The output selection is a fresh untracked snapshot and is not installed as
* the terminal's current selection.
*
* The selection's start and end grid refs must both be valid untracked
* snapshots for the given terminal's currently active screen. In practice,
* they must come from that terminal and screen, and no mutating terminal call
* may have occurred since the refs were produced or reconstructed from
* tracked refs. Passing refs from another terminal, another screen, or stale
* refs violates this precondition.
*
* @param terminal The terminal handle (NULL returns GHOSTTY_INVALID_VALUE)
* @param selection Selection snapshot to order
* @param desired Desired endpoint order
* @param[out] out_selection On success, receives the ordered selection
* @return GHOSTTY_SUCCESS on success, GHOSTTY_INVALID_VALUE if the terminal,
* selection, selection references, desired order, or output pointer
* are invalid
*
* @ingroup selection
*/
GHOSTTY_API GhosttyResult ghostty_terminal_selection_ordered(
GhosttyTerminal terminal,
const GhosttySelection* selection,
GhosttySelectionOrder desired,
GhosttySelection* out_selection);
/**
* Test whether a terminal point is inside a selection snapshot.
*
* This uses the same selection semantics as the terminal, including
* rectangular/block selections and linear selections spanning multiple rows.
*
* The selection's start and end grid refs must both be valid untracked
* snapshots for the given terminal's currently active screen. In practice,
* they must come from that terminal and screen, and no mutating terminal call
* may have occurred since the refs were produced or reconstructed from
* tracked refs. Passing refs from another terminal, another screen, or stale
* refs violates this precondition.
*
* @param terminal The terminal handle (NULL returns GHOSTTY_INVALID_VALUE)
* @param selection Selection snapshot to inspect
* @param point Point to test for containment
* @param[out] out_contains On success, receives whether point is inside selection
* @return GHOSTTY_SUCCESS on success, GHOSTTY_INVALID_VALUE if the terminal,
* selection, selection references, point, or output pointer are invalid
*
* @ingroup selection
*/
GHOSTTY_API GhosttyResult ghostty_terminal_selection_contains(
GhosttyTerminal terminal,
const GhosttySelection* selection,
GhosttyPoint point,
bool* out_contains);
/** @} */
#ifdef __cplusplus

View File

@@ -1123,118 +1123,6 @@ GHOSTTY_API GhosttyResult ghostty_terminal_get_multi(GhosttyTerminal terminal,
void** values,
size_t* out_written);
/**
* Adjust a selection snapshot using terminal selection semantics.
*
* This mutates the caller-provided GhosttySelection in place. The logical end
* endpoint is always moved, regardless of whether the selection is forward or
* reversed visually. The input selection remains a snapshot: after adjustment,
* call ghostty_terminal_set() with GHOSTTY_TERMINAL_OPT_SELECTION to install it
* as the terminal-owned selection if desired.
*
* The selection's start and end grid refs must both be valid untracked
* snapshots for the given terminal's currently active screen. In practice,
* they must come from that terminal and screen, and no mutating terminal call
* may have occurred since the refs were produced or reconstructed from
* tracked refs. Passing refs from another terminal, another screen, or stale
* refs violates this precondition.
*
* @param terminal The terminal handle (NULL returns GHOSTTY_INVALID_VALUE)
* @param selection Selection snapshot to adjust in place
* @param adjustment The adjustment operation to apply
* @return GHOSTTY_SUCCESS on success, GHOSTTY_INVALID_VALUE if the terminal,
* selection, selection references, or adjustment are invalid
*
* @ingroup terminal
*/
GHOSTTY_API GhosttyResult ghostty_terminal_selection_adjust(
GhosttyTerminal terminal,
GhosttySelection* selection,
GhosttySelectionAdjust adjustment);
/**
* Get the current endpoint ordering of a selection snapshot.
*
* The selection's start and end grid refs must both be valid untracked
* snapshots for the given terminal's currently active screen. In practice,
* they must come from that terminal and screen, and no mutating terminal call
* may have occurred since the refs were produced or reconstructed from
* tracked refs. Passing refs from another terminal, another screen, or stale
* refs violates this precondition.
*
* @param terminal The terminal handle (NULL returns GHOSTTY_INVALID_VALUE)
* @param selection Selection snapshot to inspect
* @param[out] out_order On success, receives the selection order
* @return GHOSTTY_SUCCESS on success, GHOSTTY_INVALID_VALUE if the terminal,
* selection, selection references, or output pointer are invalid
*
* @ingroup terminal
*/
GHOSTTY_API GhosttyResult ghostty_terminal_selection_order(
GhosttyTerminal terminal,
const GhosttySelection* selection,
GhosttySelectionOrder* out_order);
/**
* Return a selection snapshot with endpoints ordered as requested.
*
* Use GHOSTTY_SELECTION_ORDER_FORWARD to get top-left to bottom-right bounds,
* and GHOSTTY_SELECTION_ORDER_REVERSE to get bottom-right to top-left bounds.
* Mirrored desired orders are accepted but normalized the same as forward.
* The output selection is a fresh untracked snapshot and is not installed as
* the terminal's current selection.
*
* The selection's start and end grid refs must both be valid untracked
* snapshots for the given terminal's currently active screen. In practice,
* they must come from that terminal and screen, and no mutating terminal call
* may have occurred since the refs were produced or reconstructed from
* tracked refs. Passing refs from another terminal, another screen, or stale
* refs violates this precondition.
*
* @param terminal The terminal handle (NULL returns GHOSTTY_INVALID_VALUE)
* @param selection Selection snapshot to order
* @param desired Desired endpoint order
* @param[out] out_selection On success, receives the ordered selection
* @return GHOSTTY_SUCCESS on success, GHOSTTY_INVALID_VALUE if the terminal,
* selection, selection references, desired order, or output pointer
* are invalid
*
* @ingroup terminal
*/
GHOSTTY_API GhosttyResult ghostty_terminal_selection_ordered(
GhosttyTerminal terminal,
const GhosttySelection* selection,
GhosttySelectionOrder desired,
GhosttySelection* out_selection);
/**
* Test whether a terminal point is inside a selection snapshot.
*
* This uses the same selection semantics as the terminal, including
* rectangular/block selections and linear selections spanning multiple rows.
*
* The selection's start and end grid refs must both be valid untracked
* snapshots for the given terminal's currently active screen. In practice,
* they must come from that terminal and screen, and no mutating terminal call
* may have occurred since the refs were produced or reconstructed from
* tracked refs. Passing refs from another terminal, another screen, or stale
* refs violates this precondition.
*
* @param terminal The terminal handle (NULL returns GHOSTTY_INVALID_VALUE)
* @param selection Selection snapshot to inspect
* @param point Point to test for containment
* @param[out] out_contains On success, receives whether point is inside selection
* @return GHOSTTY_SUCCESS on success, GHOSTTY_INVALID_VALUE if the terminal,
* selection, selection references, point, or output pointer are invalid
*
* @ingroup terminal
*/
GHOSTTY_API GhosttyResult ghostty_terminal_selection_contains(
GhosttyTerminal terminal,
const GhosttySelection* selection,
GhosttyPoint point,
bool* out_contains);
/**
* Resolve a point in the terminal grid to a grid reference.
*