- M0: libghostty SSH 终端(渲染/输入/连接)+ 白屏修复(OutputGate) + 会话状态机/自动重连 - M1: tsnet 用户态组网 + SSH-over-tsnet(fd 桥),shell 级真机验证;R5(Go+gvisor+C+++Swift 同进程) retire - M1.5: tmux -CC 原生 tab(MVP) - 结构: packages/(TXCore·TXTransport), apps/TerminalX, vendor/(libghostty-spm/libssh2/mbedtls/tsnet-bridge), artifacts/ - 文档: CLAUDE.md + docs/HANDOFF.md(新会话入口) - 环境: 认证代理→依赖 vendor 本地化;Go 在 ~/.local/go;仅模拟器/未签名 - 待续: M2 mosh, tmux 多 pane, M4 安全(host key/SE) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
82 lines
2.5 KiB
Swift
82 lines
2.5 KiB
Swift
//
|
|
// TerminalStickyModifierState.swift
|
|
// libghostty-spm
|
|
//
|
|
|
|
#if canImport(UIKit) && !targetEnvironment(macCatalyst)
|
|
import Foundation
|
|
|
|
@MainActor
|
|
final class TerminalStickyModifierState {
|
|
enum Activation { case inactive, armed, locked }
|
|
enum Modifier { case ctrl, alt, command }
|
|
|
|
private(set) var ctrl: Activation = .inactive
|
|
private(set) var alt: Activation = .inactive
|
|
private(set) var command: Activation = .inactive
|
|
|
|
var onChange: (() -> Void)?
|
|
|
|
private var lastCtrlTap: Date = .distantPast
|
|
private var lastAltTap: Date = .distantPast
|
|
private var lastCommandTap: Date = .distantPast
|
|
private let doubleTapInterval: TimeInterval = 0.3
|
|
|
|
func toggle(_ modifier: Modifier) {
|
|
switch modifier {
|
|
case .ctrl:
|
|
ctrl = nextActivation(ctrl, lastTap: lastCtrlTap)
|
|
lastCtrlTap = Date()
|
|
case .alt:
|
|
alt = nextActivation(alt, lastTap: lastAltTap)
|
|
lastAltTap = Date()
|
|
case .command:
|
|
command = nextActivation(command, lastTap: lastCommandTap)
|
|
lastCommandTap = Date()
|
|
}
|
|
onChange?()
|
|
}
|
|
|
|
func consumeForNextKey() -> TerminalInputModifiers {
|
|
var mods = TerminalInputModifiers()
|
|
if ctrl != .inactive { mods.insert(.ctrl) }
|
|
if alt != .inactive { mods.insert(.alt) }
|
|
if command != .inactive { mods.insert(.super_) }
|
|
if ctrl == .armed { ctrl = .inactive }
|
|
if alt == .armed { alt = .inactive }
|
|
if command == .armed { command = .inactive }
|
|
onChange?()
|
|
return mods
|
|
}
|
|
|
|
var hasActiveModifiers: Bool {
|
|
ctrl != .inactive || alt != .inactive || command != .inactive
|
|
}
|
|
|
|
func reset() {
|
|
guard hasActiveModifiers else { return }
|
|
ctrl = .inactive
|
|
alt = .inactive
|
|
command = .inactive
|
|
onChange?()
|
|
}
|
|
|
|
private func nextActivation(
|
|
_ current: Activation,
|
|
lastTap: Date
|
|
) -> Activation {
|
|
switch current {
|
|
case .inactive:
|
|
return .armed
|
|
case .armed:
|
|
if Date().timeIntervalSince(lastTap) < doubleTapInterval {
|
|
return .locked
|
|
}
|
|
return .inactive
|
|
case .locked:
|
|
return .inactive
|
|
}
|
|
}
|
|
}
|
|
#endif
|