GhosttyKit

June 1, 2026 · View on GitHub

Swift Package wrapping Ghostty's terminal emulator library for Apple platforms.

Pre-built libghostty static library distributed as an XCFramework binary target.

Platforms

  • macOS 13+
  • iOS 15+
  • Mac Catalyst 15+

Products

LibraryDescription
GhosttyKitRe-exports the libghostty C API (ghostty.h)
GhosttyTerminalSwift wrapper — native views, SwiftUI integration, input handling, display link
GhosttyTheme485 terminal color themes from iTerm2-Color-Schemes (MIT License)
ShellCraftKitSandboxed shell emulation framework (depends on GhosttyTerminal)

Installation

Add to your Package.swift:

dependencies: [
    .package(url: "https://github.com/Lakr233/libghostty-spm.git", from: "1.2.0"),
]

Then add the product you need:

.target(
    name: "YourTarget",
    dependencies: [
        .product(name: "GhosttyTerminal", package: "libghostty-spm"),
    ]
)

Usage

The example apps are the best starting point for real integration:

  • Example/GhosttyTerminalApp/ — macOS AppKit demo with delegate callbacks
  • Example/MobileGhosttyApp/ — iOS UIKit demo with keyboard, safe area, themes, and text selection

SwiftUI (iOS 15+ / macOS 13+ / Mac Catalyst 15+)

import SwiftUI
import GhosttyTerminal

struct ContentView: View {
    @StateObject private var terminal = TerminalViewState()
    private let session = InMemoryTerminalSession(
        write: { data in
            // Handle bytes produced by the terminal.
        },
        resize: { viewport in
            // Keep your host backend in sync with the terminal grid.
        }
    )

    var body: some View {
        TerminalSurfaceView(context: terminal)
            .navigationTitle(terminal.title)
            .onAppear {
                terminal.configuration = TerminalSurfaceOptions(
                    backend: .inMemory(session)
                )
            }
    }
}

UIKit / AppKit

import GhosttyTerminal

let terminalView = TerminalView(frame: .zero)
terminalView.delegate = self
terminalView.controller = TerminalController(configFilePath: path)
terminalView.configuration = TerminalSurfaceOptions(
    backend: .inMemory(session)
)

TerminalView is a type alias that resolves to UITerminalView (iOS/Catalyst) or AppTerminalView (macOS).

Notes

  • TerminalViewState is the SwiftUI state container.
  • TerminalView is the UIKit/AppKit view typealias.
  • TerminalController owns app lifecycle, config resolution, themes, and surface creation.
  • InMemoryTerminalSession provides the host-managed backend used by the sandboxed example apps.
  • GhosttyThemeCatalog exposes bundled iTerm2 color schemes.

Building from Source

The package includes a pre-built XCFramework. To rebuild libghostty from the Ghostty source:

# Requires: zig compiler
./Script/build.sh

This applies patches from Patches/ghostty/, builds for all target architectures, and assembles the XCFramework.

Trimmed Build

The bundled libghostty is a trimmed build optimized for sandboxed, embedded use on Apple platforms.

ComponentUpstream Ghosttylibghostty-spmReason
Terminal emulation coreYesYesFull VT parser, state machine, grid — retained
Metal rendererYesYesGPU rendering via CAMetalLayer / IOSurface — retained
Font rasterization & shapingYesYesCoreText font backend — retained
Configuration systemYesYesAll terminal config options — retained
Input handling (key, mouse, IME)YesYesFull keyboard/mouse/touch/IME pipeline — retained
Text selection & clipboardYesYesSelection, copy/paste APIs — retained
Custom shaders (GLSL)YesNoglslang and spirv-cross removed (-Dcustom-shaders=false). Shadertoy/post-processing shaders are a desktop feature unnecessary for embedded use.
Terminal inspector (ImGui)YesNodcimgui removed (-Dinspector=false). Debug inspector UI replaced with no-op stubs.
Sentry crash reportingYesNoDisabled (-Dsentry=false).
Native app runtimeYesNoCocoa/GTK/Wayland app shell disabled (-Dapp-runtime=none). The host app provides its own runtime.
Standalone executableYesNoNo terminal .app or CLI binary emitted (-Demit-exe=false).
Documentation generationYesNoSkipped (-Demit-docs=false).
Frame data generatorBuild-time toolPre-compiledframedata.compressed shipped pre-built; framegen C tool dependency removed.
Host-managed I/O backendNoAddedNew GHOSTTY_SURFACE_IO_BACKEND_HOST_MANAGED for non-PTY, sandbox-safe terminal I/O.
iOS Metal rendering fixesNoAddedIOSurface +1px tolerance, synchronous present, 64-byte row alignment for iOS.
iOS platform fixesNoAddedDeployment target lowered, private API removed, kqueue fix for simulator.

License

MIT License. See LICENSE for details.

The bundled libghostty binary is built from Ghostty, which has its own license terms.

  • LookInside helps you inspect a running iOS or macOS app UI from your Mac.
  • This project/repository is sponsored by AFK AI, INC.