A Swift package wrapping Ghostty's terminal engine for embedding in macOS apps.
Add swift-ghostty as a Swift Package Manager dependency:
dependencies: [
.package(url: "https://github.com/NoDevOrg/swift-ghostty.git", from: "0.1.0"),
]Then add Ghostty to your target's dependencies:
.target(
name: "YourApp",
dependencies: [
.product(name: "Ghostty", package: "swift-ghostty"),
]
)The package depends on a pre-built GhosttyKit xcframework. Build it from the ghostty submodule:
git submodule update --init --recursive
make xcframeworkThis compiles the Ghostty C library from source using Zig and packages it as Frameworks/GhosttyKit.xcframework.zip.
import Ghostty
// Initialize once at app launch
GhosttyAppManager.shared.initialize()
// Embed a terminal in SwiftUI
GhosttyTerminalView(appManager: GhosttyAppManager.shared)See Examples/BasicTerminal for a complete working app.
make xcframework
cd Examples/BasicTerminal
swift runGhostty- Swift library with SwiftUI/AppKit terminal viewsGhosttyAppManager- Singleton managing the ghostty app lifecycleGhosttyTerminalView- SwiftUI view embedding a terminalGhosttyTerminalSurface- AppKit NSView with Metal rendering
GhosttyKit- Binary target wrapping the C xcframework