mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-09-04 05:10:27 +00:00
terminal: C API for unknown sequences
This commit is contained in:
@@ -97,6 +97,7 @@ extern "C" {
|
||||
* | `GHOSTTY_TERMINAL_OPT_CLIPBOARD_WRITE` | `GhosttyTerminalClipboardWriteFn` | Clipboard write via OSC 52 / OSC 1337 |
|
||||
* | `GHOSTTY_TERMINAL_OPT_DESKTOP_NOTIFICATION`| `GhosttyTerminalDesktopNotificationFn` | Desktop notification via OSC 9 / OSC 777 |
|
||||
* | `GHOSTTY_TERMINAL_OPT_PROGRESS_REPORT` | `GhosttyTerminalProgressReportFn` | Progress report via OSC 9;4 |
|
||||
* | `GHOSTTY_TERMINAL_OPT_UNKNOWN_SEQUENCE` | `GhosttyTerminalUnknownSequenceFn` | Unsupported sequence identifier |
|
||||
*
|
||||
* ### Defining a write_pty callback
|
||||
* @snippet c-vt-effects/src/main.c effects-write-pty
|
||||
@@ -110,6 +111,9 @@ extern "C" {
|
||||
* ### Defining a clipboard_write callback
|
||||
* @snippet c-vt-effects/src/main.c effects-clipboard-write
|
||||
*
|
||||
* ### Defining an unknown_sequence callback
|
||||
* @snippet c-vt-effects/src/main.c effects-unknown-sequence
|
||||
*
|
||||
* ### Registering effects and processing VT data
|
||||
* @snippet c-vt-effects/src/main.c effects-register
|
||||
*
|
||||
@@ -331,6 +335,88 @@ typedef struct {
|
||||
typedef void (*GhosttyTerminalBellFn)(GhosttyTerminal terminal,
|
||||
void* userdata);
|
||||
|
||||
/**
|
||||
* Unsupported terminal sequence tags.
|
||||
*
|
||||
* Only APC sequences are currently reported. Additional sequence types may
|
||||
* be added without changing the callback shape.
|
||||
*
|
||||
* @ingroup terminal
|
||||
*/
|
||||
typedef enum GHOSTTY_ENUM_TYPED {
|
||||
/** Application Program Command (APC). */
|
||||
GHOSTTY_TERMINAL_UNKNOWN_SEQUENCE_APC = 0,
|
||||
GHOSTTY_TERMINAL_UNKNOWN_SEQUENCE_MAX_VALUE = GHOSTTY_ENUM_MAX_VALUE,
|
||||
} GhosttyTerminalUnknownSequenceTag;
|
||||
|
||||
/**
|
||||
* An unsupported string terminal sequence.
|
||||
*
|
||||
* The content is borrowed and valid only for the callback duration. It
|
||||
* contains the bytes between the sequence introducer and terminator, may
|
||||
* contain arbitrary binary data, and is not null-terminated.
|
||||
*
|
||||
* @ingroup terminal
|
||||
*/
|
||||
typedef struct {
|
||||
/** Whether content was shortened by the byte limit or allocation failure. */
|
||||
bool truncated;
|
||||
|
||||
/** Retained sequence content. */
|
||||
GhosttyString content;
|
||||
} GhosttyTerminalUnknownStringSequence;
|
||||
|
||||
/**
|
||||
* Unsupported terminal sequence value.
|
||||
*
|
||||
* @ingroup terminal
|
||||
*/
|
||||
typedef union {
|
||||
/** Application Program Command (APC). */
|
||||
GhosttyTerminalUnknownStringSequence apc;
|
||||
|
||||
/**
|
||||
* Padding for ABI compatibility. Do not use.
|
||||
*
|
||||
* 128 bytes leaves room for future structured sequence payloads, such as
|
||||
* CSI with borrowed parameter, separator, and intermediate arrays, without
|
||||
* changing the tagged union's ABI.
|
||||
*/
|
||||
uint64_t _padding[16];
|
||||
} GhosttyTerminalUnknownSequenceValue;
|
||||
|
||||
/**
|
||||
* An unsupported terminal sequence.
|
||||
*
|
||||
* @ingroup terminal
|
||||
*/
|
||||
typedef struct {
|
||||
GhosttyTerminalUnknownSequenceTag tag;
|
||||
GhosttyTerminalUnknownSequenceValue value;
|
||||
} GhosttyTerminalUnknownSequence;
|
||||
|
||||
/**
|
||||
* Callback function type for unsupported terminal sequences.
|
||||
*
|
||||
* Called synchronously for normally terminated sequences whose identifier is
|
||||
* not supported by the active terminal handler. Aborted sequences, malformed
|
||||
* recognized commands, and explicitly disabled known protocols are ignored.
|
||||
*
|
||||
* Capture must also be enabled with a nonzero
|
||||
* GHOSTTY_TERMINAL_OPT_UNKNOWN_MAX_BYTES value. Installing this callback alone
|
||||
* does not retain sequence content or allocate memory.
|
||||
*
|
||||
* @param terminal The terminal handle
|
||||
* @param userdata The userdata pointer set via GHOSTTY_TERMINAL_OPT_USERDATA
|
||||
* @param sequence Borrowed unsupported sequence
|
||||
*
|
||||
* @ingroup terminal
|
||||
*/
|
||||
typedef void (*GhosttyTerminalUnknownSequenceFn)(
|
||||
GhosttyTerminal terminal,
|
||||
void* userdata,
|
||||
const GhosttyTerminalUnknownSequence* sequence);
|
||||
|
||||
/**
|
||||
* Clipboard destination for a clipboard write.
|
||||
*
|
||||
@@ -1103,6 +1189,27 @@ typedef enum GHOSTTY_ENUM_TYPED {
|
||||
* Input type: GhosttyTerminalModeConfig*
|
||||
*/
|
||||
GHOSTTY_TERMINAL_OPT_MODE = 34,
|
||||
|
||||
/**
|
||||
* Callback invoked for unsupported terminal sequence identifiers. Set to
|
||||
* NULL to ignore unsupported sequences. Capture must also be enabled with
|
||||
* GHOSTTY_TERMINAL_OPT_UNKNOWN_MAX_BYTES.
|
||||
*
|
||||
* Input type: GhosttyTerminalUnknownSequenceFn
|
||||
*/
|
||||
GHOSTTY_TERMINAL_OPT_UNKNOWN_SEQUENCE = 35,
|
||||
|
||||
/**
|
||||
* Set the maximum content bytes retained for each unsupported terminal
|
||||
* sequence. A NULL value pointer or zero disables capture and prevents
|
||||
* unknown-sequence callbacks.
|
||||
*
|
||||
* When this limit is hit, the unknown sequence callback will still
|
||||
* be invoked but `truncated` will be set to true.
|
||||
*
|
||||
* Input type: size_t*
|
||||
*/
|
||||
GHOSTTY_TERMINAL_OPT_UNKNOWN_MAX_BYTES = 36,
|
||||
GHOSTTY_TERMINAL_OPT_MAX_VALUE = GHOSTTY_ENUM_MAX_VALUE,
|
||||
} GhosttyTerminalOption;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user