GhosttyKit
Swift package for embedding Ghostty’s terminal emulator library in Apple apps. Native SwiftUI, UIKit, and AppKit views wrap a pre-built libghostty XCFramework.
Capabilities
- Terminal rendering: Ghostty’s VT parser, grid, CoreText font backend, and Metal renderer.
- SwiftUI:
TerminalSurfaceViewwith anObservableObjectTerminalViewState. - UIKit and AppKit: platform terminal views through the shared
TerminalViewtypealias. - Input: hardware keyboard, software keyboard, IME, mouse, touch scrolling, iOS accessory keys, sticky modifiers.
- Host-managed I/O: sandbox-friendly byte transport through
InMemoryTerminalSession. - Themes: 485 bundled iTerm2 color schemes exposed through
GhosttyThemeCatalog. - ShellCraftKit: a sandboxed shell emulation framework for demos and embedded command surfaces.
Install
Add the package to Package.swift:
dependencies: [
.package(url: "https://github.com/Lakr233/libghostty-spm.git", from: "1.2.0"),
],
targets: [
.target(name: "App", dependencies: [
.product(name: "GhosttyTerminal", package: "libghostty-spm"),
]),
]
Choose the product that matches the integration layer you need.
| Product | Use |
|---|---|
GhosttyKit | Direct access to the ghostty.h C API. |
GhosttyTerminal | Swift wrapper, native views, configuration, input, display link, host-managed I/O. |
GhosttyTheme | Bundled terminal color schemes and bridges to TerminalConfiguration. |
ShellCraftKit | Sandboxed shell emulation on top of GhosttyTerminal. |
Platforms
| Platform | Floor |
|---|---|
| iOS | 15.0 |
| macOS | 13.0 |
| Mac Catalyst | 15.0 |
Quick start
import SwiftUI
import GhosttyTerminal
struct ContentView: View {
@StateObject private var terminal = TerminalViewState()
private let session = InMemoryTerminalSession(
write: { data in
// Bytes from Ghostty to your host process or emulator.
},
resize: { viewport in
// Keep your backend grid in sync with Ghostty.
}
)
var body: some View {
TerminalSurfaceView(context: terminal)
.navigationTitle(terminal.title)
.onAppear {
terminal.configuration = TerminalSurfaceOptions(
backend: .inMemory(session)
)
}
}
}
InMemoryTerminalSession.receive(_:) writes host output into the terminal. The write closure receives terminal input bytes for your backend.
Examples
Example/GhosttyTerminalAppis the macOS AppKit demo with delegate callbacks.Example/MobileGhosttyAppis the iOS UIKit demo with keyboard, safe area, themes, and text selection.