fix: clear terminal on connect, increase SIGWINCH settle time to 600ms

This commit is contained in:
jay 2026-05-16 04:00:02 +02:00
parent 994b450fe4
commit d085444adc
1 changed files with 11 additions and 4 deletions

View File

@ -103,20 +103,27 @@ struct MainTerminalView: View {
Task { try? await conn.send(.keys(data: text)) } Task { try? await conn.send(.keys(data: text)) }
} }
// On first connection: resize brief pause (SIGWINCH propagation) // On first connection:
// snapshot. This avoids replaying history at the wrong size. // 1. Clear SwiftTerm immediately (removes stale content)
// 2. Send resize so tmux + shell know the real dimensions
// 3. Wait for SIGWINCH to propagate and shell to redraw
// 4. Snapshot the now-stable screen state
conn.$connectionState conn.$connectionState
.filter { $0 == .connected } .filter { $0 == .connected }
.first() .first()
.receive(on: DispatchQueue.main) .receive(on: DispatchQueue.main)
.sink { [weak conn, terminalVC] _ in .sink { [weak conn, terminalVC] _ in
// Clear immediately dont show stale/mismatched content.
terminalVC.feed(data: Data("\u{1B}[H\u{1B}[2J".utf8))
Task { @MainActor in Task { @MainActor in
let (cols, rows) = terminalVC.terminalSize let (cols, rows) = terminalVC.terminalSize
if cols > 0 && rows > 0 { if cols > 0 && rows > 0 {
try? await conn?.send(.resize(cols: cols, rows: rows)) try? await conn?.send(.resize(cols: cols, rows: rows))
} }
// Let tmux propagate SIGWINCH before snapshotting. // 600 ms: SIGWINCH fish/bash redraws tmux pane settles.
try? await Task.sleep(nanoseconds: 250_000_000) // SSH sessions need extra round-trip time.
try? await Task.sleep(nanoseconds: 600_000_000)
try? await conn?.send(.snapshotRequest) try? await conn?.send(.snapshotRequest)
} }
} }