Cleanup: remove unnecessary function Label()

It's a no-op. (I think this might not have been the case in the past, where
Label() was needed to "normalize" a keybinding or something.)
This commit is contained in:
Stefan Haller 2025-11-16 18:38:18 +01:00
parent f866f04b7c
commit ff58687b68
14 changed files with 53 additions and 74 deletions

View file

@ -7,7 +7,6 @@ import (
"time"
"github.com/jesseduffield/lazygit/pkg/constants"
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
"github.com/jesseduffield/lazygit/pkg/gui/style"
"github.com/jesseduffield/lazygit/pkg/theme"
)
@ -55,7 +54,7 @@ func (gui *Gui) LogCommand(cmdStr string, commandLine bool) {
func (gui *Gui) printCommandLogHeader() {
introStr := fmt.Sprintf(
gui.c.Tr.CommandLogHeader,
keybindings.Label(gui.c.UserConfig().Keybinding.Universal.ExtrasMenu),
gui.c.UserConfig().Keybinding.Universal.ExtrasMenu,
)
fmt.Fprintln(gui.Views.Extras, style.FgCyan.Sprint(introStr))
@ -72,95 +71,91 @@ func (gui *Gui) printCommandLogHeader() {
func (gui *Gui) getRandomTip() string {
config := gui.c.UserConfig().Keybinding
formattedKey := func(key string) string {
return keybindings.Label(key)
}
tips := []string{
// keybindings and lazygit-specific advice
fmt.Sprintf(
"To force push, press '%s' and then if the push is rejected you will be asked if you want to force push",
formattedKey(config.Universal.Push),
config.Universal.Push,
),
fmt.Sprintf(
"To filter commits by path, press '%s'",
formattedKey(config.Universal.FilteringMenu),
config.Universal.FilteringMenu,
),
fmt.Sprintf(
"To start an interactive rebase, press '%s' on a commit. You can always abort the rebase by pressing '%s' and selecting 'abort'",
formattedKey(config.Universal.Edit),
formattedKey(config.Universal.CreateRebaseOptionsMenu),
config.Universal.Edit,
config.Universal.CreateRebaseOptionsMenu,
),
fmt.Sprintf(
"In flat file view, merge conflicts are sorted to the top. To switch to flat file view press '%s'",
formattedKey(config.Files.ToggleTreeView),
config.Files.ToggleTreeView,
),
"If you want to learn Go and can think of ways to improve lazygit, join the team! Click 'Ask Question' and express your interest",
fmt.Sprintf(
"If you press '%s'/'%s' you can undo/redo your changes. Be wary though, this only applies to branches/commits, so only do this if your worktree is clear.\nDocs: %s",
formattedKey(config.Universal.Undo),
formattedKey(config.Universal.Redo),
config.Universal.Undo,
config.Universal.Redo,
constants.Links.Docs.Undoing,
),
fmt.Sprintf(
"to hard reset onto your current upstream branch, press '%s' in the files panel",
formattedKey(config.Commits.ViewResetOptions),
config.Commits.ViewResetOptions,
),
fmt.Sprintf(
"To push a tag, navigate to the tag in the tags tab and press '%s'",
formattedKey(config.Branches.PushTag),
config.Branches.PushTag,
),
fmt.Sprintf(
"You can view the individual files of a stash entry by pressing '%s'",
formattedKey(config.Universal.GoInto),
config.Universal.GoInto,
),
fmt.Sprintf(
"You can diff two commits by pressing '%s' on one commit and then navigating to the other. You can then press '%s' to view the files of the diff",
formattedKey(config.Universal.DiffingMenu),
formattedKey(config.Universal.GoInto),
config.Universal.DiffingMenu,
config.Universal.GoInto,
),
fmt.Sprintf(
"press '%s' on a commit to drop it (delete it)",
formattedKey(config.Universal.Remove),
config.Universal.Remove,
),
fmt.Sprintf(
"If you need to pull out the big guns to resolve merge conflicts, you can press '%s' in the files panel to open merge options",
formattedKey(config.Files.OpenMergeOptions),
config.Files.OpenMergeOptions,
),
fmt.Sprintf(
"To revert a commit, press '%s' on that commit",
formattedKey(config.Commits.RevertCommit),
config.Commits.RevertCommit,
),
fmt.Sprintf(
"To escape a mode, for example cherry-picking, patch-building, diffing, or filtering mode, you can just spam the '%s' button. Unless of course you have `quitOnTopLevelReturn` enabled in your config",
formattedKey(config.Universal.Return),
config.Universal.Return,
),
fmt.Sprintf(
"You can page through the items of a panel using '%s' and '%s'",
formattedKey(config.Universal.PrevPage),
formattedKey(config.Universal.NextPage),
config.Universal.PrevPage,
config.Universal.NextPage,
),
fmt.Sprintf(
"You can jump to the top/bottom of a panel using '%s (or %s)' and '%s (or %s)'",
formattedKey(config.Universal.GotoTop), formattedKey(config.Universal.GotoTopAlt),
formattedKey(config.Universal.GotoBottom), formattedKey(config.Universal.GotoBottomAlt),
config.Universal.GotoTop, config.Universal.GotoTopAlt,
config.Universal.GotoBottom, config.Universal.GotoBottomAlt,
),
fmt.Sprintf(
"To collapse/expand a directory, press '%s'",
formattedKey(config.Universal.GoInto),
config.Universal.GoInto,
),
fmt.Sprintf(
"You can append your staged changes to an older commit by pressing '%s' on that commit",
formattedKey(config.Commits.AmendToCommit),
config.Commits.AmendToCommit,
),
fmt.Sprintf(
"You can amend the last commit with your new file changes by pressing '%s' in the files panel",
formattedKey(config.Files.AmendLastCommit),
config.Files.AmendLastCommit,
),
fmt.Sprintf(
"You can now navigate the side panels with '%s' and '%s'",
formattedKey(config.Universal.NextBlockAlt2),
formattedKey(config.Universal.PrevBlockAlt2),
config.Universal.NextBlockAlt2,
config.Universal.PrevBlockAlt2,
),
"You can use lazygit with a bare repo by passing the --git-dir and --work-tree arguments as you would for the git CLI",

View file

@ -6,7 +6,6 @@ import (
"strconv"
"strings"
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/utils"
"github.com/spf13/afero"
@ -167,8 +166,8 @@ func (self *CommitMessageContext) SetPanelState(
self.c.Views().CommitDescription.Subtitle = utils.ResolvePlaceholderString(self.c.Tr.CommitDescriptionSubTitle,
map[string]string{
"togglePanelKeyBinding": keybindings.Label(self.c.UserConfig().Keybinding.Universal.TogglePanel),
"commitMenuKeybinding": keybindings.Label(self.c.UserConfig().Keybinding.CommitMessage.CommitMenu),
"togglePanelKeyBinding": self.c.UserConfig().Keybinding.Universal.TogglePanel,
"commitMenuKeybinding": self.c.UserConfig().Keybinding.CommitMessage.CommitMenu,
})
self.c.Views().CommitDescription.Visible = true

View file

@ -3,7 +3,6 @@ package context
import (
"fmt"
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
"github.com/jesseduffield/lazygit/pkg/theme"
)
@ -45,7 +44,7 @@ func (self *SearchTrait) RenderSearchStatus(index int, total int) {
fmt.Sprintf(
self.c.Tr.NoMatchesFor,
self.searchString,
theme.OptionsFgColor.Sprintf(self.c.Tr.ExitSearchMode, keybindings.Label(keybindingConfig.Universal.Return)),
theme.OptionsFgColor.Sprintf(self.c.Tr.ExitSearchMode, keybindingConfig.Universal.Return),
),
)
} else {
@ -58,9 +57,9 @@ func (self *SearchTrait) RenderSearchStatus(index int, total int) {
total,
theme.OptionsFgColor.Sprintf(
self.c.Tr.SearchKeybindings,
keybindings.Label(keybindingConfig.Universal.NextMatch),
keybindings.Label(keybindingConfig.Universal.PrevMatch),
keybindings.Label(keybindingConfig.Universal.Return),
keybindingConfig.Universal.NextMatch,
keybindingConfig.Universal.PrevMatch,
keybindingConfig.Universal.Return,
),
),
)

View file

@ -7,7 +7,6 @@ import (
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/gui/context/traits"
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/utils"
"github.com/samber/lo"
@ -106,8 +105,8 @@ func (self *BasicCommitsController) GetKeybindings(opts types.KeybindingsOpts) [
Description: self.c.Tr.CherryPickCopy,
Tooltip: utils.ResolvePlaceholderString(self.c.Tr.CherryPickCopyTooltip,
map[string]string{
"paste": keybindings.Label(opts.Config.Commits.PasteCommits),
"escape": keybindings.Label(opts.Config.Universal.Return),
"paste": opts.Config.Commits.PasteCommits,
"escape": opts.Config.Universal.Return,
},
),
DisplayOnScreen: true,

View file

@ -2,7 +2,6 @@ package controllers
import (
"github.com/jesseduffield/lazygit/pkg/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/utils"
)
@ -72,18 +71,18 @@ func (self *CommitDescriptionController) GetOnFocus() func(types.OnFocusOpts) {
if self.c.UserConfig().Keybinding.Universal.ConfirmInEditor == "<disabled>" {
footer = utils.ResolvePlaceholderString(self.c.Tr.CommitDescriptionFooter,
map[string]string{
"confirmInEditorKeybinding": keybindings.Label(self.c.UserConfig().Keybinding.Universal.ConfirmInEditorAlt),
"confirmInEditorKeybinding": self.c.UserConfig().Keybinding.Universal.ConfirmInEditorAlt,
})
} else if self.c.UserConfig().Keybinding.Universal.ConfirmInEditorAlt == "<disabled>" {
footer = utils.ResolvePlaceholderString(self.c.Tr.CommitDescriptionFooter,
map[string]string{
"confirmInEditorKeybinding": keybindings.Label(self.c.UserConfig().Keybinding.Universal.ConfirmInEditor),
"confirmInEditorKeybinding": self.c.UserConfig().Keybinding.Universal.ConfirmInEditor,
})
} else {
footer = utils.ResolvePlaceholderString(self.c.Tr.CommitDescriptionFooterTwoBindings,
map[string]string{
"confirmInEditorKeybinding1": keybindings.Label(self.c.UserConfig().Keybinding.Universal.ConfirmInEditor),
"confirmInEditorKeybinding2": keybindings.Label(self.c.UserConfig().Keybinding.Universal.ConfirmInEditorAlt),
"confirmInEditorKeybinding1": self.c.UserConfig().Keybinding.Universal.ConfirmInEditor,
"confirmInEditorKeybinding2": self.c.UserConfig().Keybinding.Universal.ConfirmInEditorAlt,
})
}
}

View file

@ -14,7 +14,6 @@ import (
"github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers"
"github.com/jesseduffield/lazygit/pkg/gui/filetree"
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/utils"
"github.com/samber/lo"
@ -437,7 +436,7 @@ func (self *CommitFilesController) openDiffTool(node *filetree.CommitFileNode) e
func (self *CommitFilesController) toggleForPatch(selectedNodes []*filetree.CommitFileNode) error {
if self.c.UserConfig().Git.DiffContextSize == 0 {
return fmt.Errorf(self.c.Tr.Actions.NotEnoughContextForCustomPatch,
keybindings.Label(self.c.UserConfig().Keybinding.Universal.IncreaseContextInDiffView))
self.c.UserConfig().Keybinding.Universal.IncreaseContextInDiffView)
}
toggle := func() error {
@ -531,7 +530,7 @@ func (self *CommitFilesController) enterCommitFile(node *filetree.CommitFileNode
if self.c.UserConfig().Git.DiffContextSize == 0 {
return fmt.Errorf(self.c.Tr.Actions.NotEnoughContextForCustomPatch,
keybindings.Label(self.c.UserConfig().Keybinding.Universal.IncreaseContextInDiffView))
self.c.UserConfig().Keybinding.Universal.IncreaseContextInDiffView)
}
from, to, reverse := self.currentFromToReverseForPatchBuilding()

View file

@ -4,7 +4,6 @@ import (
"fmt"
"github.com/jesseduffield/lazygit/pkg/commands/patch"
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
"github.com/jesseduffield/lazygit/pkg/gui/patch_exploring"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
@ -26,8 +25,7 @@ func (self *PatchBuildingHelper) ShowHunkStagingHint() {
self.c.AppState.DidShowHunkStagingHint = true
self.c.SaveAppStateAndLogError()
message := fmt.Sprintf(self.c.Tr.HunkStagingHint,
keybindings.Label(self.c.UserConfig().Keybinding.Main.ToggleSelectHunk))
message := fmt.Sprintf(self.c.Tr.HunkStagingHint, self.c.UserConfig().Keybinding.Main.ToggleSelectHunk)
self.c.Confirm(types.ConfirmOpts{
Prompt: message,
})

View file

@ -6,7 +6,6 @@ import (
"github.com/jesseduffield/lazygit/pkg/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/theme"
"github.com/jesseduffield/lazygit/pkg/utils"
@ -75,7 +74,7 @@ func (self *SearchHelper) DisplayFilterStatus(context types.IFilterableContext)
promptView := self.promptView()
keybindingConfig := self.c.UserConfig().Keybinding
promptView.SetContent(fmt.Sprintf("matches for '%s' ", searchString) + theme.OptionsFgColor.Sprintf(self.c.Tr.ExitTextFilterMode, keybindings.Label(keybindingConfig.Universal.Return)))
promptView.SetContent(fmt.Sprintf("matches for '%s' ", searchString) + theme.OptionsFgColor.Sprintf(self.c.Tr.ExitTextFilterMode, keybindingConfig.Universal.Return))
}
func (self *SearchHelper) DisplaySearchStatus(context types.ISearchableContext) {

View file

@ -10,7 +10,6 @@ import (
"github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/context/traits"
"github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers"
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
"github.com/jesseduffield/lazygit/pkg/gui/style"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/utils"
@ -142,7 +141,7 @@ func (self *LocalCommitsController) GetKeybindings(opts types.KeybindingsOpts) [
GetDisabledReason: self.require(self.notMidRebase(self.c.Tr.AlreadyRebasing), self.canFindCommitForQuickStart),
Description: self.c.Tr.QuickStartInteractiveRebase,
Tooltip: utils.ResolvePlaceholderString(self.c.Tr.QuickStartInteractiveRebaseTooltip, map[string]string{
"editKey": keybindings.Label(editCommitKey),
"editKey": editCommitKey,
}),
},
{
@ -162,7 +161,7 @@ func (self *LocalCommitsController) GetKeybindings(opts types.KeybindingsOpts) [
Tooltip: utils.ResolvePlaceholderString(
self.c.Tr.CreateFixupCommitTooltip,
map[string]string{
"squashAbove": keybindings.Label(opts.Config.Commits.SquashAboveCommits),
"squashAbove": opts.Config.Commits.SquashAboveCommits,
},
),
},
@ -680,7 +679,7 @@ func (self *LocalCommitsController) findCommitForQuickStartInteractiveRebase() (
if !ok || index == 0 {
errorMsg := utils.ResolvePlaceholderString(self.c.Tr.CannotQuickStartInteractiveRebase, map[string]string{
"editKey": keybindings.Label(self.c.UserConfig().Keybinding.Universal.Edit),
"editKey": self.c.UserConfig().Keybinding.Universal.Edit,
})
return nil, errors.New(errorMsg)

View file

@ -4,7 +4,6 @@ import (
"fmt"
"github.com/jesseduffield/lazygit/pkg/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/samber/lo"
)
@ -188,7 +187,7 @@ func (self *PatchBuildingController) getDisabledReasonForDiscard() *types.Disabl
}
if self.c.UserConfig().Git.DiffContextSize == 0 {
text := fmt.Sprintf(self.c.Tr.Actions.NotEnoughContextToRemoveLines,
keybindings.Label(self.c.UserConfig().Keybinding.Universal.IncreaseContextInDiffView))
self.c.UserConfig().Keybinding.Universal.IncreaseContextInDiffView)
return &types.DisabledReason{Text: text, ShowErrorInPanel: true}
}
return nil

View file

@ -7,7 +7,6 @@ import (
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
"github.com/jesseduffield/lazygit/pkg/commands/patch"
"github.com/jesseduffield/lazygit/pkg/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
@ -205,7 +204,7 @@ func (self *StagingController) TogglePanel() error {
func (self *StagingController) ToggleStaged() error {
if self.c.UserConfig().Git.DiffContextSize == 0 {
return fmt.Errorf(self.c.Tr.Actions.NotEnoughContextToStage,
keybindings.Label(self.c.UserConfig().Keybinding.Universal.IncreaseContextInDiffView))
self.c.UserConfig().Keybinding.Universal.IncreaseContextInDiffView)
}
return self.applySelectionAndRefresh(self.staged)
@ -214,7 +213,7 @@ func (self *StagingController) ToggleStaged() error {
func (self *StagingController) DiscardSelection() error {
if self.c.UserConfig().Git.DiffContextSize == 0 {
return fmt.Errorf(self.c.Tr.Actions.NotEnoughContextToDiscard,
keybindings.Label(self.c.UserConfig().Keybinding.Universal.IncreaseContextInDiffView))
self.c.UserConfig().Keybinding.Universal.IncreaseContextInDiffView)
}
return self.c.ConfirmIf(!self.staged && !self.c.UserConfig().Gui.SkipDiscardChangeWarning,

View file

@ -8,7 +8,6 @@ import (
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
"github.com/jesseduffield/lazygit/pkg/gui/style"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/utils"
@ -45,7 +44,7 @@ func (self *SubmodulesController) GetKeybindings(opts types.KeybindingsOpts) []*
GetDisabledReason: self.require(self.singleItemSelected()),
Description: self.c.Tr.Enter,
Tooltip: utils.ResolvePlaceholderString(self.c.Tr.EnterSubmoduleTooltip,
map[string]string{"escape": keybindings.Label(opts.Config.Universal.Return)}),
map[string]string{"escape": opts.Config.Universal.Return}),
DisplayOnScreen: true,
},
{

View file

@ -12,10 +12,6 @@ import (
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
func Label(name string) string {
return LabelFromKey(GetKey(name))
}
func LabelFromKey(key types.Key) string {
if key == nil {
return ""

View file

@ -69,7 +69,7 @@ func (self *OptionsMapMgr) renderContextOptionsMap() {
if currentContext.GetKey() == context.LOCAL_COMMITS_CONTEXT_KEY {
if self.c.Modes().CherryPicking.Active() {
optionsMap = utils.Prepend(optionsMap, bindingInfo{
key: keybindings.Label(self.c.KeybindingsOpts().Config.Commits.PasteCommits),
key: self.c.KeybindingsOpts().Config.Commits.PasteCommits,
description: self.c.Tr.PasteCommits,
style: style.FgCyan,
})
@ -77,7 +77,7 @@ func (self *OptionsMapMgr) renderContextOptionsMap() {
if self.c.Model().BisectInfo.Started() {
optionsMap = utils.Prepend(optionsMap, bindingInfo{
key: keybindings.Label(self.c.KeybindingsOpts().Config.Commits.ViewBisectOptions),
key: self.c.KeybindingsOpts().Config.Commits.ViewBisectOptions,
description: self.c.Tr.ViewBisectOptions,
style: style.FgGreen,
})
@ -87,7 +87,7 @@ func (self *OptionsMapMgr) renderContextOptionsMap() {
// Mode-specific global keybindings
if state := self.c.Model().WorkingTreeStateAtLastCommitRefresh; state.Any() {
optionsMap = utils.Prepend(optionsMap, bindingInfo{
key: keybindings.Label(self.c.KeybindingsOpts().Config.Universal.CreateRebaseOptionsMenu),
key: self.c.KeybindingsOpts().Config.Universal.CreateRebaseOptionsMenu,
description: state.OptionsMapTitle(self.c.Tr),
style: style.FgYellow,
})
@ -95,7 +95,7 @@ func (self *OptionsMapMgr) renderContextOptionsMap() {
if self.c.Git().Patch.PatchBuilder.Active() {
optionsMap = utils.Prepend(optionsMap, bindingInfo{
key: keybindings.Label(self.c.KeybindingsOpts().Config.Universal.CreatePatchOptionsMenu),
key: self.c.KeybindingsOpts().Config.Universal.CreatePatchOptionsMenu,
description: self.c.Tr.ViewPatchOptions,
style: style.FgYellow,
})