/
githubmirror
/
lazygit
Обзор
Документация
Войти
/
githubmirror
/
lazygit
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
pkg/gocui/task.go
114 строк
2 KB
Stefan Haller
Exclude view-buffer render tasks from the busy query
07 июл 2026, 19:09
07 июл 2026, 19:09
8655d3f
Код
Авторство
О чём код?
package gocui // A task represents the fact that the program is busy doing something, which // is useful for integration tests which only want to proceed when the program // is idle. type Task interface { Done() Pause() Continue() // not exporting these because we don't need to isBusy() bool isBackground() bool } type TaskImpl struct { id int busy bool onDone func() withMutex func(func()) // Background tasks don't count towards the program being "busy" for the // purpose of deciding whether a repo switch is safe (see // TaskManager.hasBusyForegroundTaskExcept). Two kinds of work are tagged // this way: the ongoing background routines (auto-fetch, files refresh, // external-change detection) and the refreshes they trigger, whose model // writes are already guarded against a concurrent repo switch by the repo // generation; and view-buffer content rendering, which only paints a view // and so is harmless to leave running across a switch. What stays // foreground is lazygit driving a git operation and applying its results // to the model — exactly the work a repo switch must not run underneath. background bool } func (self *TaskImpl) Done() { self.onDone() } func (self *TaskImpl) Pause() { self.withMutex(func() { self.busy = false }) } func (self *TaskImpl) Continue() { self.withMutex(func() { self.busy = true }) } func (self *TaskImpl) isBusy() bool { return self.busy } func (self *TaskImpl) isBackground() bool { return self.background } type TaskStatus int const ( TaskStatusBusy TaskStatus = iota TaskStatusPaused TaskStatusDone ) type FakeTask struct { status TaskStatus } func NewFakeTask() *FakeTask { return &FakeTask{ status: TaskStatusBusy, } } func (self *FakeTask) Done() { self.status = TaskStatusDone } func (self *FakeTask) Pause() { self.status = TaskStatusPaused } func (self *FakeTask) Continue() { self.status = TaskStatusBusy } func (self *FakeTask) isBusy() bool { return self.status == TaskStatusBusy } func (self *FakeTask) isBackground() bool { return false } func (self *FakeTask) Status() TaskStatus { return self.status } func (self *FakeTask) FormatStatus() string { return formatTaskStatus(self.status) } func formatTaskStatus(status TaskStatus) string { switch status { case TaskStatusBusy: return "busy" case TaskStatusPaused: return "paused" case TaskStatusDone: return "done" } return "unknown" }