Skip to main content

libghostty C API Overview

The libghostty C API enables you to embed a fast, feature-rich terminal emulator into any application. This library provides the core terminal functionality that powers the Ghostty terminal emulator.
The libghostty API is currently used primarily by the macOS app and is not yet stabilized for general-purpose embedding. The API may change significantly between releases.

What is libghostty?

libghostty is a C-compatible library that provides:
  • Full terminal emulation - Standards-compliant VT100/xterm emulation
  • Native rendering - Metal on macOS, OpenGL on Linux
  • Cross-platform support - macOS, iOS, Linux
  • Modern features - Ligatures, color schemes, splits, tabs
  • High performance - Dedicated IO threads, GPU-accelerated rendering

Use Cases

Common use cases for embedding libghostty:
  • Native terminal apps - Build platform-native terminal emulators (like the Ghostty macOS app)
  • IDE/Editor integration - Embed terminals in code editors and IDEs
  • DevOps tools - Add terminal capabilities to development and operations tools
  • Educational software - Interactive coding environments and tutorials

Architecture

The libghostty API is organized around several key concepts:

Application Flow

  1. Initialize - Call ghostty_init() to set up global state
  2. Configure - Create and configure ghostty_config_t
  3. Create App - Initialize ghostty_app_t with runtime callbacks
  4. Create Surfaces - Create one or more ghostty_surface_t for terminals
  5. Event Loop - Call ghostty_app_tick() regularly and handle callbacks
  6. Render - Call ghostty_surface_draw() when rendering is needed
  7. Cleanup - Free surfaces, app, and config on shutdown

Platform Support

Full support with Metal rendering:
  • SwiftUI/AppKit integration
  • Metal rendering backend
  • CoreText font discovery
  • Native menu and window chrome

Quick Example

Here’s a minimal example of embedding libghostty:

Next Steps

API Stability

The current libghostty API is not stable. Future versions of libghostty-vt will provide a stable, cross-platform terminal parsing library. The full libghostty embedding API will be stabilized in a future release. See the libghostty blog post for more details on the roadmap.