From 5d2c28362d65d03cbb27ba134da4283ca50accb9 Mon Sep 17 00:00:00 2001 From: onevcat Date: Fri, 17 Apr 2026 08:56:20 +0900 Subject: [PATCH] Delay auto-close by 800ms so users can see final output MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Immediate close on exit 0 was too abrupt — the tab/split vanished before the user could read the command's final output. Schedule the close on a Task that sleeps 800ms first, then verifies the surface still exists before issuing close. The id is still removed from the auto-close set synchronously so a second command in that window cannot trigger the close again. --- .../Terminal/Models/WorktreeTerminalState.swift | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/supacode/Features/Terminal/Models/WorktreeTerminalState.swift b/supacode/Features/Terminal/Models/WorktreeTerminalState.swift index 198efbc5..28443843 100644 --- a/supacode/Features/Terminal/Models/WorktreeTerminalState.swift +++ b/supacode/Features/Terminal/Models/WorktreeTerminalState.swift @@ -536,6 +536,18 @@ final class WorktreeTerminalState { autoCloseSurfaceIds.contains(surfaceId) } + // Short delay lets the user see the final output before the pane disappears. + private static let autoCloseDelay: Duration = .milliseconds(800) + + private func scheduleAutoClose(surfaceId: UUID) { + Task { [weak self] in + try? await Task.sleep(for: Self.autoCloseDelay) + guard let self else { return } + guard let view = self.surfaces[surfaceId] else { return } + self.handleCloseRequest(for: view, processAlive: false) + } + } + func performSplitAction(_ action: GhosttySplitAction, for surfaceId: UUID) -> Bool { guard let tabId = tabId(containing: surfaceId), var tree = trees[tabId] else { return false @@ -1294,8 +1306,8 @@ final class WorktreeTerminalState { // Auto-close on success (exit 0). One-shot: the id is removed regardless of outcome. if autoCloseSurfaceIds.remove(surfaceId) != nil { - if exitCode == 0, let view = surfaces[surfaceId] { - handleCloseRequest(for: view, processAlive: false) + if exitCode == 0, surfaces[surfaceId] != nil { + scheduleAutoClose(surfaceId: surfaceId) return } } -- 2.51.2