1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-30 03:23:08 +03:00

Use an interface for tasks instead of a concrete struct

By using an interface for tasks we can use a fake implementation in tests with extra methods
This commit is contained in:
Jesse Duffield
2023-07-09 21:09:52 +10:00
parent 8964cedf27
commit 6b9390409e
45 changed files with 333 additions and 222 deletions

View File

@ -50,7 +50,10 @@ type ViewBufferManager struct {
onEndOfInput func()
// see docs/dev/Busy.md
newTask func() *gocui.Task
// A gocui task is not the same thing as the tasks defined in this file.
// A gocui task simply represents the fact that lazygit is busy doing something,
// whereas the tasks in this file are about rendering content to a view.
newGocuiTask func() gocui.Task
// if the user flicks through a heap of items, with each one
// spawning a process to render something to the main view,
@ -80,7 +83,7 @@ func NewViewBufferManager(
refreshView func(),
onEndOfInput func(),
onNewKey func(),
newTask func() *gocui.Task,
newGocuiTask func() gocui.Task,
) *ViewBufferManager {
return &ViewBufferManager{
Log: log,
@ -90,7 +93,7 @@ func NewViewBufferManager(
onEndOfInput: onEndOfInput,
readLines: make(chan LinesToRead, 1024),
onNewKey: onNewKey,
newTask: newTask,
newGocuiTask: newGocuiTask,
}
}
@ -296,7 +299,7 @@ type TaskOpts struct {
}
func (self *ViewBufferManager) NewTask(f func(TaskOpts) error, key string) error {
task := self.newTask()
task := self.newGocuiTask()
var completeTaskOnce sync.Once