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

move getDisplayStrings funcs into contexts

This commit is contained in:
Jesse Duffield
2023-03-23 12:02:03 +11:00
parent 0c6ab4b43e
commit f081358943
11 changed files with 155 additions and 177 deletions

View File

@ -1,8 +1,11 @@
package context
import (
"github.com/jesseduffield/generics/slices"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/gui/filetree"
"github.com/jesseduffield/lazygit/pkg/gui/presentation"
"github.com/jesseduffield/lazygit/pkg/gui/style"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
@ -17,17 +20,24 @@ var (
_ types.DiffableContext = (*CommitFilesContext)(nil)
)
func NewCommitFilesContext(
getDisplayStrings func(startIdx int, length int) [][]string,
c *types.HelperCommon,
) *CommitFilesContext {
func NewCommitFilesContext(c *types.HelperCommon) *CommitFilesContext {
viewModel := filetree.NewCommitFileTreeViewModel(
func() []*models.CommitFile { return c.Model().CommitFiles },
c.Log,
c.UserConfig.Gui.ShowFileTree,
)
getDisplayStrings := func(startIdx int, length int) [][]string {
if viewModel.Len() == 0 {
return [][]string{{style.FgRed.Sprint("(none)")}}
}
lines := presentation.RenderCommitFileTree(viewModel, c.Modes().Diffing.Ref, c.Git().Patch.PatchBuilder)
return slices.Map(lines, func(line string) []string {
return []string{line}
})
}
return &CommitFilesContext{
CommitFileTreeViewModel: viewModel,
DynamicTitleBuilder: NewDynamicTitleBuilder(c.Tr.CommitFilesDynamicTitle),