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.void*
The main application instance. Manages global state, configuration, and coordinates multiple surfaces.Created with
ghostty_app_new() and freed with ghostty_app_free().void*
Configuration object containing terminal settings and behavior.Created with
ghostty_config_new() and freed with ghostty_config_free().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().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.enum
Invalid/uninitialized platform.
enum
macOS platform with Metal rendering and NSView integration.
enum
iOS platform with Metal rendering and UIView integration.
ghostty_platform_macos_s
Platform-specific data for macOS.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.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.ghostty_platform_e.
Surface Configuration
ghostty_surface_config_s
Configuration for creating a new terminal surface.ghostty_platform_e
required
The target platform for this surface.
ghostty_platform_u
required
Platform-specific configuration data. Use the field corresponding to
platform_tag.void*
Arbitrary pointer to user data. Retrieved with
ghostty_surface_userdata().double
Display scale factor (e.g., 2.0 for Retina displays). Used for high-DPI rendering.
float
Font size in points.
const char*
Initial working directory for the shell. NULL for user’s home directory.
const char*
Command to run instead of the default shell. NULL for default shell.
ghostty_env_var_s*
Array of environment variables to set for the shell.
size_t
Number of environment variables in
env_vars.const char*
Text to send to the terminal after initialization. NULL for no initial input.
bool
If true, keep the terminal open after the command exits.
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.enum
Surface is the primary terminal in a window.
enum
Surface is in a tab.
enum
Surface is in a split pane.
ghostty_surface_size_s
Describes the size of a terminal surface.uint16_t
Number of character columns.
uint16_t
Number of character rows.
uint32_t
Width in pixels.
uint32_t
Height in pixels.
uint32_t
Width of a single character cell in pixels.
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.void*
Arbitrary pointer passed to all callbacks. Retrieved with
ghostty_app_userdata().bool
Whether the platform supports X11-style selection clipboard (middle-click paste).
ghostty_runtime_wakeup_cb
required
Callback invoked when libghostty needs the event loop to wake up.
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.ghostty_runtime_read_clipboard_cb
Callback invoked when the terminal needs to read from the clipboard.
ghostty_runtime_confirm_read_clipboard_cb
Callback invoked when the terminal needs confirmation before reading the clipboard (OSC 52).
ghostty_runtime_write_clipboard_cb
Callback invoked when the terminal needs to write to the clipboard.
ghostty_runtime_close_surface_cb
Callback invoked when a surface should be closed.
Clipboard Types
ghostty_clipboard_e
Clipboard selection type.enum
Standard system clipboard (Ctrl+C/Ctrl+V).
enum
X11 selection clipboard (middle-click paste).
ghostty_clipboard_content_s
Content for clipboard operations.const char*
MIME type of the content (e.g., “text/plain”, “text/html”).
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.const char*
Pointer to the string data.
uintptr_t
Length of the string in bytes.
bool
If true, the string is null-terminated.
ghostty_string_free().
ghostty_info_s
Information about the libghostty build.ghostty_build_mode_e
The build mode (debug, release, etc.).
const char*
Version string (not null-terminated, use
version_len).uintptr_t
Length of the version string.
ghostty_build_mode_e
ghostty_diagnostic_s
A configuration diagnostic (warning or error).const char*
Human-readable diagnostic message.
Color Types
ghostty_color_scheme_e
System color scheme preference.ghostty_config_color_s
RGB color value.uint8_t
Red component (0-255).
uint8_t
Green component (0-255).
uint8_t
Blue component (0-255).
Environment Variables
ghostty_env_var_s
An environment variable key-value pair.const char*
Environment variable name.
const char*
Environment variable value.
Constants
GHOSTTY_SUCCESS
ghostty_init().
See Also
- Configuration API - Configuration types and functions
- Input Types - Input-related types
- Actions - Action types and rendering