Skip to content

Commit a667129

Browse files
andyrewleeclaude
andcommitted
Extract resetPTYStateLocked to dedup 4 identical cleanup blocks
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 56756cc commit a667129

4 files changed

Lines changed: 17 additions & 28 deletions

File tree

internal/ui/center/model_lifecycle.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,7 @@ func (m *Model) Close() {
202202
tab.ptyTraceFile = nil
203203
tab.ptyTraceClosed = true
204204
}
205-
tab.pendingOutput = nil
206-
tab.pendingOutputBytes = 0
207-
tab.clearCatchUpLocked()
208-
tab.ptyBytesReceived = 0
209-
tab.ptyBytesSettled = 0
210-
tab.ptyNoiseTrailing = nil
211-
tab.actorQueuedBytes = 0
205+
tab.resetPTYStateLocked()
212206
tab.DiffViewer = nil
213207
tab.Terminal = nil
214208
tab.cachedSnap = nil

internal/ui/center/model_tab.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,19 @@ func (t *Tab) normalizePTYAccountingLocked() {
212212
}
213213
}
214214

215+
func (t *Tab) resetPTYStateLocked() {
216+
if t == nil {
217+
return
218+
}
219+
t.pendingOutput = nil
220+
t.pendingOutputBytes = 0
221+
t.clearCatchUpLocked()
222+
t.ptyBytesReceived = 0
223+
t.ptyBytesSettled = 0
224+
t.ptyNoiseTrailing = nil
225+
t.actorQueuedBytes = 0
226+
}
227+
215228
func (t *Tab) clearCatchUpLocked() {
216229
if t == nil {
217230
return
@@ -396,13 +409,7 @@ func (m *Model) CleanupWorkspace(ws *data.Workspace) {
396409
tab.ptyTraceFile = nil
397410
tab.ptyTraceClosed = true
398411
}
399-
tab.pendingOutput = nil
400-
tab.pendingOutputBytes = 0
401-
tab.clearCatchUpLocked()
402-
tab.ptyBytesReceived = 0
403-
tab.ptyBytesSettled = 0
404-
tab.actorQueuedBytes = 0
405-
tab.ptyNoiseTrailing = nil
412+
tab.resetPTYStateLocked()
406413
tab.DiffViewer = nil
407414
tab.Terminal = nil
408415
tab.cachedSnap = nil

internal/ui/center/model_tabs_actions.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,7 @@ func (m *Model) closeTabAt(index int) tea.Cmd {
5656
tab.cachedSnap = nil
5757
tab.Workspace = nil
5858
tab.Running = false
59-
tab.pendingOutput = nil
60-
tab.pendingOutputBytes = 0
61-
tab.clearCatchUpLocked()
62-
tab.ptyBytesReceived = 0
63-
tab.ptyBytesSettled = 0
64-
tab.ptyNoiseTrailing = nil
65-
tab.actorQueuedBytes = 0
59+
tab.resetPTYStateLocked()
6660
tab.mu.Unlock()
6761
tab.markClosed()
6862

internal/ui/center/model_tabs_session.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,7 @@ func (m *Model) detachTab(tab *Tab, index int) tea.Cmd {
4343
tab.Running = false
4444
tab.Detached = true
4545
tab.reattachInFlight = false
46-
tab.pendingOutput = nil
47-
tab.pendingOutputBytes = 0
48-
tab.clearCatchUpLocked()
49-
tab.ptyBytesReceived = 0
50-
tab.ptyBytesSettled = 0
51-
tab.ptyNoiseTrailing = nil
52-
tab.actorQueuedBytes = 0
46+
tab.resetPTYStateLocked()
5347
if tab.Agent != nil && tab.SessionName == "" {
5448
tab.SessionName = tab.Agent.Session
5549
}

0 commit comments

Comments
 (0)