mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-04-18 21:40:29 +00:00
libghostty: add GhosttySelection type and selection support to formatter (#12115)
Add a new GhosttySelection C API type (selection.h / c/selection.zig) that pairs two GhosttyGridRef endpoints with a rectangle flag. This maps directly to the internal Selection type using untracked pins. The formatter terminal options gain an optional selection pointer. When non-null the formatter restricts output to the specified range instead of emitting the entire screen. When null the existing behavior of formatting the full screen is preserved.
This commit is contained in:
@@ -123,6 +123,7 @@ extern "C" {
|
||||
#include <ghostty/vt/mouse.h>
|
||||
#include <ghostty/vt/paste.h>
|
||||
#include <ghostty/vt/screen.h>
|
||||
#include <ghostty/vt/selection.h>
|
||||
#include <ghostty/vt/size_report.h>
|
||||
#include <ghostty/vt/wasm.h>
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <ghostty/vt/allocator.h>
|
||||
#include <ghostty/vt/selection.h>
|
||||
#include <ghostty/vt/types.h>
|
||||
#include <ghostty/vt/terminal.h>
|
||||
|
||||
@@ -133,6 +134,10 @@ typedef struct {
|
||||
|
||||
/** Extra terminal state to include in styled output. */
|
||||
GhosttyFormatterTerminalExtra extra;
|
||||
|
||||
/** Optional selection to restrict output to a range.
|
||||
* If NULL, the entire screen is formatted. */
|
||||
const GhosttySelection *selection;
|
||||
} GhosttyFormatterTerminalOptions;
|
||||
|
||||
/**
|
||||
|
||||
53
include/ghostty/vt/selection.h
Normal file
53
include/ghostty/vt/selection.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* @file selection.h
|
||||
*
|
||||
* Selection range type for specifying a region of terminal content.
|
||||
*/
|
||||
|
||||
#ifndef GHOSTTY_VT_SELECTION_H
|
||||
#define GHOSTTY_VT_SELECTION_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <ghostty/vt/grid_ref.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @defgroup selection Selection
|
||||
*
|
||||
* A selection range defined by two grid references that identifies a
|
||||
* contiguous or rectangular region of terminal content.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* A selection range defined by two grid references.
|
||||
*
|
||||
* This is a sized struct. Use GHOSTTY_INIT_SIZED() to initialize it.
|
||||
*
|
||||
* @ingroup selection
|
||||
*/
|
||||
typedef struct {
|
||||
/** Size of this struct in bytes. Must be set to sizeof(GhosttySelection). */
|
||||
size_t size;
|
||||
|
||||
/** Start of the selection range (inclusive). */
|
||||
GhosttyGridRef start;
|
||||
|
||||
/** End of the selection range (inclusive). */
|
||||
GhosttyGridRef end;
|
||||
|
||||
/** Whether the selection is rectangular (block) rather than linear. */
|
||||
bool rectangle;
|
||||
} GhosttySelection;
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* GHOSTTY_VT_SELECTION_H */
|
||||
Reference in New Issue
Block a user