mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-03-05 15:15:49 +02:00
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.
28 lines
765 B
Go
28 lines
765 B
Go
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)
|
|
}
|