libghostty-vt 0.0.0
Loading...
Searching...
No Matches
Size Reports

Encode size reports, for mode 2048 and XTWINOPS queries. More...

Detailed Description

Encode size reports, for mode 2048 and XTWINOPS queries.

A size report tells a program how big your terminal is, in cells and pixels.

These answer in-band size reports (mode 2048) and XTWINOPS queries (CSI 14 t, CSI 16 t, CSI 18 t, CSI 19 t). A terminal answers those for you through a GhosttyTerminalSizeFn, so you only need this without one. Fill in a GhosttySizeReportSize and pass it to ghostty_size_report_encode().

Example

int main() {
.rows = 24,
.columns = 80,
.cell_width = 9,
.cell_height = 18,
};
uint8_t 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;
}

Full program: c-vt-size-report/src/main.c

See the Effects guide for the terminal's callback.

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_CSI_19_T = 4 , GHOSTTY_SIZE_REPORT_STYLE_MAX_VALUE = GHOSTTY_ENUM_MAX_VALUE
}

Functions

GHOSTTY_API GhosttyResult ghostty_size_report_encode (GhosttySizeReportStyle style, const GhosttySizeReportSize *size, uint8_t *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

GHOSTTY_SIZE_REPORT_CSI_19_T 

XTWINOPS screen size in characters: ESC [ 9 ; rows ; cols t

The physical screen size is not known, so this reports the text area size in characters, the same as CSI 18 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,
const GhosttySizeReportSize * size,
uint8_t * 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 buf is too small, this returns GHOSTTY_OUT_OF_SPACE and sets out_written to the size needed. The buffer may then hold part of the sequence, which you should discard. To get the size without encoding anything, pass NULL for buf and 0 for buf_len.

Parameters
styleThe size report format to encode
sizeTerminal size information
bufBuffer to write the sequence into. May be NULL if buf_len is 0.
buf_lenSize of buf in bytes
[out]out_writtenThe number of bytes written, or the size needed if the result is GHOSTTY_OUT_OF_SPACE
Returns
GHOSTTY_SUCCESS on success, GHOSTTY_OUT_OF_SPACE if the buffer is too small, or GHOSTTY_INVALID_VALUE if size is NULL
Examples
c-vt-size-report/src/main.c.