Skip to main content

Rendering and Display

The libghostty rendering API provides functions for managing terminal surface rendering, sizing, and display properties.

Surface Management

ghostty_surface_new

Creates a new terminal surface.
ghostty_app_t
required
The app instance that will own this surface.
const ghostty_surface_config_s*
required
Configuration for the new surface.
Returns: A new surface, or NULL on failure. Example:

ghostty_surface_free

Frees a surface and its resources.
ghostty_surface_t
required
The surface to free.

ghostty_surface_config_new

Creates a default surface configuration.
Returns: A configuration struct with default values.

ghostty_surface_inherited_config

Gets configuration for creating a derived surface (e.g., split).
ghostty_surface_t
required
The parent surface.
ghostty_surface_context_e
required
The context for the new surface (tab, split, etc.).
Returns: Configuration that inherits settings from the parent surface.

Rendering

ghostty_surface_draw

Draws the surface to its render target.
ghostty_surface_t
required
The surface to draw.
This function renders the terminal content using the platform’s native rendering backend (Metal on macOS/iOS, OpenGL on Linux). Example:

ghostty_surface_refresh

Marks the surface as needing a redraw.
ghostty_surface_t
required
The surface to refresh.
Call this when you want to force a redraw (e.g., after the view is uncovered).

Size and Scale

ghostty_surface_set_size

Sets the surface size in pixels.
ghostty_surface_t
required
The surface to resize.
uint32_t
required
New width in pixels.
uint32_t
required
New height in pixels.
Example:

ghostty_surface_size

Gets the current surface size.
ghostty_surface_t
required
The surface to query.
Returns: Surface size information including dimensions and cell size. Example:

ghostty_surface_set_content_scale

Sets the content scale factor (for high-DPI displays).
ghostty_surface_t
required
The surface.
double
required
Horizontal scale factor (e.g., 2.0 for Retina).
double
required
Vertical scale factor.
Example:

Focus and Occlusion

ghostty_surface_set_focus

Sets the focus state of the surface.
ghostty_surface_t
required
The surface.
bool
required
Whether the surface has focus.
This affects cursor rendering and keyboard input. Example:

ghostty_surface_set_occlusion

Sets whether the surface is occluded (hidden by other windows).
ghostty_surface_t
required
The surface.
bool
required
Whether the surface is occluded.
This can be used to reduce CPU/GPU usage when the terminal is not visible.

ghostty_surface_set_color_scheme

Sets the color scheme preference.
ghostty_surface_t
required
The surface.
ghostty_color_scheme_e
required
Color scheme (light or dark).
Example:

Configuration

ghostty_surface_update_config

Updates the surface configuration.
ghostty_surface_t
required
The surface to update.
ghostty_config_t
required
New configuration to apply.
This allows hot-reloading configuration without recreating the surface.

Surface Queries

ghostty_surface_userdata

Gets the user data pointer associated with the surface.
ghostty_surface_t
required
The surface.
Returns: The userdata pointer from ghostty_surface_config_s.

ghostty_surface_app

Gets the app that owns the surface.
ghostty_surface_t
required
The surface.
Returns: The parent app instance.

ghostty_surface_needs_confirm_quit

Checks if the surface needs confirmation before closing.
Returns: true if there’s a running process that would be terminated.

ghostty_surface_process_exited

Checks if the surface’s shell process has exited.
Returns: true if the process has exited.

Platform-Specific (macOS)

ghostty_surface_set_display_id

Sets the display ID for the surface (for proper font rendering).

ghostty_surface_quicklook_font

Gets the CTFont for QuickLook integration.
Returns: A CTFontRef (cast to void*).

ghostty_surface_quicklook_word

Gets the word under the cursor for QuickLook.

Text Selection

ghostty_surface_has_selection

Checks if the surface has an active selection.
Returns: true if text is selected.

ghostty_surface_read_selection

Reads the currently selected text.
ghostty_surface_t
required
The surface.
ghostty_text_s*
required
Pointer to store the selected text.
Returns: true if text was read successfully. Must free with ghostty_surface_free_text().

ghostty_surface_read_text

Reads text from a specific region.
ghostty_surface_t
required
The surface.
ghostty_selection_s
required
The region to read.
ghostty_text_s*
required
Pointer to store the text.
Returns: true if text was read successfully.

ghostty_surface_free_text

Frees text returned by read functions.

Surface Actions

ghostty_surface_binding_action

Executes a binding action by name.
ghostty_surface_t
required
The surface.
const char*
required
Action name.
uintptr_t
required
Length of action string.
Returns: true if the action was executed. Example:

ghostty_surface_request_close

Requests the surface to close.
ghostty_surface_t
required
The surface to close.
This will trigger the close_surface_cb callback.

Split Management

ghostty_surface_split

Splits the surface in a direction.
ghostty_surface_t
required
The surface to split.
ghostty_action_split_direction_e
required
Split direction (right, down, left, up).

ghostty_surface_split_focus

Moves focus to an adjacent split.

ghostty_surface_split_resize

Resizes a split pane.

ghostty_surface_split_equalize

Equalizes split pane sizes.

Complete Rendering Example

See Also