1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-06-02 23:27:32 +02:00

rename displayString to label for menu items

This commit is contained in:
Jesse Duffield 2022-05-08 14:23:32 +10:00
parent 125e948d82
commit 6f8063217d
23 changed files with 126 additions and 122 deletions

View File

@ -58,7 +58,7 @@ func (self *MenuContext) GetSelectedItemId() string {
return "" return ""
} }
return item.DisplayString return item.Label
} }
type MenuViewModel struct { type MenuViewModel struct {
@ -96,11 +96,11 @@ func (self *MenuViewModel) GetDisplayStrings(_startIdx int, _length int) [][]str
} }
func getItemDisplayStrings(item *types.MenuItem) []string { func getItemDisplayStrings(item *types.MenuItem) []string {
if item.DisplayStrings != nil { if item.LabelColumns != nil {
return item.DisplayStrings return item.LabelColumns
} }
styledStr := item.DisplayString styledStr := item.Label
if item.OpensMenu { if item.OpensMenu {
styledStr = presentation.OpensMenuStyle(styledStr) styledStr = presentation.OpensMenuStyle(styledStr)
} }

View File

@ -101,35 +101,35 @@ func (self *BasicCommitsController) copyCommitAttribute(commit *models.Commit) e
Title: self.c.Tr.Actions.CopyCommitAttributeToClipboard, Title: self.c.Tr.Actions.CopyCommitAttributeToClipboard,
Items: []*types.MenuItem{ Items: []*types.MenuItem{
{ {
DisplayString: self.c.Tr.LcCommitSha, Label: self.c.Tr.LcCommitSha,
OnPress: func() error { OnPress: func() error {
return self.copyCommitSHAToClipboard(commit) return self.copyCommitSHAToClipboard(commit)
}, },
Key: 's', Key: 's',
}, },
{ {
DisplayString: self.c.Tr.LcCommitURL, Label: self.c.Tr.LcCommitURL,
OnPress: func() error { OnPress: func() error {
return self.copyCommitURLToClipboard(commit) return self.copyCommitURLToClipboard(commit)
}, },
Key: 'u', Key: 'u',
}, },
{ {
DisplayString: self.c.Tr.LcCommitDiff, Label: self.c.Tr.LcCommitDiff,
OnPress: func() error { OnPress: func() error {
return self.copyCommitDiffToClipboard(commit) return self.copyCommitDiffToClipboard(commit)
}, },
Key: 'd', Key: 'd',
}, },
{ {
DisplayString: self.c.Tr.LcCommitMessage, Label: self.c.Tr.LcCommitMessage,
OnPress: func() error { OnPress: func() error {
return self.copyCommitMessageToClipboard(commit) return self.copyCommitMessageToClipboard(commit)
}, },
Key: 'm', Key: 'm',
}, },
{ {
DisplayString: self.c.Tr.LcCommitAuthor, Label: self.c.Tr.LcCommitAuthor,
OnPress: func() error { OnPress: func() error {
return self.copyAuthorToClipboard(commit) return self.copyAuthorToClipboard(commit)
}, },

View File

@ -67,7 +67,7 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c
menuItems := []*types.MenuItem{ menuItems := []*types.MenuItem{
{ {
DisplayString: fmt.Sprintf(self.c.Tr.Bisect.Mark, commit.ShortSha(), info.NewTerm()), Label: fmt.Sprintf(self.c.Tr.Bisect.Mark, commit.ShortSha(), info.NewTerm()),
OnPress: func() error { OnPress: func() error {
self.c.LogAction(self.c.Tr.Actions.BisectMark) self.c.LogAction(self.c.Tr.Actions.BisectMark)
if err := self.git.Bisect.Mark(commit.Sha, info.NewTerm()); err != nil { if err := self.git.Bisect.Mark(commit.Sha, info.NewTerm()); err != nil {
@ -79,7 +79,7 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c
Key: 'b', Key: 'b',
}, },
{ {
DisplayString: fmt.Sprintf(self.c.Tr.Bisect.Mark, commit.ShortSha(), info.OldTerm()), Label: fmt.Sprintf(self.c.Tr.Bisect.Mark, commit.ShortSha(), info.OldTerm()),
OnPress: func() error { OnPress: func() error {
self.c.LogAction(self.c.Tr.Actions.BisectMark) self.c.LogAction(self.c.Tr.Actions.BisectMark)
if err := self.git.Bisect.Mark(commit.Sha, info.OldTerm()); err != nil { if err := self.git.Bisect.Mark(commit.Sha, info.OldTerm()); err != nil {
@ -91,7 +91,7 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c
Key: 'g', Key: 'g',
}, },
{ {
DisplayString: fmt.Sprintf(self.c.Tr.Bisect.Skip, commit.ShortSha()), Label: fmt.Sprintf(self.c.Tr.Bisect.Skip, commit.ShortSha()),
OnPress: func() error { OnPress: func() error {
self.c.LogAction(self.c.Tr.Actions.BisectSkip) self.c.LogAction(self.c.Tr.Actions.BisectSkip)
if err := self.git.Bisect.Skip(commit.Sha); err != nil { if err := self.git.Bisect.Skip(commit.Sha); err != nil {
@ -103,7 +103,7 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c
Key: 's', Key: 's',
}, },
{ {
DisplayString: self.c.Tr.Bisect.ResetOption, Label: self.c.Tr.Bisect.ResetOption,
OnPress: func() error { OnPress: func() error {
return self.helpers.Bisect.Reset() return self.helpers.Bisect.Reset()
}, },
@ -122,7 +122,7 @@ func (self *BisectController) openStartBisectMenu(info *git_commands.BisectInfo,
Title: self.c.Tr.Bisect.BisectMenuTitle, Title: self.c.Tr.Bisect.BisectMenuTitle,
Items: []*types.MenuItem{ Items: []*types.MenuItem{
{ {
DisplayString: fmt.Sprintf(self.c.Tr.Bisect.MarkStart, commit.ShortSha(), info.NewTerm()), Label: fmt.Sprintf(self.c.Tr.Bisect.MarkStart, commit.ShortSha(), info.NewTerm()),
OnPress: func() error { OnPress: func() error {
self.c.LogAction(self.c.Tr.Actions.StartBisect) self.c.LogAction(self.c.Tr.Actions.StartBisect)
if err := self.git.Bisect.Start(); err != nil { if err := self.git.Bisect.Start(); err != nil {
@ -138,7 +138,7 @@ func (self *BisectController) openStartBisectMenu(info *git_commands.BisectInfo,
Key: 'b', Key: 'b',
}, },
{ {
DisplayString: fmt.Sprintf(self.c.Tr.Bisect.MarkStart, commit.ShortSha(), info.OldTerm()), Label: fmt.Sprintf(self.c.Tr.Bisect.MarkStart, commit.ShortSha(), info.OldTerm()),
OnPress: func() error { OnPress: func() error {
self.c.LogAction(self.c.Tr.Actions.StartBisect) self.c.LogAction(self.c.Tr.Actions.StartBisect)
if err := self.git.Bisect.Start(); err != nil { if err := self.git.Bisect.Start(); err != nil {

View File

@ -111,7 +111,7 @@ func (self *BranchesController) setUpstream(selectedBranch *models.Branch) error
Title: self.c.Tr.Actions.SetUnsetUpstream, Title: self.c.Tr.Actions.SetUnsetUpstream,
Items: []*types.MenuItem{ Items: []*types.MenuItem{
{ {
DisplayStrings: []string{self.c.Tr.LcUnsetUpstream}, LabelColumns: []string{self.c.Tr.LcUnsetUpstream},
OnPress: func() error { OnPress: func() error {
if err := self.git.Branch.UnsetUpstream(selectedBranch.Name); err != nil { if err := self.git.Branch.UnsetUpstream(selectedBranch.Name); err != nil {
return self.c.Error(err) return self.c.Error(err)
@ -130,7 +130,7 @@ func (self *BranchesController) setUpstream(selectedBranch *models.Branch) error
Key: 'u', Key: 'u',
}, },
{ {
DisplayStrings: []string{self.c.Tr.LcSetUpstream}, LabelColumns: []string{self.c.Tr.LcSetUpstream},
OnPress: func() error { OnPress: func() error {
return self.helpers.Upstream.PromptForUpstreamWithoutInitialContent(selectedBranch, func(upstream string) error { return self.helpers.Upstream.PromptForUpstreamWithoutInitialContent(selectedBranch, func(upstream string) error {
upstreamRemote, upstreamBranch, err := self.helpers.Upstream.ParseUpstream(upstream) upstreamRemote, upstreamBranch, err := self.helpers.Upstream.ParseUpstream(upstream)
@ -417,20 +417,20 @@ func (self *BranchesController) newBranch(selectedBranch *models.Branch) error {
func (self *BranchesController) createPullRequestMenu(selectedBranch *models.Branch, checkedOutBranch *models.Branch) error { func (self *BranchesController) createPullRequestMenu(selectedBranch *models.Branch, checkedOutBranch *models.Branch) error {
menuItems := make([]*types.MenuItem, 0, 4) menuItems := make([]*types.MenuItem, 0, 4)
fromToDisplayStrings := func(from string, to string) []string { fromToLabelColumns := func(from string, to string) []string {
return []string{fmt.Sprintf("%s → %s", from, to)} return []string{fmt.Sprintf("%s → %s", from, to)}
} }
menuItemsForBranch := func(branch *models.Branch) []*types.MenuItem { menuItemsForBranch := func(branch *models.Branch) []*types.MenuItem {
return []*types.MenuItem{ return []*types.MenuItem{
{ {
DisplayStrings: fromToDisplayStrings(branch.Name, self.c.Tr.LcDefaultBranch), LabelColumns: fromToLabelColumns(branch.Name, self.c.Tr.LcDefaultBranch),
OnPress: func() error { OnPress: func() error {
return self.createPullRequest(branch.Name, "") return self.createPullRequest(branch.Name, "")
}, },
}, },
{ {
DisplayStrings: fromToDisplayStrings(branch.Name, self.c.Tr.LcSelectBranch), LabelColumns: fromToLabelColumns(branch.Name, self.c.Tr.LcSelectBranch),
OnPress: func() error { OnPress: func() error {
return self.c.Prompt(types.PromptOpts{ return self.c.Prompt(types.PromptOpts{
Title: branch.Name + " →", Title: branch.Name + " →",
@ -447,7 +447,7 @@ func (self *BranchesController) createPullRequestMenu(selectedBranch *models.Bra
if selectedBranch != checkedOutBranch { if selectedBranch != checkedOutBranch {
menuItems = append(menuItems, menuItems = append(menuItems,
&types.MenuItem{ &types.MenuItem{
DisplayStrings: fromToDisplayStrings(checkedOutBranch.Name, selectedBranch.Name), LabelColumns: fromToLabelColumns(checkedOutBranch.Name, selectedBranch.Name),
OnPress: func() error { OnPress: func() error {
return self.createPullRequest(checkedOutBranch.Name, selectedBranch.Name) return self.createPullRequest(checkedOutBranch.Name, selectedBranch.Name)
}, },

View File

@ -500,19 +500,19 @@ func (self *FilesController) handleStatusFilterPressed() error {
Title: self.c.Tr.FilteringMenuTitle, Title: self.c.Tr.FilteringMenuTitle,
Items: []*types.MenuItem{ Items: []*types.MenuItem{
{ {
DisplayString: self.c.Tr.FilterStagedFiles, Label: self.c.Tr.FilterStagedFiles,
OnPress: func() error { OnPress: func() error {
return self.setStatusFiltering(filetree.DisplayStaged) return self.setStatusFiltering(filetree.DisplayStaged)
}, },
}, },
{ {
DisplayString: self.c.Tr.FilterUnstagedFiles, Label: self.c.Tr.FilterUnstagedFiles,
OnPress: func() error { OnPress: func() error {
return self.setStatusFiltering(filetree.DisplayUnstaged) return self.setStatusFiltering(filetree.DisplayUnstaged)
}, },
}, },
{ {
DisplayString: self.c.Tr.ResetCommitFilterState, Label: self.c.Tr.ResetCommitFilterState,
OnPress: func() error { OnPress: func() error {
return self.setStatusFiltering(filetree.DisplayAll) return self.setStatusFiltering(filetree.DisplayAll)
}, },
@ -557,14 +557,14 @@ func (self *FilesController) createStashMenu() error {
Title: self.c.Tr.LcStashOptions, Title: self.c.Tr.LcStashOptions,
Items: []*types.MenuItem{ Items: []*types.MenuItem{
{ {
DisplayString: self.c.Tr.LcStashAllChanges, Label: self.c.Tr.LcStashAllChanges,
OnPress: func() error { OnPress: func() error {
return self.handleStashSave(self.git.Stash.Save, self.c.Tr.Actions.StashAllChanges, self.c.Tr.NoFilesToStash) return self.handleStashSave(self.git.Stash.Save, self.c.Tr.Actions.StashAllChanges, self.c.Tr.NoFilesToStash)
}, },
Key: 'a', Key: 'a',
}, },
{ {
DisplayString: self.c.Tr.LcStashAllChangesKeepIndex, Label: self.c.Tr.LcStashAllChangesKeepIndex,
OnPress: func() error { OnPress: func() error {
// if there are no staged files it behaves the same as Stash.Save // if there are no staged files it behaves the same as Stash.Save
return self.handleStashSave(self.git.Stash.StashAndKeepIndex, self.c.Tr.Actions.StashAllChangesKeepIndex, self.c.Tr.NoFilesToStash) return self.handleStashSave(self.git.Stash.StashAndKeepIndex, self.c.Tr.Actions.StashAllChangesKeepIndex, self.c.Tr.NoFilesToStash)
@ -572,7 +572,7 @@ func (self *FilesController) createStashMenu() error {
Key: 'i', Key: 'i',
}, },
{ {
DisplayString: self.c.Tr.LcStashStagedChanges, Label: self.c.Tr.LcStashStagedChanges,
OnPress: func() error { OnPress: func() error {
// there must be something in staging otherwise the current implementation mucks the stash up // there must be something in staging otherwise the current implementation mucks the stash up
if !self.helpers.WorkingTree.AnyStagedFiles() { if !self.helpers.WorkingTree.AnyStagedFiles() {
@ -583,7 +583,7 @@ func (self *FilesController) createStashMenu() error {
Key: 's', Key: 's',
}, },
{ {
DisplayString: self.c.Tr.LcStashUnstagedChanges, Label: self.c.Tr.LcStashUnstagedChanges,
OnPress: func() error { OnPress: func() error {
if self.helpers.WorkingTree.AnyStagedFiles() { if self.helpers.WorkingTree.AnyStagedFiles() {
return self.handleStashSave(self.git.Stash.StashUnstagedChanges, self.c.Tr.Actions.StashUnstagedChanges, self.c.Tr.NoFilesToStash) return self.handleStashSave(self.git.Stash.StashUnstagedChanges, self.c.Tr.Actions.StashUnstagedChanges, self.c.Tr.NoFilesToStash)

View File

@ -43,7 +43,7 @@ func (self *FilesRemoveController) remove(node *filetree.FileNode) error {
if node.File == nil { if node.File == nil {
menuItems = []*types.MenuItem{ menuItems = []*types.MenuItem{
{ {
DisplayString: self.c.Tr.LcDiscardAllChanges, Label: self.c.Tr.LcDiscardAllChanges,
OnPress: func() error { OnPress: func() error {
self.c.LogAction(self.c.Tr.Actions.DiscardAllChangesInDirectory) self.c.LogAction(self.c.Tr.Actions.DiscardAllChangesInDirectory)
if err := self.git.WorkingTree.DiscardAllDirChanges(node); err != nil { if err := self.git.WorkingTree.DiscardAllDirChanges(node); err != nil {
@ -57,7 +57,7 @@ func (self *FilesRemoveController) remove(node *filetree.FileNode) error {
if node.GetHasStagedChanges() && node.GetHasUnstagedChanges() { if node.GetHasStagedChanges() && node.GetHasUnstagedChanges() {
menuItems = append(menuItems, &types.MenuItem{ menuItems = append(menuItems, &types.MenuItem{
DisplayString: self.c.Tr.LcDiscardUnstagedChanges, Label: self.c.Tr.LcDiscardUnstagedChanges,
OnPress: func() error { OnPress: func() error {
self.c.LogAction(self.c.Tr.Actions.DiscardUnstagedChangesInDirectory) self.c.LogAction(self.c.Tr.Actions.DiscardUnstagedChangesInDirectory)
if err := self.git.WorkingTree.DiscardUnstagedDirChanges(node); err != nil { if err := self.git.WorkingTree.DiscardUnstagedDirChanges(node); err != nil {
@ -78,7 +78,7 @@ func (self *FilesRemoveController) remove(node *filetree.FileNode) error {
menuItems = []*types.MenuItem{ menuItems = []*types.MenuItem{
{ {
DisplayString: self.c.Tr.LcSubmoduleStashAndReset, Label: self.c.Tr.LcSubmoduleStashAndReset,
OnPress: func() error { OnPress: func() error {
return self.ResetSubmodule(submodule) return self.ResetSubmodule(submodule)
}, },
@ -87,7 +87,7 @@ func (self *FilesRemoveController) remove(node *filetree.FileNode) error {
} else { } else {
menuItems = []*types.MenuItem{ menuItems = []*types.MenuItem{
{ {
DisplayString: self.c.Tr.LcDiscardAllChanges, Label: self.c.Tr.LcDiscardAllChanges,
OnPress: func() error { OnPress: func() error {
self.c.LogAction(self.c.Tr.Actions.DiscardAllChangesInFile) self.c.LogAction(self.c.Tr.Actions.DiscardAllChangesInFile)
if err := self.git.WorkingTree.DiscardAllFileChanges(file); err != nil { if err := self.git.WorkingTree.DiscardAllFileChanges(file); err != nil {
@ -101,7 +101,7 @@ func (self *FilesRemoveController) remove(node *filetree.FileNode) error {
if file.HasStagedChanges && file.HasUnstagedChanges { if file.HasStagedChanges && file.HasUnstagedChanges {
menuItems = append(menuItems, &types.MenuItem{ menuItems = append(menuItems, &types.MenuItem{
DisplayString: self.c.Tr.LcDiscardUnstagedChanges, Label: self.c.Tr.LcDiscardUnstagedChanges,
OnPress: func() error { OnPress: func() error {
self.c.LogAction(self.c.Tr.Actions.DiscardAllUnstagedChangesInFile) self.c.LogAction(self.c.Tr.Actions.DiscardAllUnstagedChangesInFile)
if err := self.git.WorkingTree.DiscardUnstagedFileChanges(file); err != nil { if err := self.git.WorkingTree.DiscardUnstagedFileChanges(file); err != nil {

View File

@ -64,30 +64,30 @@ func (self *GitFlowController) handleCreateGitFlowMenu(branch *models.Branch) er
Items: []*types.MenuItem{ Items: []*types.MenuItem{
{ {
// not localising here because it's one to one with the actual git flow commands // not localising here because it's one to one with the actual git flow commands
DisplayString: fmt.Sprintf("finish branch '%s'", branch.Name), Label: fmt.Sprintf("finish branch '%s'", branch.Name),
OnPress: func() error { OnPress: func() error {
return self.gitFlowFinishBranch(branch.Name) return self.gitFlowFinishBranch(branch.Name)
}, },
}, },
{ {
DisplayString: "start feature", Label: "start feature",
OnPress: startHandler("feature"), OnPress: startHandler("feature"),
Key: 'f', Key: 'f',
}, },
{ {
DisplayString: "start hotfix", Label: "start hotfix",
OnPress: startHandler("hotfix"), OnPress: startHandler("hotfix"),
Key: 'h', Key: 'h',
}, },
{ {
DisplayString: "start bugfix", Label: "start bugfix",
OnPress: startHandler("bugfix"), OnPress: startHandler("bugfix"),
Key: 'b', Key: 'b',
}, },
{ {
DisplayString: "start release", Label: "start release",
OnPress: startHandler("release"), OnPress: startHandler("release"),
Key: 'r', Key: 'r',
}, },
}, },
}) })

View File

@ -64,7 +64,7 @@ func (self *MergeAndRebaseHelper) CreateRebaseOptionsMenu() error {
menuItems := slices.Map(options, func(row optionAndKey) *types.MenuItem { menuItems := slices.Map(options, func(row optionAndKey) *types.MenuItem {
return &types.MenuItem{ return &types.MenuItem{
DisplayString: row.option, Label: row.option,
OnPress: func() error { OnPress: func() error {
return self.genericMergeCommand(row.option) return self.genericMergeCommand(row.option)
}, },

View File

@ -146,7 +146,7 @@ func (self *RefsHelper) CreateGitResetMenu(ref string) error {
menuItems := slices.Map(strengths, func(row strengthWithKey) *types.MenuItem { menuItems := slices.Map(strengths, func(row strengthWithKey) *types.MenuItem {
return &types.MenuItem{ return &types.MenuItem{
DisplayStrings: []string{ LabelColumns: []string{
fmt.Sprintf("%s reset", row.strength), fmt.Sprintf("%s reset", row.strength),
style.FgRed.Sprintf("reset --%s %s", row.strength, ref), style.FgRed.Sprintf("reset --%s %s", row.strength, ref),
}, },

View File

@ -26,13 +26,13 @@ func (self *TagsHelper) CreateTagMenu(commitSha string, onCreate func()) error {
Title: self.c.Tr.TagMenuTitle, Title: self.c.Tr.TagMenuTitle,
Items: []*types.MenuItem{ Items: []*types.MenuItem{
{ {
DisplayString: self.c.Tr.LcLightweightTag, Label: self.c.Tr.LcLightweightTag,
OnPress: func() error { OnPress: func() error {
return self.handleCreateLightweightTag(commitSha, onCreate) return self.handleCreateLightweightTag(commitSha, onCreate)
}, },
}, },
{ {
DisplayString: self.c.Tr.LcAnnotatedTag, Label: self.c.Tr.LcAnnotatedTag,
OnPress: func() error { OnPress: func() error {
return self.handleCreateAnnotatedTag(commitSha, onCreate) return self.handleCreateAnnotatedTag(commitSha, onCreate)
}, },

View File

@ -470,7 +470,7 @@ func (self *LocalCommitsController) createRevertMergeCommitMenu(commit *models.C
} }
menuItems[i] = &types.MenuItem{ menuItems[i] = &types.MenuItem{
DisplayString: fmt.Sprintf("%s: %s", utils.SafeTruncate(parentSha, 8), message), Label: fmt.Sprintf("%s: %s", utils.SafeTruncate(parentSha, 8), message),
OnPress: func() error { OnPress: func() error {
parentNumber := i + 1 parentNumber := i + 1
self.c.LogAction(self.c.Tr.Actions.RevertCommit) self.c.LogAction(self.c.Tr.Actions.RevertCommit)
@ -570,7 +570,7 @@ func (self *LocalCommitsController) handleOpenLogMenu() error {
Title: self.c.Tr.LogMenuTitle, Title: self.c.Tr.LogMenuTitle,
Items: []*types.MenuItem{ Items: []*types.MenuItem{
{ {
DisplayString: self.c.Tr.ToggleShowGitGraphAll, Label: self.c.Tr.ToggleShowGitGraphAll,
OnPress: func() error { OnPress: func() error {
self.context().SetShowWholeGitGraph(!self.context().GetShowWholeGitGraph()) self.context().SetShowWholeGitGraph(!self.context().GetShowWholeGitGraph())
@ -586,8 +586,8 @@ func (self *LocalCommitsController) handleOpenLogMenu() error {
}, },
}, },
{ {
DisplayString: self.c.Tr.ShowGitGraph, Label: self.c.Tr.ShowGitGraph,
OpensMenu: true, OpensMenu: true,
OnPress: func() error { OnPress: func() error {
onPress := func(value string) func() error { onPress := func(value string) func() error {
return func() error { return func() error {
@ -599,24 +599,24 @@ func (self *LocalCommitsController) handleOpenLogMenu() error {
Title: self.c.Tr.LogMenuTitle, Title: self.c.Tr.LogMenuTitle,
Items: []*types.MenuItem{ Items: []*types.MenuItem{
{ {
DisplayString: "always", Label: "always",
OnPress: onPress("always"), OnPress: onPress("always"),
}, },
{ {
DisplayString: "never", Label: "never",
OnPress: onPress("never"), OnPress: onPress("never"),
}, },
{ {
DisplayString: "when maximised", Label: "when maximised",
OnPress: onPress("when-maximised"), OnPress: onPress("when-maximised"),
}, },
}, },
}) })
}, },
}, },
{ {
DisplayString: self.c.Tr.SortCommits, Label: self.c.Tr.SortCommits,
OpensMenu: true, OpensMenu: true,
OnPress: func() error { OnPress: func() error {
onPress := func(value string) func() error { onPress := func(value string) func() error {
return func() error { return func() error {
@ -636,16 +636,16 @@ func (self *LocalCommitsController) handleOpenLogMenu() error {
Title: self.c.Tr.LogMenuTitle, Title: self.c.Tr.LogMenuTitle,
Items: []*types.MenuItem{ Items: []*types.MenuItem{
{ {
DisplayString: "topological (topo-order)", Label: "topological (topo-order)",
OnPress: onPress("topo-order"), OnPress: onPress("topo-order"),
}, },
{ {
DisplayString: "date-order", Label: "date-order",
OnPress: onPress("date-order"), OnPress: onPress("date-order"),
}, },
{ {
DisplayString: "author-date-order", Label: "author-date-order",
OnPress: onPress("author-date-order"), OnPress: onPress("author-date-order"),
}, },
}, },
}) })

View File

@ -146,7 +146,7 @@ func (self *SubmodulesController) openBulkActionsMenu() error {
Title: self.c.Tr.LcBulkSubmoduleOptions, Title: self.c.Tr.LcBulkSubmoduleOptions,
Items: []*types.MenuItem{ Items: []*types.MenuItem{
{ {
DisplayStrings: []string{self.c.Tr.LcBulkInitSubmodules, style.FgGreen.Sprint(self.git.Submodule.BulkInitCmdObj().ToString())}, LabelColumns: []string{self.c.Tr.LcBulkInitSubmodules, style.FgGreen.Sprint(self.git.Submodule.BulkInitCmdObj().ToString())},
OnPress: func() error { OnPress: func() error {
return self.c.WithWaitingStatus(self.c.Tr.LcRunningCommand, func() error { return self.c.WithWaitingStatus(self.c.Tr.LcRunningCommand, func() error {
self.c.LogAction(self.c.Tr.Actions.BulkInitialiseSubmodules) self.c.LogAction(self.c.Tr.Actions.BulkInitialiseSubmodules)
@ -161,7 +161,7 @@ func (self *SubmodulesController) openBulkActionsMenu() error {
Key: 'i', Key: 'i',
}, },
{ {
DisplayStrings: []string{self.c.Tr.LcBulkUpdateSubmodules, style.FgYellow.Sprint(self.git.Submodule.BulkUpdateCmdObj().ToString())}, LabelColumns: []string{self.c.Tr.LcBulkUpdateSubmodules, style.FgYellow.Sprint(self.git.Submodule.BulkUpdateCmdObj().ToString())},
OnPress: func() error { OnPress: func() error {
return self.c.WithWaitingStatus(self.c.Tr.LcRunningCommand, func() error { return self.c.WithWaitingStatus(self.c.Tr.LcRunningCommand, func() error {
self.c.LogAction(self.c.Tr.Actions.BulkUpdateSubmodules) self.c.LogAction(self.c.Tr.Actions.BulkUpdateSubmodules)
@ -175,7 +175,7 @@ func (self *SubmodulesController) openBulkActionsMenu() error {
Key: 'u', Key: 'u',
}, },
{ {
DisplayStrings: []string{self.c.Tr.LcBulkDeinitSubmodules, style.FgRed.Sprint(self.git.Submodule.BulkDeinitCmdObj().ToString())}, LabelColumns: []string{self.c.Tr.LcBulkDeinitSubmodules, style.FgRed.Sprint(self.git.Submodule.BulkDeinitCmdObj().ToString())},
OnPress: func() error { OnPress: func() error {
return self.c.WithWaitingStatus(self.c.Tr.LcRunningCommand, func() error { return self.c.WithWaitingStatus(self.c.Tr.LcRunningCommand, func() error {
self.c.LogAction(self.c.Tr.Actions.BulkDeinitialiseSubmodules) self.c.LogAction(self.c.Tr.Actions.BulkDeinitialiseSubmodules)

View File

@ -19,7 +19,7 @@ func (self *FilesController) createResetMenu() error {
menuItems := []*types.MenuItem{ menuItems := []*types.MenuItem{
{ {
DisplayStrings: []string{ LabelColumns: []string{
self.c.Tr.LcDiscardAllChangesToAllFiles, self.c.Tr.LcDiscardAllChangesToAllFiles,
red.Sprint(nukeStr), red.Sprint(nukeStr),
}, },
@ -35,7 +35,7 @@ func (self *FilesController) createResetMenu() error {
Tooltip: self.c.Tr.NukeDescription, Tooltip: self.c.Tr.NukeDescription,
}, },
{ {
DisplayStrings: []string{ LabelColumns: []string{
self.c.Tr.LcDiscardAnyUnstagedChanges, self.c.Tr.LcDiscardAnyUnstagedChanges,
red.Sprint("git checkout -- ."), red.Sprint("git checkout -- ."),
}, },
@ -50,7 +50,7 @@ func (self *FilesController) createResetMenu() error {
Key: 'u', Key: 'u',
}, },
{ {
DisplayStrings: []string{ LabelColumns: []string{
self.c.Tr.LcDiscardUntrackedFiles, self.c.Tr.LcDiscardUntrackedFiles,
red.Sprint("git clean -fd"), red.Sprint("git clean -fd"),
}, },
@ -65,7 +65,7 @@ func (self *FilesController) createResetMenu() error {
Key: 'c', Key: 'c',
}, },
{ {
DisplayStrings: []string{ LabelColumns: []string{
self.c.Tr.LcSoftReset, self.c.Tr.LcSoftReset,
red.Sprint("git reset --soft HEAD"), red.Sprint("git reset --soft HEAD"),
}, },
@ -80,7 +80,7 @@ func (self *FilesController) createResetMenu() error {
Key: 's', Key: 's',
}, },
{ {
DisplayStrings: []string{ LabelColumns: []string{
"mixed reset", "mixed reset",
red.Sprint("git reset --mixed HEAD"), red.Sprint("git reset --mixed HEAD"),
}, },
@ -95,7 +95,7 @@ func (self *FilesController) createResetMenu() error {
Key: 'm', Key: 'm',
}, },
{ {
DisplayStrings: []string{ LabelColumns: []string{
self.c.Tr.LcHardReset, self.c.Tr.LcHardReset,
red.Sprint("git reset --hard HEAD"), red.Sprint("git reset --hard HEAD"),
}, },

View File

@ -112,7 +112,7 @@ func (gui *Gui) handleCreateDiffingMenuPanel() error {
name := name name := name
menuItems = append(menuItems, []*types.MenuItem{ menuItems = append(menuItems, []*types.MenuItem{
{ {
DisplayString: fmt.Sprintf("%s %s", gui.c.Tr.LcDiff, name), Label: fmt.Sprintf("%s %s", gui.c.Tr.LcDiff, name),
OnPress: func() error { OnPress: func() error {
gui.State.Modes.Diffing.Ref = name gui.State.Modes.Diffing.Ref = name
// can scope this down based on current view but too lazy right now // can scope this down based on current view but too lazy right now
@ -124,7 +124,7 @@ func (gui *Gui) handleCreateDiffingMenuPanel() error {
menuItems = append(menuItems, []*types.MenuItem{ menuItems = append(menuItems, []*types.MenuItem{
{ {
DisplayString: gui.c.Tr.LcEnterRefToDiff, Label: gui.c.Tr.LcEnterRefToDiff,
OnPress: func() error { OnPress: func() error {
return gui.c.Prompt(types.PromptOpts{ return gui.c.Prompt(types.PromptOpts{
Title: gui.c.Tr.LcEnteRefName, Title: gui.c.Tr.LcEnteRefName,
@ -141,14 +141,14 @@ func (gui *Gui) handleCreateDiffingMenuPanel() error {
if gui.State.Modes.Diffing.Active() { if gui.State.Modes.Diffing.Active() {
menuItems = append(menuItems, []*types.MenuItem{ menuItems = append(menuItems, []*types.MenuItem{
{ {
DisplayString: gui.c.Tr.LcSwapDiff, Label: gui.c.Tr.LcSwapDiff,
OnPress: func() error { OnPress: func() error {
gui.State.Modes.Diffing.Reverse = !gui.State.Modes.Diffing.Reverse gui.State.Modes.Diffing.Reverse = !gui.State.Modes.Diffing.Reverse
return gui.c.Refresh(types.RefreshOptions{Mode: types.ASYNC}) return gui.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
}, },
}, },
{ {
DisplayString: gui.c.Tr.LcExitDiffMode, Label: gui.c.Tr.LcExitDiffMode,
OnPress: func() error { OnPress: func() error {
gui.State.Modes.Diffing = diffing.New() gui.State.Modes.Diffing = diffing.New()
return gui.c.Refresh(types.RefreshOptions{Mode: types.ASYNC}) return gui.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})

View File

@ -13,7 +13,7 @@ func (gui *Gui) handleCreateExtrasMenuPanel() error {
Title: gui.c.Tr.CommandLog, Title: gui.c.Tr.CommandLog,
Items: []*types.MenuItem{ Items: []*types.MenuItem{
{ {
DisplayString: gui.c.Tr.ToggleShowCommandLog, Label: gui.c.Tr.ToggleShowCommandLog,
OnPress: func() error { OnPress: func() error {
currentContext := gui.currentStaticContext() currentContext := gui.currentStaticContext()
if gui.ShowExtrasWindow && currentContext.GetKey() == context.COMMAND_LOG_CONTEXT_KEY { if gui.ShowExtrasWindow && currentContext.GetKey() == context.COMMAND_LOG_CONTEXT_KEY {
@ -29,8 +29,8 @@ func (gui *Gui) handleCreateExtrasMenuPanel() error {
}, },
}, },
{ {
DisplayString: gui.c.Tr.FocusCommandLog, Label: gui.c.Tr.FocusCommandLog,
OnPress: gui.handleFocusCommandLog, OnPress: gui.handleFocusCommandLog,
}, },
}, },
}) })

View File

@ -26,7 +26,7 @@ func (gui *Gui) handleCreateFilteringMenuPanel() error {
if fileName != "" { if fileName != "" {
menuItems = append(menuItems, &types.MenuItem{ menuItems = append(menuItems, &types.MenuItem{
DisplayString: fmt.Sprintf("%s '%s'", gui.c.Tr.LcFilterBy, fileName), Label: fmt.Sprintf("%s '%s'", gui.c.Tr.LcFilterBy, fileName),
OnPress: func() error { OnPress: func() error {
return gui.setFiltering(fileName) return gui.setFiltering(fileName)
}, },
@ -34,7 +34,7 @@ func (gui *Gui) handleCreateFilteringMenuPanel() error {
} }
menuItems = append(menuItems, &types.MenuItem{ menuItems = append(menuItems, &types.MenuItem{
DisplayString: gui.c.Tr.LcFilterPathOption, Label: gui.c.Tr.LcFilterPathOption,
OnPress: func() error { OnPress: func() error {
return gui.c.Prompt(types.PromptOpts{ return gui.c.Prompt(types.PromptOpts{
FindSuggestionsFunc: gui.helpers.Suggestions.GetFilePathSuggestionsFunc(), FindSuggestionsFunc: gui.helpers.Suggestions.GetFilePathSuggestionsFunc(),
@ -48,8 +48,8 @@ func (gui *Gui) handleCreateFilteringMenuPanel() error {
if gui.State.Modes.Filtering.Active() { if gui.State.Modes.Filtering.Active() {
menuItems = append(menuItems, &types.MenuItem{ menuItems = append(menuItems, &types.MenuItem{
DisplayString: gui.c.Tr.LcExitFilterMode, Label: gui.c.Tr.LcExitFilterMode,
OnPress: gui.clearFiltering, OnPress: gui.clearFiltering,
}) })
} }

View File

@ -23,7 +23,7 @@ func (gui *Gui) createMenu(opts types.CreateMenuOptions) error {
if !opts.HideCancel { if !opts.HideCancel {
// this is mutative but I'm okay with that for now // this is mutative but I'm okay with that for now
opts.Items = append(opts.Items, &types.MenuItem{ opts.Items = append(opts.Items, &types.MenuItem{
DisplayStrings: []string{gui.c.Tr.LcCancel}, LabelColumns: []string{gui.c.Tr.LcCancel},
OnPress: func() error { OnPress: func() error {
return nil return nil
}, },
@ -31,7 +31,7 @@ func (gui *Gui) createMenu(opts types.CreateMenuOptions) error {
} }
for _, item := range opts.Items { for _, item := range opts.Items {
if item.OpensMenu && item.DisplayStrings != nil { if item.OpensMenu && item.LabelColumns != nil {
return errors.New("Message for the developer of this app: you've set opensMenu with displaystrings on the menu panel. Bad developer!. Apologies, user") return errors.New("Message for the developer of this app: you've set opensMenu with displaystrings on the menu panel. Bad developer!. Apologies, user")
} }
} }

View File

@ -65,7 +65,7 @@ func (gui *Gui) handleCreateOptionsMenu() error {
menuItems := slices.Map(bindings, func(binding *types.Binding) *types.MenuItem { menuItems := slices.Map(bindings, func(binding *types.Binding) *types.MenuItem {
return &types.MenuItem{ return &types.MenuItem{
DisplayString: gui.displayDescription(binding), Label: gui.displayDescription(binding),
OnPress: func() error { OnPress: func() error {
if binding.Key == nil { if binding.Key == nil {
return nil return nil

View File

@ -15,38 +15,38 @@ func (gui *Gui) handleCreatePatchOptionsMenu() error {
menuItems := []*types.MenuItem{ menuItems := []*types.MenuItem{
{ {
DisplayString: "reset patch", Label: "reset patch",
OnPress: gui.handleResetPatch, OnPress: gui.handleResetPatch,
Key: 'c', Key: 'c',
}, },
{ {
DisplayString: "apply patch", Label: "apply patch",
OnPress: func() error { return gui.handleApplyPatch(false) }, OnPress: func() error { return gui.handleApplyPatch(false) },
Key: 'a', Key: 'a',
}, },
{ {
DisplayString: "apply patch in reverse", Label: "apply patch in reverse",
OnPress: func() error { return gui.handleApplyPatch(true) }, OnPress: func() error { return gui.handleApplyPatch(true) },
Key: 'r', Key: 'r',
}, },
} }
if gui.git.Patch.PatchManager.CanRebase && gui.git.Status.WorkingTreeState() == enums.REBASE_MODE_NONE { if gui.git.Patch.PatchManager.CanRebase && gui.git.Status.WorkingTreeState() == enums.REBASE_MODE_NONE {
menuItems = append(menuItems, []*types.MenuItem{ menuItems = append(menuItems, []*types.MenuItem{
{ {
DisplayString: fmt.Sprintf("remove patch from original commit (%s)", gui.git.Patch.PatchManager.To), Label: fmt.Sprintf("remove patch from original commit (%s)", gui.git.Patch.PatchManager.To),
OnPress: gui.handleDeletePatchFromCommit, OnPress: gui.handleDeletePatchFromCommit,
Key: 'd', Key: 'd',
}, },
{ {
DisplayString: "move patch out into index", Label: "move patch out into index",
OnPress: gui.handleMovePatchIntoWorkingTree, OnPress: gui.handleMovePatchIntoWorkingTree,
Key: 'i', Key: 'i',
}, },
{ {
DisplayString: "move patch into new commit", Label: "move patch into new commit",
OnPress: gui.handlePullPatchIntoNewCommit, OnPress: gui.handlePullPatchIntoNewCommit,
Key: 'n', Key: 'n',
}, },
}...) }...)
@ -59,9 +59,9 @@ func (gui *Gui) handleCreatePatchOptionsMenu() error {
append( append(
[]*types.MenuItem{ []*types.MenuItem{
{ {
DisplayString: fmt.Sprintf("move patch to selected commit (%s)", selectedCommit.Sha), Label: fmt.Sprintf("move patch to selected commit (%s)", selectedCommit.Sha),
OnPress: gui.handleMovePatchToSelectedCommit, OnPress: gui.handleMovePatchToSelectedCommit,
Key: 'm', Key: 'm',
}, },
}, menuItems[1:]..., }, menuItems[1:]...,
)..., )...,

View File

@ -17,7 +17,7 @@ func (gui *Gui) handleCreateRecentReposMenu() error {
// we won't show the current repo hence the -1 // we won't show the current repo hence the -1
menuItems := slices.Map(recentRepoPaths[1:], func(path string) *types.MenuItem { menuItems := slices.Map(recentRepoPaths[1:], func(path string) *types.MenuItem {
return &types.MenuItem{ return &types.MenuItem{
DisplayStrings: []string{ LabelColumns: []string{
filepath.Base(path), filepath.Base(path),
style.FgMagenta.Sprint(path), style.FgMagenta.Sprint(path),
}, },

View File

@ -102,7 +102,7 @@ func (self *HandlerCreator) inputPrompt(prompt *config.CustomCommandPrompt, wrap
func (self *HandlerCreator) menuPrompt(prompt *config.CustomCommandPrompt, wrappedF func(string) error) error { func (self *HandlerCreator) menuPrompt(prompt *config.CustomCommandPrompt, wrappedF func(string) error) error {
menuItems := slices.Map(prompt.Options, func(option config.CustomCommandMenuOption) *types.MenuItem { menuItems := slices.Map(prompt.Options, func(option config.CustomCommandMenuOption) *types.MenuItem {
return &types.MenuItem{ return &types.MenuItem{
DisplayStrings: []string{option.Name, style.FgYellow.Sprint(option.Description)}, LabelColumns: []string{option.Name, style.FgYellow.Sprint(option.Description)},
OnPress: func() error { OnPress: func() error {
return wrappedF(option.Value) return wrappedF(option.Value)
}, },
@ -127,7 +127,7 @@ func (self *HandlerCreator) menuPromptFromCommand(prompt *config.CustomCommandPr
menuItems := slices.Map(candidates, func(candidate *commandMenuEntry) *types.MenuItem { menuItems := slices.Map(candidates, func(candidate *commandMenuEntry) *types.MenuItem {
return &types.MenuItem{ return &types.MenuItem{
DisplayStrings: []string{candidate.label}, LabelColumns: []string{candidate.label},
OnPress: func() error { OnPress: func() error {
return wrappedF(candidate.value) return wrappedF(candidate.value)
}, },

View File

@ -105,7 +105,7 @@ func (gui *Gui) askForConfigFile(action func(file string) error) error {
default: default:
menuItems := slices.Map(confPaths, func(path string) *types.MenuItem { menuItems := slices.Map(confPaths, func(path string) *types.MenuItem {
return &types.MenuItem{ return &types.MenuItem{
DisplayString: path, Label: path,
OnPress: func() error { OnPress: func() error {
return action(path) return action(path)
}, },

View File

@ -109,17 +109,21 @@ type PromptOpts struct {
} }
type MenuItem struct { type MenuItem struct {
DisplayString string Label string
DisplayStrings []string
OnPress func() error // alternative to Label. Allows specifying columns which will be auto-aligned
// only applies when displayString is used LabelColumns []string
OnPress func() error
// Only applies when Label is used
OpensMenu bool OpensMenu bool
// if Key is defined it allows the user to press the key to invoke the menu // If Key is defined it allows the user to press the key to invoke the menu
// item, as opposed to having to navigate to it // item, as opposed to having to navigate to it
Key Key Key Key
// the tooltip will be displayed upon highlighting the menu item // The tooltip will be displayed upon highlighting the menu item
Tooltip string Tooltip string
} }