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.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
- Initialize - Call
ghostty_init()to set up global state - Configure - Create and configure
ghostty_config_t - Create App - Initialize
ghostty_app_twith runtime callbacks - Create Surfaces - Create one or more
ghostty_surface_tfor terminals - Event Loop - Call
ghostty_app_tick()regularly and handle callbacks - Render - Call
ghostty_surface_draw()when rendering is needed - Cleanup - Free surfaces, app, and config on shutdown
Platform Support
- macOS
- iOS
- Linux
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
- Embedding Guide - Step-by-step tutorial for embedding
- Core Types - Detailed type documentation
- Configuration - Configuration API reference
- Input Handling - Keyboard and mouse input
- Rendering - Surface rendering and display