libghostty
Loading...
Searching...
No Matches
Size Report Encoding

Detailed Description

Utilities for encoding terminal size reports into escape sequences, supporting in-band size reports (mode 2048) and XTWINOPS responses (CSI 14 t, CSI 16 t, CSI 18 t).

Basic Usage

Use ghostty_size_report_encode() to encode a size 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() {
.rows = 24,
.columns = 80,
.cell_width = 9,
.cell_height = 18,
};
char buf[64];
size_t written = 0;
GHOSTTY_SIZE_REPORT_MODE_2048, size, buf, sizeof(buf), &written);
if (result == GHOSTTY_SUCCESS) {
printf("Encoded %zu bytes: ", written);
fwrite(buf, 1, written, stdout);
printf("\n");
}
return 0;
}

Enumerations

enum  GhosttySizeReportStyle { GHOSTTY_SIZE_REPORT_MODE_2048 = 0 , GHOSTTY_SIZE_REPORT_CSI_14_T = 1 , GHOSTTY_SIZE_REPORT_CSI_16_T = 2 , GHOSTTY_SIZE_REPORT_CSI_18_T = 3 , GHOSTTY_SIZE_REPORT_STYLE_MAX_VALUE = GHOSTTY_ENUM_MAX_VALUE }

Functions

GHOSTTY_API GhosttyResult ghostty_size_report_encode (GhosttySizeReportStyle style, GhosttySizeReportSize size, char *buf, size_t buf_len, size_t *out_written)

Data Structures

struct  GhosttySizeReportSize

Enumeration Type Documentation

◆ GhosttySizeReportStyle

Size report style.

Determines the output format for the terminal size report.

Enumerator
GHOSTTY_SIZE_REPORT_MODE_2048 

In-band size report (mode 2048): ESC [ 48 ; rows ; cols ; height ; width t

GHOSTTY_SIZE_REPORT_CSI_14_T 

XTWINOPS text area size in pixels: ESC [ 4 ; height ; width t

GHOSTTY_SIZE_REPORT_CSI_16_T 

XTWINOPS cell size in pixels: ESC [ 6 ; height ; width t

GHOSTTY_SIZE_REPORT_CSI_18_T 

XTWINOPS text area size in characters: ESC [ 8 ; rows ; cols t

Definition at line 43 of file size_report.h.

Function Documentation

◆ ghostty_size_report_encode()

GHOSTTY_API GhosttyResult ghostty_size_report_encode ( GhosttySizeReportStyle style,
GhosttySizeReportSize size,
char * buf,
size_t buf_len,
size_t * out_written )

Encode a terminal size report into an escape sequence.

Encodes a size report in the format specified by style 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
StyleThe size report format to encode
sizeTerminal size information
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