libghostty
Loading...
Searching...
No Matches
Focus Encoding

Detailed Description

Utilities for encoding focus gained/lost events into terminal escape sequences (CSI I / CSI O) for focus reporting mode (mode 1004).

Basic Usage

Use ghostty_focus_encode() to encode a focus event into a caller-provided buffer. If the buffer is too small, the function returns GHOSTTY_OUT_OF_SPACE and sets the required size in the output parameter.

Example

int main() {
char buf[8];
size_t written = 0;
GHOSTTY_FOCUS_GAINED, buf, sizeof(buf), &written);
if (result == GHOSTTY_SUCCESS) {
printf("Encoded %zu bytes: ", written);
fwrite(buf, 1, written, stdout);
printf("\n");
}
return 0;
}

Enumerations

enum  GhosttyFocusEvent { GHOSTTY_FOCUS_GAINED = 0 , GHOSTTY_FOCUS_LOST = 1 }

Functions

GhosttyResult ghostty_focus_encode (GhosttyFocusEvent event, char *buf, size_t buf_len, size_t *out_written)

Enumeration Type Documentation

◆ GhosttyFocusEvent

Focus event types for focus reporting mode (mode 1004).

Enumerator
GHOSTTY_FOCUS_GAINED 

Terminal window gained focus

GHOSTTY_FOCUS_LOST 

Terminal window lost focus

Definition at line 38 of file focus.h.

Function Documentation

◆ ghostty_focus_encode()

GhosttyResult ghostty_focus_encode ( GhosttyFocusEvent event,
char * buf,
size_t buf_len,
size_t * out_written )

Encode a focus event into a terminal escape sequence.

Encodes a focus gained (CSI I) or focus lost (CSI O) report into the provided buffer.

If the buffer is too small, the function returns GHOSTTY_OUT_OF_SPACE and writes the required buffer size to out_written. The caller can then retry with a sufficiently sized buffer.

Parameters
eventThe focus event to encode
bufOutput buffer to write the encoded sequence into (may be NULL)
buf_lenSize of the output buffer in bytes
[out]out_writtenOn success, the number of bytes written. On GHOSTTY_OUT_OF_SPACE, the required buffer size.
Returns
GHOSTTY_SUCCESS on success, GHOSTTY_OUT_OF_SPACE if the buffer is too small