Skip to main content

Core Types

This page documents the core types and data structures used throughout the libghostty C API.

Opaque Types

These types are opaque pointers managed entirely by libghostty. Never dereference these pointers directly.
ghostty_app_t
void*
The main application instance. Manages global state, configuration, and coordinates multiple surfaces.Created with ghostty_app_new() and freed with ghostty_app_free().
ghostty_config_t
void*
Configuration object containing terminal settings and behavior.Created with ghostty_config_new() and freed with ghostty_config_free().
ghostty_surface_t
void*
A terminal surface (a single terminal instance). Each surface represents one terminal that can be rendered.Created with ghostty_surface_new() and freed with ghostty_surface_free().
ghostty_inspector_t
void*
An inspector/debugger interface for viewing terminal state.Obtained with ghostty_surface_inspector() and freed with ghostty_inspector_free().

Platform Types

ghostty_platform_e

Defines the target platform for a surface.
GHOSTTY_PLATFORM_INVALID
enum
Invalid/uninitialized platform.
GHOSTTY_PLATFORM_MACOS
enum
macOS platform with Metal rendering and NSView integration.
GHOSTTY_PLATFORM_IOS
enum
iOS platform with Metal rendering and UIView integration.

ghostty_platform_macos_s

Platform-specific data for macOS.
nsview
void*
Pointer to an NSView (cast to void*). The terminal will render into this view using Metal.

ghostty_platform_ios_s

Platform-specific data for iOS.
uiview
void*
Pointer to a UIView (cast to void*). The terminal will render into this view using Metal.

ghostty_platform_u

Union of platform-specific data.
Use the appropriate field based on ghostty_platform_e.

Surface Configuration

ghostty_surface_config_s

Configuration for creating a new terminal surface.
platform_tag
ghostty_platform_e
required
The target platform for this surface.
platform
ghostty_platform_u
required
Platform-specific configuration data. Use the field corresponding to platform_tag.
userdata
void*
Arbitrary pointer to user data. Retrieved with ghostty_surface_userdata().
scale_factor
double
Display scale factor (e.g., 2.0 for Retina displays). Used for high-DPI rendering.
font_size
float
Font size in points.
working_directory
const char*
Initial working directory for the shell. NULL for user’s home directory.
command
const char*
Command to run instead of the default shell. NULL for default shell.
env_vars
ghostty_env_var_s*
Array of environment variables to set for the shell.
env_var_count
size_t
Number of environment variables in env_vars.
initial_input
const char*
Text to send to the terminal after initialization. NULL for no initial input.
wait_after_command
bool
If true, keep the terminal open after the command exits.
context
ghostty_surface_context_e
Context in which the surface is being created (window, tab, split).

ghostty_surface_context_e

Defines the UI context for a surface.
GHOSTTY_SURFACE_CONTEXT_WINDOW
enum
Surface is the primary terminal in a window.
GHOSTTY_SURFACE_CONTEXT_TAB
enum
Surface is in a tab.
GHOSTTY_SURFACE_CONTEXT_SPLIT
enum
Surface is in a split pane.

ghostty_surface_size_s

Describes the size of a terminal surface.
columns
uint16_t
Number of character columns.
rows
uint16_t
Number of character rows.
width_px
uint32_t
Width in pixels.
height_px
uint32_t
Height in pixels.
cell_width_px
uint32_t
Width of a single character cell in pixels.
cell_height_px
uint32_t
Height of a single character cell in pixels.

Runtime Configuration

ghostty_runtime_config_s

Configuration for runtime callbacks that libghostty uses to communicate with the host application.
userdata
void*
Arbitrary pointer passed to all callbacks. Retrieved with ghostty_app_userdata().
supports_selection_clipboard
bool
Whether the platform supports X11-style selection clipboard (middle-click paste).
wakeup_cb
ghostty_runtime_wakeup_cb
required
Callback invoked when libghostty needs the event loop to wake up.
action_cb
ghostty_runtime_action_cb
required
Callback invoked when the terminal performs an action (ring bell, change title, etc.).
Return true if the action was handled, false otherwise.
read_clipboard_cb
ghostty_runtime_read_clipboard_cb
Callback invoked when the terminal needs to read from the clipboard.
confirm_read_clipboard_cb
ghostty_runtime_confirm_read_clipboard_cb
Callback invoked when the terminal needs confirmation before reading the clipboard (OSC 52).
write_clipboard_cb
ghostty_runtime_write_clipboard_cb
Callback invoked when the terminal needs to write to the clipboard.
close_surface_cb
ghostty_runtime_close_surface_cb
Callback invoked when a surface should be closed.

Clipboard Types

ghostty_clipboard_e

Clipboard selection type.
GHOSTTY_CLIPBOARD_STANDARD
enum
Standard system clipboard (Ctrl+C/Ctrl+V).
GHOSTTY_CLIPBOARD_SELECTION
enum
X11 selection clipboard (middle-click paste).

ghostty_clipboard_content_s

Content for clipboard operations.
mime
const char*
MIME type of the content (e.g., “text/plain”, “text/html”).
data
const char*
The clipboard data as a null-terminated string.

ghostty_clipboard_request_e

Type of clipboard request.

Utility Types

ghostty_string_s

A string returned by libghostty that must be freed.
ptr
const char*
Pointer to the string data.
len
uintptr_t
Length of the string in bytes.
sentinel
bool
If true, the string is null-terminated.
Free with ghostty_string_free().

ghostty_info_s

Information about the libghostty build.
build_mode
ghostty_build_mode_e
The build mode (debug, release, etc.).
version
const char*
Version string (not null-terminated, use version_len).
version_len
uintptr_t
Length of the version string.

ghostty_build_mode_e

ghostty_diagnostic_s

A configuration diagnostic (warning or error).
message
const char*
Human-readable diagnostic message.

Color Types

ghostty_color_scheme_e

System color scheme preference.

ghostty_config_color_s

RGB color value.
r
uint8_t
Red component (0-255).
g
uint8_t
Green component (0-255).
b
uint8_t
Blue component (0-255).

Environment Variables

ghostty_env_var_s

An environment variable key-value pair.
key
const char*
Environment variable name.
value
const char*
Environment variable value.

Constants

GHOSTTY_SUCCESS

Return value indicating successful operation. Used by functions like ghostty_init().

See Also