From 81c27b2ff8183a92fdb5a3fc91121b27988f43bd Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sun, 6 Sep 2026 14:40:12 +0200 Subject: [PATCH] Separate reading a fixed number of lines from reading to the end ReadToEnd holds a gocui task while it reads, so that lazygit doesn't count as idle while something waits on the result. That has nothing to do with reading all the way to the end, and the next commit needs it for a bounded read too, so the two are pulled apart. Co-authored-by: Claude Opus 5 (1M context) --- pkg/tasks/tasks.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pkg/tasks/tasks.go b/pkg/tasks/tasks.go index deaeee042..f9b309c3d 100644 --- a/pkg/tasks/tasks.go +++ b/pkg/tasks/tasks.go @@ -212,8 +212,13 @@ func (self *ViewBufferManager) StartLoading() { } func (self *ViewBufferManager) ReadToEnd(then func()) { - // The reading happens on the task's own goroutine, and the caller hears about - // it through then, so lazygit must not count as idle in between. + self.readHoldingATask(-1, then) +} + +// readHoldingATask asks the task to have read totalLines lines in total (-1 for all of +// them) and calls then once it has. The reading happens on the task's own goroutine and +// the caller is waiting on the result, so lazygit must not count as idle in between. +func (self *ViewBufferManager) readHoldingATask(totalLines int, then func()) { task := self.newGocuiTask() answered := func() { task.Done() @@ -222,7 +227,7 @@ func (self *ViewBufferManager) ReadToEnd(then func()) { } } - request := LinesToRead{Total: -1, InitialRefreshAfter: -1, Then: answered} + request := LinesToRead{Total: totalLines, InitialRefreshAfter: -1, Then: answered} if !self.readRequests.enqueue(request) { // With no task reading, everything there is to read has been read. answered()