summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2023-03-23 12:02:03 +1100
committerJesse Duffield <jessedduffield@gmail.com>2023-04-30 13:19:53 +1000
commitf08135894344583394240f240377015ea874b03b (patch)
tree07375df50c6b9a390a04f422e9f1a9ff60f759e6
parent0c6ab4b43e96763088c1d19039a9c4eba81a25f1 (diff)
move getDisplayStrings funcs into contexts
-rw-r--r--pkg/gui/context/commit_files_context.go20
-rw-r--r--pkg/gui/context/local_commits_context.go58
-rw-r--r--pkg/gui/context/reflog_commits_context.go18
-rw-r--r--pkg/gui/context/remote_branches_context.go7
-rw-r--r--pkg/gui/context/remotes_context.go11
-rw-r--r--pkg/gui/context/stash_context.go7
-rw-r--r--pkg/gui/context/sub_commits_context.go29
-rw-r--r--pkg/gui/context/submodules_context.go11
-rw-r--r--pkg/gui/context/tags_context.go7
-rw-r--r--pkg/gui/controllers/common.go16
-rw-r--r--pkg/gui/list_context_config.go148
11 files changed, 155 insertions, 177 deletions
diff --git a/pkg/gui/context/commit_files_context.go b/pkg/gui/context/commit_files_context.go
index f7ee4a930..80e3c52d0 100644
--- a/pkg/gui/context/commit_files_context.go
+++ b/pkg/gui/context/commit_files_context.go
@@ -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),
diff --git a/pkg/gui/context/local_commits_context.go b/pkg/gui/context/local_commits_context.go
index 4ce8f9c64..277e567ff 100644
--- a/pkg/gui/context/local_commits_context.go
+++ b/pkg/gui/context/local_commits_context.go
@@ -1,7 +1,11 @@
package context
import (
+ "log"
+
"github.com/jesseduffield/lazygit/pkg/commands/models"
+ "github.com/jesseduffield/lazygit/pkg/commands/types/enums"
+ "github.com/jesseduffield/lazygit/pkg/gui/presentation"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
@@ -15,16 +19,41 @@ var (
_ types.DiffableContext = (*LocalCommitsContext)(nil)
)
-func NewLocalCommitsContext(
- getDisplayStrings func(startIdx int, length int) [][]string,
-
- c *types.HelperCommon,
-) *LocalCommitsContext {
+func NewLocalCommitsContext(c *types.HelperCommon) *LocalCommitsContext {
viewModel := NewLocalCommitsViewModel(
func() []*models.Commit { return c.Model().Commits },
c,
)
+ getDisplayStrings := func(startIdx int, length int) [][]string {
+ selectedCommitSha := ""
+
+ if c.CurrentContext().GetKey() == LOCAL_COMMITS_CONTEXT_KEY {
+ selectedCommit := viewModel.GetSelected()
+ if selectedCommit != nil {
+ selectedCommitSha = selectedCommit.Sha
+ }
+ }
+
+ showYouAreHereLabel := c.Model().WorkingTreeStateAtLastCommitRefresh == enums.REBASE_MODE_REBASING
+
+ return presentation.GetCommitListDisplayStrings(
+ c.Common,
+ c.Model().Commits,
+ c.State().GetRepoState().GetScreenMode() != types.SCREEN_NORMAL,
+ c.Modes().CherryPicking.SelectedShaSet(),
+ c.Modes().Diffing.Ref,
+ c.UserConfig.Gui.TimeFormat,
+ c.UserConfig.Git.ParseEmoji,
+ selectedCommitSha,
+ startIdx,
+ length,
+ shouldShowGraph(c),
+ c.Model().BisectInfo,
+ showYouAreHereLabel,
+ )
+ }
+
return &LocalCommitsContext{
LocalCommitsViewModel: viewModel,
ViewportListContextTrait: &ViewportListContextTrait{
@@ -111,3 +140,22 @@ func (self *LocalCommitsViewModel) GetShowWholeGitGraph() bool {
func (self *LocalCommitsViewModel) GetCommits() []*models.Commit {
return self.getModel()
}
+
+func shouldShowGraph(c *types.HelperCommon) bool {
+ if c.Modes().Filtering.Active() {
+ return false
+ }
+
+ value := c.UserConfig.Git.Log.ShowGraph
+ switch value {
+ case "always":
+ return true
+ case "never":
+ return false
+ case "when-maximised":
+ return c.State().GetRepoState().GetScreenMode() != types.SCREEN_NORMAL
+ }
+
+ log.Fatalf("Unknown value for git.log.showGraph: %s. Expected one of: 'always', 'never', 'when-maximised'", value)
+ return false
+}
diff --git a/pkg/gui/context/reflog_commits_context.go b/pkg/gui/context/reflog_commits_context.go
index 6a50ed422..bb13038ec 100644
--- a/pkg/gui/context/reflog_commits_context.go
+++ b/pkg/gui/context/reflog_commits_context.go
@@ -2,6 +2,7 @@ package context
import (
"github.com/jesseduffield/lazygit/pkg/commands/models"
+ "github.com/jesseduffield/lazygit/pkg/gui/presentation"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
@@ -15,13 +16,20 @@ var (
_ types.DiffableContext = (*ReflogCommitsContext)(nil)
)
-func NewReflogCommitsContext(
- getDisplayStrings func(startIdx int, length int) [][]string,
-
- c *types.HelperCommon,
-) *ReflogCommitsContext {
+func NewReflogCommitsContext(c *types.HelperCommon) *ReflogCommitsContext {
viewModel := NewBasicViewModel(func() []*models.Commit { return c.Model().FilteredReflogCommits })
+ getDisplayStrings := func(startIdx int, length int) [][]string {
+ return presentation.GetReflogCommitListDisplayStrings(
+ c.Model().FilteredReflogCommits,
+ c.State().GetRepoState().GetScreenMode() != types.SCREEN_NORMAL,
+ c.Modes().CherryPicking.SelectedShaSet(),
+ c.Modes().Diffing.Ref,
+ c.UserConfig.Gui.TimeFormat,
+ c.UserConfig.Git.ParseEmoji,
+ )
+ }
+
return &ReflogCommitsContext{
BasicViewModel: viewModel,
ListContextTrait: &ListContextTrait{
diff --git a/pkg/gui/context/remote_branches_context.go b/pkg/gui/context/remote_branches_context.go
index 78a72001e..474adb2a9 100644
--- a/pkg/gui/context/remote_branches_context.go
+++ b/pkg/gui/context/remote_branches_context.go
@@ -2,6 +2,7 @@ package context
import (
"github.com/jesseduffield/lazygit/pkg/commands/models"
+ "github.com/jesseduffield/lazygit/pkg/gui/presentation"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
@@ -17,12 +18,14 @@ var (
)
func NewRemoteBranchesContext(
- getDisplayStrings func(startIdx int, length int) [][]string,
-
c *types.HelperCommon,
) *RemoteBranchesContext {
viewModel := NewBasicViewModel(func() []*models.RemoteBranch { return c.Model().RemoteBranches })
+ getDisplayStrings := func(startIdx int, length int) [][]string {
+ return presentation.GetRemoteBranchListDisplayStrings(c.Model().RemoteBranches, c.Modes().Diffing.Ref)
+ }
+
return &RemoteBranchesContext{
BasicViewModel: viewModel,
DynamicTitleBuilder: NewDynamicTitleBuilder(c.Tr.RemoteBranchesDynamicTitle),
diff --git a/pkg/gui/context/remotes_context.go b/pkg/gui/context/remotes_context.go
index 402c1bef4..a194baec8 100644
--- a/pkg/gui/context/remotes_context.go
+++ b/pkg/gui/context/remotes_context.go
@@ -2,6 +2,7 @@ package context
import (
"github.com/jesseduffield/lazygit/pkg/commands/models"
+ "github.com/jesseduffield/lazygit/pkg/gui/presentation"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
@@ -15,13 +16,13 @@ var (
_ types.DiffableContext = (*RemotesContext)(nil)
)
-func NewRemotesContext(
- getDisplayStrings func(startIdx int, length int) [][]string,
-
- c *types.HelperCommon,
-) *RemotesContext {
+func NewRemotesContext(c *types.HelperCommon) *RemotesContext {
viewModel := NewBasicViewModel(func() []*models.Remote { return c.Model().Remotes })
+ getDisplayStrings := func(startIdx int, length int) [][]string {
+ return presentation.GetRemoteListDisplayStrings(c.Model().Remotes, c.Modes().Diffing.Ref)
+ }
+
return &RemotesContext{
BasicViewModel: viewModel,
ListContextTrait: &ListContextTrait{
diff --git a/pkg/gui/context/stash_context.go b/pkg/gui/context/stash_context.go
index f9ed354b9..f56abc561 100644
--- a/pkg/gui/context/stash_context.go
+++ b/pkg/gui/context/stash_context.go
@@ -2,6 +2,7 @@ package context
import (
"github.com/jesseduffield/lazygit/pkg/commands/models"
+ "github.com/jesseduffield/lazygit/pkg/gui/presentation"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
@@ -16,12 +17,14 @@ var (
)
func NewStashContext(
- getDisplayStrings func(startIdx int, length int) [][]string,
-
c *types.HelperCommon,
) *StashContext {
viewModel := NewBasicViewModel(func() []*models.StashEntry { return c.Model().StashEntries })
+ getDisplayStrings := func(startIdx int, length int) [][]string {
+ return presentation.GetStashEntryListDisplayStrings(c.Model().StashEntries, c.Modes().Diffing.Ref)
+ }
+
return &StashContext{
BasicViewModel: viewModel,
ListContextTrait: &ListContextTrait{
diff --git a/pkg/gui/context/sub_commits_context.go b/pkg/gui/context/sub_commits_context.go
index 160d905e3..0b75b37c2 100644
--- a/pkg/gui/context/sub_commits_context.go
+++ b/pkg/gui/context/sub_commits_context.go
@@ -3,7 +3,9 @@ package context
import (
"fmt"
+ "github.com/jesseduffield/lazygit/pkg/commands/git_commands"
"github.com/jesseduffield/lazygit/pkg/commands/models"
+ "github.com/jesseduffield/lazygit/pkg/gui/presentation"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/utils"
)
@@ -20,8 +22,6 @@ var (
)
func NewSubCommitsContext(
- getDisplayStrings func(startIdx int, length int) [][]string,
-
c *types.HelperCommon,
) *SubCommitsContext {
viewModel := &SubCommitsViewModel{
@@ -32,6 +32,31 @@ func NewSubCommitsContext(
limitCommits: true,
}
+ getDisplayStrings := func(startIdx int, length int) [][]string {
+ selectedCommitSha := ""
+ if c.CurrentContext().GetKey() == SUB_COMMITS_CONTEXT_KEY {
+ selectedCommit := viewModel.GetSelected()
+ if selectedCommit != nil {
+ selectedCommitSha = selectedCommit.Sha
+ }
+ }
+ return presentation.GetCommitListDisplayStrings(
+ c.Common,
+ c.Model().SubCommits,
+ c.State().GetRepoState().GetScreenMode() != types.SCREEN_NORMAL,
+ c.Modes().CherryPicking.SelectedShaSet(),
+ c.Modes().Diffing.Ref,
+ c.UserConfig.Gui.TimeFormat,
+ c.UserConfig.Git.ParseEmoji,
+ selectedCommitSha,
+ startIdx,
+ length,
+ shouldShowGraph(c),
+ git_commands.NewNullBisectInfo(),
+ false,
+ )
+ }
+
return &SubCommitsContext{
SubCommitsViewModel: viewModel,
DynamicTitleBuilder: NewDynamicTitleBuilder(c.Tr.SubCommitsDynamicTitle),
diff --git a/pkg/gui/context/submodules_context.go b/pkg/gui/context/submodules_context.go
index 83564dfa5..5cd942284 100644
--- a/pkg/gui/context/submodules_context.go
+++ b/pkg/gui/context/submodules_context.go
@@ -2,6 +2,7 @@ package context
import (
"github.com/jesseduffield/lazygit/pkg/commands/models"
+ "github.com/jesseduffield/lazygit/pkg/gui/presentation"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
@@ -12,13 +13,13 @@ type SubmodulesContext struct {
var _ types.IListContext = (*SubmodulesContext)(nil)
-func NewSubmodulesContext(
- getDisplayStrings func(startIdx int, length int) [][]string,
-
- c *types.HelperCommon,
-) *SubmodulesContext {
+func NewSubmodulesContext(c *types.HelperCommon) *SubmodulesContext {
viewModel := NewBasicViewModel(func() []*models.SubmoduleConfig { return c.Model().Submodules })
+ getDisplayStrings := func(startIdx int, length int) [][]string {
+ return presentation.GetSubmoduleListDisplayStrings(c.Model().Submodules)
+ }
+
return &SubmodulesContext{
BasicViewModel: viewModel,
ListContextTrait: &ListContextTrait{
diff --git a/pkg/gui/context/tags_context.go b/pkg/gui/context/tags_context.go
index c71a6eef9..9722ece48 100644
--- a/pkg/gui/context/tags_context.go
+++ b/pkg/gui/context/tags_context.go
@@ -2,6 +2,7 @@ package context
import (
"github.com/jesseduffield/lazygit/pkg/commands/models"
+ "github.com/jesseduffield/lazygit/pkg/gui/presentation"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
@@ -16,12 +17,14 @@ var (
)
func NewTagsContext(
- getDisplayStrings func(startIdx int, length int) [][]string,
-
c *types.HelperCommon,
) *TagsContext {
viewModel := NewBasicViewModel(func() []*models.Tag { return c.Model().Tags })
+ getDisplayStrings := func(startIdx int, length int) [][]string {
+ return presentation.GetTagListDisplayStrings(c.Model().Tags, c.Modes().Diffing.Ref)
+ }
+
return &TagsContext{
BasicViewModel: viewModel,
ListContextTrait: &ListContextTrait{
diff --git a/pkg/gui/controllers/common.go b/pkg/gui/controllers/common.go
index 12a3788fd..f3b3011d3 100644
--- a/pkg/gui/controllers/common.go
+++ b/pkg/gui/controllers/common.go
@@ -10,13 +10,19 @@ import (
type controllerCommon struct {
c *types.HelperCommon
- os *oscommands.OSCommand
- git *commands.GitCommand
helpers *helpers.Helpers
- model *types.Model
contexts *context.ContextTree
- modes *types.Modes
- mutexes *types.Mutexes
+
+ // TODO: use helperCommon's .OS() method instead of this
+ os *oscommands.OSCommand
+ // TODO: use helperCommon's .Git() method instead of this
+ git *commands.GitCommand
+ // TODO: use helperCommon's .Model() method instead of this
+ model *types.Model
+ // TODO: use helperCommon's .Modes() method instead of this
+ modes *types.Modes
+ // TODO: use helperCommon's .Mutexes() method instead of this
+ mutexes *types.Mutexes
}
func NewControllerCommon(
diff --git a/pkg/gui/list_context_config.go b/pkg/gui/list_context_config.go
index 62ae5d180..dda2d2379 100644
--- a/pkg/gui/list_context_config.go
+++ b/pkg/gui/list_context_config.go
@@ -1,14 +1,7 @@
package gui
import (
- "log"
-
- "github.com/jesseduffield/generics/slices"
- "github.com/jesseduffield/lazygit/pkg/commands/git_commands"
- "github.com/jesseduffield/lazygit/pkg/commands/types/enums"
"github.com/jesseduffield/lazygit/pkg/gui/context"
- "github.com/jesseduffield/lazygit/pkg/gui/presentation"
- "github.com/jesseduffield/lazygit/pkg/gui/style"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
@@ -25,162 +18,39 @@ func (gui *Gui) branchesListContext() *context.BranchesContext {
}
func (gui *Gui) remotesListContext() *context.RemotesContext {
- return context.NewRemotesContext(
- func(startIdx int, length int) [][]string {
- return presentation.GetRemoteListDisplayStrings(gui.State.Model.Remotes, gui.State.Modes.Diffing.Ref)
- },
- gui.c,
- )
+ return context.NewRemotesContext(gui.c)
}
func (gui *Gui) remoteBranchesListContext() *context.RemoteBranchesContext {
- return context.NewRemoteBranchesContext(
- func(startIdx int, length int) [][]string {
- return presentation.GetRemoteBranchListDisplayStrings(gui.State.Model.RemoteBranches, gui.State.Modes.Diffing.Ref)
- },
- gui.c,
- )
+ return context.NewRemoteBranchesContext(gui.c)
}
func (gui *Gui) tagsListContext() *context.TagsContext {
- return context.NewTagsContext(
- func(startIdx int, length int) [][]string {
- return presentation.GetTagListDisplayStrings(gui.State.Model.Tags, gui.State.Modes.Diffing.Ref)
- },
- gui.c,
- )
+ return context.NewTagsContext(gui.c)
}
func (gui *Gui) branchCommitsListContext() *context.LocalCommitsContext {
- return context.NewLocalCommitsContext(
- func(startIdx int, length int) [][]string {
- selectedCommitSha := ""
- if gui.c.CurrentContext().GetKey() == context.LOCAL_COMMITS_CONTEXT_KEY {
- selectedCommit := gui.State.Contexts.LocalCommits.GetSelected()
- if selectedCommit != nil {
- selectedCommitSha = selectedCommit.Sha
- }
- }
-
- showYouAreHereLabel := gui.State.Model.WorkingTreeStateAtLastCommitRefresh == enums.REBASE_MODE_REBASING
-
- return presentation.GetCommitListDisplayStrings(
- gui.Common,
- gui.State.Model.Commits,
- gui.State.ScreenMode != types.SCREEN_NORMAL,
- gui.c.Modes().CherryPicking.SelectedShaSet(),
- gui.State.Modes.Diffing.Ref,
- gui.c.UserConfig.Gui.TimeFormat,
- gui.c.UserConfig.Git.ParseEmoji,
- selectedCommitSha,
- startIdx,
- length,
- gui.shouldShowGraph(),
- gui.State.Model.BisectInfo,
- showYouAreHereLabel,
- )
- },
- gui.c,
- )
+ return context.NewLocalCommitsContext(gui.c)
}
func (gui *Gui) subCommitsListContext() *context.SubCommitsContext {
- return context.NewSubCommitsContext(
- func(startIdx int, length int) [][]string {
- selectedCommitSha := ""
- if gui.c.CurrentContext().GetKey() == context.SUB_COMMITS_CONTEXT_KEY {
- selectedCommit := gui.State.Contexts.SubCommits.GetSelected()
- if selectedCommit != nil {
- selectedCommitSha = selectedCommit.Sha
- }
- }
- return presentation.GetCommitListDisplayStrings(
- gui.Common,
- gui.State.Model.SubCommits,
- gui.State.ScreenMode != types.SCREEN_NORMAL,
- gui.c.Modes().CherryPicking.SelectedShaSet(),
- gui.State.Modes.Diffing.Ref,
- gui.c.UserConfig.Gui.TimeFormat,
- gui.c.UserConfig.Git.ParseEmoji,
- selectedCommitSha,
- startIdx,
- length,
- gui.shouldShowGraph(),
- git_commands.NewNullBisectInfo(),
- false,
- )
- },
- gui.c,
- )
-}
-
-func (gui *Gui) shouldShowGraph() bool {
- if gui.State.Modes.Filtering.Active() {
- return false
- }
-
- value := gui.c.UserConfig.Git.Log.ShowGraph
- switch value {
- case "always":
- return true
- case "never":
- return false
- case "when-maximised":
- return gui.State.ScreenMode != types.SCREEN_NORMAL
- }
-
- log.Fatalf("Unknown value for git.log.showGraph: %s. Expected one of: 'always', 'never', 'when-maximised'", value)
- return false
+ return context.NewSubCommitsContext(gui.c)
}
func (gui *Gui) reflogCommitsListContext() *context.ReflogCommitsContext {
- return context.NewReflogCommitsContext(
- func(startIdx int, length int) [][]string {
- return presentation.GetReflogCommitListDisplayStrings(
- gui.State.Model.FilteredReflogCommits,
- gui.State.ScreenMode != types.SCREEN_NORMAL,
- gui.c.Modes().CherryPicking.SelectedShaSet(),
- gui.State.Modes.Diffing.Ref,
- gui.c.UserConfig.Gui.TimeFormat,
- gui.c.UserConfig.Git.ParseEmoji,
- )
- },
- gui.c,
- )
+ return context.NewReflogCommitsContext(gui.c)
}
func (gui *Gui) stashListContext() *context.StashContext {
- return context.NewStashContext(
- func(startIdx int, length int) [][]string {
- return presentation.GetStashEntryListDisplayStrings(gui.State.Model.StashEntries, gui.State.Modes.Diffing.Ref)
- },
- gui.c,
- )
+ return context.NewStashContext(gui.c)
}
func (gui *Gui) commitFilesListContext() *context.CommitFilesContext {
- return context.NewCommitFilesContext(
- func(startIdx int, length int) [][]string {
- if gui.State.Contexts.CommitFiles.CommitFileTreeViewModel.Len() == 0 {
- return [][]string{{style.FgRed.Sprint("(none)")}}
- }
-
- lines := presentation.RenderCommitFileTree(gui.State.Contexts.CommitFiles.CommitFileTreeViewModel, gui.State.Modes.Diffing.Ref, gui.git.Patch.PatchBuilder)
- return slices.Map(lines, func(line string) []string {
- return []string{line}
- })
- },
- gui.c,
- )
+ return context.NewCommitFilesContext(gui.c)
}
func (gui *Gui) submodulesListContext() *context.SubmodulesContext {
- return context.NewSubmodulesContext(
- func(startIdx int, length int) [][]string {
- return presentation.GetSubmoduleListDisplayStrings(gui.State.Model.Submodules)
- },
- gui.c,
- )
+ return context.NewSubmodulesContext(gui.c)
}
func (gui *Gui) suggestionsListContext() *context.SuggestionsContext {