Architecture

How the package wraps Ghostty, owns terminal state, bridges native input, and keeps sandboxed apps in control of I/O.

Layers

libghostty      Zig/C       Static library inside GhosttyKit.xcframework.
   |
GhosttyKit      Swift      Re-export of ghostty.h for direct C API access.
   |
GhosttyTerminal Swift      Controller, configuration, native views, input, surface lifecycle.
   |
GhosttyTheme    Swift      Theme catalog and TerminalConfiguration conversion helpers.
   |
ShellCraftKit   Swift      Sandboxed command engine backed by InMemoryTerminalSession.

Controller and surface

TerminalController is the source of truth for Ghostty app lifecycle and resolved configuration. It composes the base config source, per-session TerminalConfiguration, active TerminalTheme, and current color scheme into one rendered Ghostty config.

A platform view asks the controller to create a TerminalSurface. The surface owns the bridge to Ghostty’s renderer, callback table, display link, and host-managed I/O hooks.

Platform views

PlatformTypeInput model
iOS / CatalystUITerminalViewUITextInput, hardware presses, touch scrolling, input accessory bar.
macOSAppTerminalViewNSTextInputClient, key events, mouse and scroll events.
SwiftUITerminalSurfaceViewWraps the platform view and syncs SwiftUI color scheme.

Host-managed I/O

Example apps use GHOSTTY_SURFACE_IO_BACKEND_HOST_MANAGED. Ghostty produces user input bytes through callbacks, and the host feeds output bytes back through ghostty_surface_write_buffer. InMemoryTerminalSession owns this bridge for Swift callers.

iOS input chain

  1. Hardware keys arrive through pressesBegan and are translated into ghostty_input_key_s.
  2. Software keyboard text arrives through insertText(_:) and deletion through deleteBackward().
  3. Marked text flows through TerminalTextInputHandler and calls Ghostty preedit APIs.
  4. The accessory bar dispatches terminal keys and sticky Ctrl/Alt/Cmd modifiers.
  5. Long-press selection requests are delegated to the host with a viewport snapshot.

Trimmed build

ComponentBundled stateReason
Terminal coreIncludedVT parser, state machine, grid.
Metal rendererIncludedCAMetalLayer / IOSurface rendering.
CoreText font backendIncludedApple text shaping and rasterization.
Custom shadersDisabledEmbedded apps get a smaller dependency graph.
Inspector UIDisabledHost apps own diagnostics UI.
Native app runtimeDisabledUIKit/AppKit/SwiftUI hosts provide the runtime.
Host-managed I/O backendAddedSandbox-friendly terminal transport.
iOS platform fixesAddedMetal row alignment, simulator fixes, deployment-target adjustments.

Architecture rules