libghostty
Loading...
Searching...
No Matches
Color Scheme Report Encoding

Detailed Description

Utilities for encoding color scheme reports into terminal escape sequences for color scheme reporting mode (mode 2031).

Basic Usage

Use ghostty_color_scheme_report_encode() to encode a color scheme report 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[16];
size_t written = 0;
GHOSTTY_COLOR_SCHEME_DARK, buf, sizeof(buf), &written);
if (result == GHOSTTY_SUCCESS) {
printf("Encoded %zu bytes: ", written);
fwrite(buf, 1, written, stdout);
printf("\n");
}
return 0;
}

Functions

GHOSTTY_API GhosttyResult ghostty_color_scheme_report_encode (GhosttyColorScheme scheme, char *buf, size_t buf_len, size_t *out_written)

Function Documentation

◆ ghostty_color_scheme_report_encode()

GHOSTTY_API GhosttyResult ghostty_color_scheme_report_encode ( GhosttyColorScheme scheme,
char * buf,
size_t buf_len,
size_t * out_written )

Encode a color scheme report into an escape sequence.

Encodes a color scheme report into the provided buffer. Dark color schemes emit ESC [ ? 997 ; 1 n, and light color schemes emit ESC [ ? 997 ; 2 n. The encoded bytes are identical to the terminal's internal CSI ? 996 n query response.

Hosts should gate unsolicited sends on GHOSTTY_MODE_COLOR_SCHEME_REPORT (mode 2031) being set, which can be checked via the mode getters.

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
schemeThe color scheme 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