SwiftUI
SwiftUI integration starts with TerminalViewState. It owns the controller, exposes observable terminal state, and tracks the current TerminalSurface after a platform view attaches.
State
import SwiftUI
import GhosttyTerminal
struct TerminalScreen: View {
@StateObject private var terminal = TerminalViewState()
var body: some View {
TerminalSurfaceView(context: terminal)
.navigationTitle(terminal.title)
}
}
Observable properties include title, surfaceSize, isFocused, bellCount, lastBellAt, desktop notification metadata, workingDirectory, and command-finished metadata.
View
TerminalSurfaceView embeds the platform terminal view and adopts the current SwiftUI color scheme. iOS 15, macOS 13, and Mac Catalyst 15 are the SwiftUI floor for this wrapper.
TerminalSurfaceView(context: terminal)
.onAppear {
terminal.configuration = TerminalSurfaceOptions(
backend: .inMemory(session),
fontSize: 13,
workingDirectory: "/"
)
}
Input
Call send(_:) after the surface attaches. The method returns true when Ghostty accepts the text.
@discardableResult
func sendCommand(_ command: String) -> Bool {
terminal.send(command + "\r")
}
Configuration
Use fluent configuration for common Ghostty settings, and custom(_:_:) for additional Ghostty config keys.
let config = TerminalConfiguration.default
.fontFamily("SF Mono")
.fontSize(13)
.windowPaddingX(8)
.windowPaddingY(6)
.custom("shell-integration", "detect")
terminal.setTerminalConfiguration(config)