Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,18 @@ public struct SSHTuiConnection: Sendable {
"-o", "RemoteCommand=none", "-o", "RequestTTY=no"]
if let port = configuration.port { arguments += ["-p", String(port)] }
if let identity = configuration.identityFile { arguments += ["-i", identity] }
for option in configuration.sshOptions { arguments += ["-o", option] }
for option in sshOptions { arguments += ["-o", option] }
return arguments
}

/// The caller's options plus cmux's shared ControlMaster, as 0.64.25's
/// connection broker used for every connect. Snapshots drop control
/// options, so without this a restored carrier opens its own connection,
/// which batch mode can't log in on a password-only host.
private var sshOptions: [String] {
SSHConnectionSharingOptions().mergingDefaults(into: configuration.sshOptions)
}

/// The daemon owns the login shell and therefore keeps it alive when SSH disconnects.
public var shellCommand: [String] {
if let restored = configuration.restoredSSHSession,
Expand Down Expand Up @@ -86,7 +94,7 @@ public struct SSHTuiConnection: Sendable {
var sshArguments = ["-o", "BatchMode=yes", "-o", "RequestTTY=no", "-o", "RemoteCommand=none"]
if let port = configuration.port { sshArguments += ["-p", String(port)] }
if let identity = configuration.identityFile { sshArguments += ["-i", identity] }
for option in configuration.sshOptions { sshArguments += ["-o", option] }
for option in sshOptions { sshArguments += ["-o", option] }
// The carrier is a headless exec channel that reconnects for its whole
// lifetime. Batch mode turns a prompt it cannot answer into OpenSSH's
// own failure. Interactive authentication and host-key prompts precede
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,15 @@ public struct CloudTuiManualIOCommand: Sendable {
return command
}

/// Writes raw input bytes to the remote PTY.
/// Writes raw input bytes to the remote PTY. Input asks for no reply, so a
/// relay can carry it as compact one-way input.
public func input(surfaceID: UInt64, bytes: Data, requestID: UInt64 = 1) -> [String: Any] {
[
"id": requestID,
"cmd": "send",
"surface": surfaceID,
"bytes": bytes.base64EncodedString(),
"no_reply": true,
]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ public final class CloudTuiManualIOConnection: @unchecked Sendable {
pendingLineSearchOffset = 0
guard !line.isEmpty,
let frame = deliversJSONMessages ? CloudTuiManualIOFrame.message(line) : CloudTuiManualIOFrameDecoder().decode(line) else { continue }
// Id zero is untracked input. A daemon that still answers it
// must not cost the consumer a turn ahead of the echo.
if case let .response(requestID, _, _, _, _, _, _) = frame, requestID == 0 { continue }
let continuation = nextFrameContinuation
nextFrameContinuation = nil
suspendReadSourceLocked()
Expand Down
7 changes: 7 additions & 0 deletions Sources/Cloud/CloudTuiManualMirrorSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,13 @@ final class CloudTuiManualMirrorSession {
claimUnsupported = false
sendClaimIfNeeded()
}
/// Called for each explicit keystroke or paste in this pane. The pane the
/// user is typing in must be the authoritative geometry owner. An owner
/// already confirmed, or a server without claims, sends its keys alone.
func noteExplicitInput() {
guard (!geometryClaimed && !claimUnsupported) || geometryClaimBlockedByPeer else { return }
claimGeometry()
}
/// Permanently tears down this view's attachment without closing the remote
/// terminal. Closing the control socket is the cleanup fence for old
/// servers; newer servers additionally retire the lease with the same close.
Expand Down
2 changes: 1 addition & 1 deletion Sources/Surfaces/CmuxTuiSurfaceProvider+ManualMirror.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ extension CmuxTuiSurfaceProvider {
let existingExplicitInput = created.surface.onExplicitInput
created.surface.onExplicitInput = { [weak session] in
existingExplicitInput?()
session?.claimGeometry()
session?.noteExplicitInput()
}
manualMirrorSessions[created.panelID] = session
session.reconnect(socketPath: connected.socketPath)
Expand Down
4 changes: 3 additions & 1 deletion Sources/Surfaces/Workspace+CloudManualMirror.swift
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ extension Workspace {
) throws -> UUID {
let previousPane = bonsplitController.focusedPaneId
let previousTab = previousPane.flatMap { bonsplitController.selectedTab(inPane: $0)?.id }
// Bonsplit moves focus into the new pane, so capture the source terminal first.
let previousHostedView = focusedTerminalInputTarget()?.panel.hostedView
panels[panel.id] = panel
panelTitles[panel.id] = Self.cloudManualMirrorTabTitle
let tab = Bonsplit.Tab(
Expand Down Expand Up @@ -238,7 +240,7 @@ extension Workspace {
rememberTerminalConfigInheritanceSource(panel)
panel.surface.flushPendingManualSizeReportIfAttached()
if focus {
focusPanel(panel.id)
focusNewSplitPanel(panel.id, previousHostedView: previousHostedView, reason: "workspace.cloudSplitReparent")
} else if let previousPane {
bonsplitController.focusPane(previousPane)
if let previousTab { bonsplitController.selectTab(previousTab) }
Expand Down
19 changes: 11 additions & 8 deletions Sources/Workspace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9064,15 +9064,8 @@ final class Workspace: Identifiable, ObservableObject, FilePreviewTabMetadataHos
)
#endif

// Suppress the old view's becomeFirstResponder side-effects during SwiftUI reparenting.
// Without this, reparenting triggers onFocus + ghostty_surface_set_focus on the old view,
// stealing focus from the new panel and creating model/surface divergence.
if focus {
suppressReparentFocusUntilLayoutFollowUp(
previousHostedView,
reason: "workspace.terminalSplitReparent"
)
focusPanel(newPanel.id, previousHostedView: previousHostedView)
focusNewSplitPanel(newPanel.id, previousHostedView: previousHostedView, reason: "workspace.terminalSplitReparent")
} else {
preserveFocusAfterNonFocusSplit(
preferredPanelId: previousFocusedPanelId,
Expand Down Expand Up @@ -11431,6 +11424,16 @@ final class Workspace: Identifiable, ObservableObject, FilePreviewTabMetadataHos
}
// MARK: - Focus Management

/// Focuses a panel a split just created. `previousHostedView` is the terminal that
/// had focus before Bonsplit moved it. SwiftUI reparents that view into the new
/// split, which would trigger onFocus + ghostty_surface_set_focus on it and steal
/// focus back from the new panel, so its becomeFirstResponder side effects stay
/// suppressed until the layout follow-up.
func focusNewSplitPanel(_ panelId: UUID, previousHostedView: GhosttySurfaceScrollView?, reason: String) {
suppressReparentFocusUntilLayoutFollowUp(previousHostedView, reason: reason)
focusPanel(panelId, previousHostedView: previousHostedView)
}

func preserveFocusAfterNonFocusSplit(
preferredPanelId: UUID?,
splitPanelId: UUID,
Expand Down
1 change: 1 addition & 0 deletions cmux-tui/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cmux-tui/crates/cmux-remote/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ cmux-remote-protocol.workspace = true
cmux-tui-core.workspace = true
cmux-wg = { workspace = true, optional = true }
diffy.workspace = true
flate2.workspace = true
fs4.workspace = true
futures-util.workspace = true
getrandom.workspace = true
Expand Down
Loading
Loading