mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-30 03:23:08 +03:00
Extract a ListRenderer struct
I'm doing this not so much because it's a great abstraction, but just because it will make it much easier to write tests for it.
This commit is contained in:
27
pkg/gui/context/list_renderer.go
Normal file
27
pkg/gui/context/list_renderer.go
Normal file
@ -0,0 +1,27 @@
|
||||
package context
|
||||
|
||||
import (
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||
)
|
||||
|
||||
type ListRenderer struct {
|
||||
list types.IList
|
||||
getDisplayStrings func(startIdx int, endIdx int) [][]string
|
||||
// Alignment for each column. If nil, the default is left alignment
|
||||
getColumnAlignments func() []utils.Alignment
|
||||
}
|
||||
|
||||
func (self *ListRenderer) GetList() types.IList {
|
||||
return self.list
|
||||
}
|
||||
|
||||
func (self *ListRenderer) renderLines(startIdx int, endIdx int) string {
|
||||
var columnAlignments []utils.Alignment
|
||||
if self.getColumnAlignments != nil {
|
||||
columnAlignments = self.getColumnAlignments()
|
||||
}
|
||||
return utils.RenderDisplayStrings(
|
||||
self.getDisplayStrings(startIdx, utils.Min(endIdx, self.list.Len())),
|
||||
columnAlignments)
|
||||
}
|
Reference in New Issue
Block a user