From d085444adcb2f23ef9f408bc6cbfd2816bb10cd2 Mon Sep 17 00:00:00 2001 From: jay Date: Sat, 16 May 2026 04:00:02 +0200 Subject: [PATCH] fix: clear terminal on connect, increase SIGWINCH settle time to 600ms --- Sources/UI/Terminal/MainTerminalView.swift | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Sources/UI/Terminal/MainTerminalView.swift b/Sources/UI/Terminal/MainTerminalView.swift index 354a2db..235418c 100644 --- a/Sources/UI/Terminal/MainTerminalView.swift +++ b/Sources/UI/Terminal/MainTerminalView.swift @@ -103,20 +103,27 @@ struct MainTerminalView: View { Task { try? await conn.send(.keys(data: text)) } } - // On first connection: resize → brief pause (SIGWINCH propagation) - // → snapshot. This avoids replaying history at the wrong size. + // On first connection: + // 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 .filter { $0 == .connected } .first() .receive(on: DispatchQueue.main) .sink { [weak conn, terminalVC] _ in + // Clear immediately — don’t show stale/mismatched content. + terminalVC.feed(data: Data("\u{1B}[H\u{1B}[2J".utf8)) + Task { @MainActor in let (cols, rows) = terminalVC.terminalSize if cols > 0 && rows > 0 { try? await conn?.send(.resize(cols: cols, rows: rows)) } - // Let tmux propagate SIGWINCH before snapshotting. - try? await Task.sleep(nanoseconds: 250_000_000) + // 600 ms: SIGWINCH → fish/bash redraws → tmux pane settles. + // SSH sessions need extra round-trip time. + try? await Task.sleep(nanoseconds: 600_000_000) try? await conn?.send(.snapshotRequest) } }