mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-10-05 21:46:49 -04:00
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) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
108b2c5aa3
commit
4ced072911
+10
-5
@@ -212,10 +212,15 @@ 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. The task is
|
||||
// done only once then has returned, because then typically hands its work to
|
||||
// the UI thread, and that work counts as busy only once it is enqueued.
|
||||
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.
|
||||
// The task is done only once then has returned, because then typically hands its work
|
||||
// to the UI thread, and that work counts as busy only once it is enqueued.
|
||||
func (self *ViewBufferManager) readHoldingATask(totalLines int, then func()) {
|
||||
task := self.newGocuiTask()
|
||||
answered := func() {
|
||||
if then != nil {
|
||||
@@ -224,7 +229,7 @@ func (self *ViewBufferManager) ReadToEnd(then func()) {
|
||||
task.Done()
|
||||
}
|
||||
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user