Files
terminalX/vendor/libghostty-spm
kid 6dd23275ff feat: 修复 3 个渲染/tmux 显示 bug + UI 产品化第一波(对标 Moshi)
渲染/tmux 修复(e2e 复现+回归,模拟器 idb 点击+截图取证):
- 终端底部残影:ghostty iOS 释放 surface 不摘 IOSurfaceLayer(上游缺陷),
  platformSetup 清现存子层 + TerminalSurfaceCoordinator.onSurfaceFreed 钩子摘孤儿层
- tmux 切 tab 切回旧 tab 内容消失:改所有窗口常驻挂载(ZStack+opacity+hitTesting),
  surface 不释放、内容保留、后台窗口持续收 %output
- tmux pane 内容钉底/顶部残行:pane grid 由容器几何定(tab 条吃高度),75 行快照喂 73 行
  溢出上滚;几何测量上移 TmuxTabbedView + attach kickoff 双条件(attachAcked∧containerKnown)
  + capture-pane 铺快照前剔尾空行

UI 产品化(对标 Moshi getmoshi.app:深蓝黑 + 终端绿 + Catppuccin):
- 设计系统 Theme.swift:TXPalette(色角色 struct)+TXThemeManager(环境注入),颜色封装供主题系统
- 统一主题:抽离 4 套 Catppuccin(Mocha/Macchiato/Frappé/Latte),一套同时驱动 app+终端配色,
  设置里选主题 app 与终端一起变色 + UserDefaults 持久化
- 主屏/主机管理页 HomeView:HostCard 主机卡 + FAB 加主机(AddHostSheet) + 设置(主题选择器),
  HostStore 本地 JSON 持久化(密码暂存/TODO Keychain),点卡片 connect(to:)
- 终端外壳 chrome TerminalTopBar:圆形返回钮 + 会话标题 + SSH/mosh 传输徽章 + 状态提示,
  tmux tab 绿 pill 化,底部工具栏深色自适应,终端默认 Catppuccin Mocha

iPad mini(A17 Pro) live 端到端验证:加主机→连接→终端→切 tab→分屏点焦点→主题切换同步。
详见 docs/HANDOFF.md §10。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-24 22:43:00 +08:00
..

GhosttyKit

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

Library Description
GhosttyKit Re-exports the libghostty C API (ghostty.h)
GhosttyTerminal Swift wrapper — native views, SwiftUI integration, input handling, display link
GhosttyTheme 485 terminal color themes from iTerm2-Color-Schemes (MIT License)
ShellCraftKit Sandboxed 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).

Prompt and scrollback navigation

TerminalViewState, TerminalView, and TerminalSurface expose the same programmatic navigation APIs:

terminal.jumpToPrompt(by: -1) // Previous prompt.
terminal.jumpToPrompt(by: 1)  // Next prompt.
terminal.scrollToRow(0)        // First absolute scrollback row.

Prompt navigation requires Ghostty shell integration, which records prompt boundaries. A host-managed backend must preserve or emit equivalent OSC 133 prompt markers. Arbitrary Ghostty actions remain available through performBindingAction(_:).

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.

Release Versioning

Bare semantic-version tags such as 1.3.1 are GhosttyKit Swift package versions. They are independent from Ghostty's upstream tags. The matching storage.1.3.1 release stores the XCFramework consumed by that package tag.

Release builds use the immutable upstream Ghostty commit recorded in Ghostty.ref. Updating Ghostty requires a reviewed change to that file, so a package release cannot silently switch to a different upstream tag or commit. Manual releases require an explicit package version; scheduled releases only increment the package patch version when main is newer than the latest package tag.

Trimmed Build

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

Component Upstream Ghostty libghostty-spm Reason
Terminal emulation core Yes Yes Full VT parser, state machine, grid — retained
Metal renderer Yes Yes GPU rendering via CAMetalLayer / IOSurface — retained
Font rasterization & shaping Yes Yes CoreText font backend — retained
Configuration system Yes Yes All terminal config options — retained
Input handling (key, mouse, IME) Yes Yes Full keyboard/mouse/touch/IME pipeline — retained
Text selection & clipboard Yes Yes Selection, copy/paste APIs — retained
Custom shaders (GLSL) Yes No glslang and spirv-cross removed (-Dcustom-shaders=false). Shadertoy/post-processing shaders are a desktop feature unnecessary for embedded use.
Terminal inspector (ImGui) Yes No dcimgui removed (-Dinspector=false). Debug inspector UI replaced with no-op stubs.
Sentry crash reporting Yes No Disabled (-Dsentry=false).
Native app runtime Yes No Cocoa/GTK/Wayland app shell disabled (-Dapp-runtime=none). The host app provides its own runtime.
Standalone executable Yes No No terminal .app or CLI binary emitted (-Demit-exe=false).
Documentation generation Yes No Skipped (-Demit-docs=false).
Frame data generator Build-time tool Pre-compiled framedata.compressed shipped pre-built; framegen C tool dependency removed.
Host-managed I/O backend No Added New GHOSTTY_SURFACE_IO_BACKEND_HOST_MANAGED for non-PTY, sandbox-safe terminal I/O.
iOS Metal rendering fixes No Added IOSurface +1px tolerance, synchronous present, 64-byte row alignment for iOS.
iOS platform fixes No Added Deployment 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.

Sponsor

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