libghostty
Loading...
Searching...
No Matches
types.h File Reference
#include <limits.h>
#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  GhosttyString

Macros

#define GHOSTTY_ENUM_TYPED
#define GHOSTTY_INIT_SIZED(type)

Typedefs

typedef struct GhosttyTerminalImpl * GhosttyTerminal
typedef struct GhosttyKittyGraphicsImpl * GhosttyKittyGraphics
typedef const struct GhosttyKittyGraphicsImageImpl * GhosttyKittyGraphicsImage
typedef struct GhosttyKittyGraphicsPlacementIteratorImpl * GhosttyKittyGraphicsPlacementIterator
typedef struct GhosttyRenderStateImpl * GhosttyRenderState
typedef struct GhosttyRenderStateRowIteratorImpl * GhosttyRenderStateRowIterator
typedef struct GhosttyRenderStateRowCellsImpl * GhosttyRenderStateRowCells
typedef struct GhosttySgrParserImpl * GhosttySgrParser
typedef struct GhosttyFormatterImpl * GhosttyFormatter
typedef struct GhosttyOscParserImpl * GhosttyOscParser
typedef struct GhosttyOscCommandImpl * GhosttyOscCommand

Enumerations

enum  GhosttyResult {
  GHOSTTY_SUCCESS = 0 , GHOSTTY_OUT_OF_MEMORY = -1 , GHOSTTY_INVALID_VALUE = -2 , GHOSTTY_OUT_OF_SPACE = -3 ,
  GHOSTTY_NO_VALUE = -4 , GHOSTTY_RESULT_MAX_VALUE = GHOSTTY_ENUM_MAX_VALUE
}

Functions

GHOSTTY_API const char * ghostty_type_json (void)

Detailed Description

Common types, macros, and utilities for libghostty-vt.

Definition in file types.h.

Macro Definition Documentation

◆ GHOSTTY_ENUM_TYPED

#define GHOSTTY_ENUM_TYPED

Enum int-sizing helpers.

The Zig side backs all C enums with c_int, so the C declarations must use int as their underlying type to maintain ABI compatibility.

C23 (detected via STDC_VERSION >= 202311L) supports explicit enum underlying types with enum : int { ... }. For pre-C23 compilers, which are free to choose any type that can represent all values (C11 ยง6.7.2.2), we add an INT_MAX sentinel as the last entry to force the compiler to use int.

INT_MAX is used rather than a fixed constant like 0xFFFFFFFF because enum constants must have type int (which is signed). Values above INT_MAX overflow signed int and are a constraint violation in standard C; compilers that accept them interpret them as negative values via two's complement, which can collide with legitimate negative enum values.

Usage:

typedef enum GHOSTTY_ENUM_TYPED {
FOO_A = 0,
FOO_B = 1,
FOO_MAX_VALUE = GHOSTTY_ENUM_MAX_VALUE,
} Foo;
#define GHOSTTY_ENUM_TYPED
Definition types.h:67

Definition at line 67 of file types.h.

◆ GHOSTTY_INIT_SIZED

#define GHOSTTY_INIT_SIZED ( type)
Value:
((type){ .size = sizeof(type) })

Initialize a sized struct to zero and set its size field.

Sized structs use a size field as the first member for ABI compatibility. This macro zero-initializes the struct and sets the size field to sizeof(type), which allows the library to detect which version of the struct the caller was compiled against.

Parameters
typeThe struct type to initialize
Returns
A zero-initialized struct with the size field set

Example:

Examples
c-vt-formatter/src/main.c, and c-vt-grid-traverse/src/main.c.

Definition at line 219 of file types.h.

Enumeration Type Documentation

◆ GhosttyResult

Result codes for libghostty-vt operations.

Enumerator
GHOSTTY_SUCCESS 

Operation completed successfully

GHOSTTY_OUT_OF_MEMORY 

Operation failed due to failed allocation

GHOSTTY_INVALID_VALUE 

Operation failed due to invalid value

GHOSTTY_OUT_OF_SPACE 

Operation failed because the provided buffer was too small

GHOSTTY_NO_VALUE 

The requested value has no value

Examples
c-vt-encode-key/src/main.c, c-vt-encode-mouse/src/main.c, c-vt-formatter/src/main.c, c-vt-grid-traverse/src/main.c, c-vt-paste/src/main.c, and c-vt-sgr/src/main.c.

Definition at line 74 of file types.h.

Function Documentation

◆ ghostty_type_json()

GHOSTTY_API const char * ghostty_type_json ( void )

Return a pointer to a null-terminated JSON string describing the layout of every C API struct for the current target.

This is primarily useful for language bindings that can't easily set C struct fields and need to do so via byte offsets. For example, WebAssembly modules can't share struct definitions with the host.

Example (abbreviated):

{
"GhosttyMouseEncoderSize": {
"size": 40,
"align": 8,
"fields": {
"size": { "offset": 0, "size": 8, "type": "u64" },
"screen_width": { "offset": 8, "size": 4, "type": "u32" },
"screen_height": { "offset": 12, "size": 4, "type": "u32" },
"cell_width": { "offset": 16, "size": 4, "type": "u32" },
"cell_height": { "offset": 20, "size": 4, "type": "u32" },
"padding_top": { "offset": 24, "size": 4, "type": "u32" },
"padding_bottom": { "offset": 28, "size": 4, "type": "u32" },
"padding_right": { "offset": 32, "size": 4, "type": "u32" },
"padding_left": { "offset": 36, "size": 4, "type": "u32" }
}
}
}

The returned pointer is valid for the lifetime of the process.

Returns
Pointer to the null-terminated JSON string.