Move keybindings.LabelFromKey to config package

So that it is next to KeyFromLabel.
This commit is contained in:
Stefan Haller 2026-04-02 10:09:41 +02:00
parent c455fca062
commit 69e99ffd64
5 changed files with 25 additions and 26 deletions

View file

@ -22,7 +22,6 @@ import (
"github.com/jesseduffield/lazycore/pkg/utils"
"github.com/jesseduffield/lazygit/pkg/app"
"github.com/jesseduffield/lazygit/pkg/config"
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/i18n"
"github.com/samber/lo"
@ -157,7 +156,7 @@ func getBindingSections(bindings []*types.Binding, tr *i18n.TranslationSet) []*b
bindingsByHeader,
func(header header, hBindings []*types.Binding) headerWithBindings {
uniqBindings := lo.UniqBy(hBindings, func(binding *types.Binding) string {
return binding.Description + keybindings.LabelFromKey(binding.Key)
return binding.Description + config.LabelForKey(binding.Key)
})
return headerWithBindings{
@ -217,7 +216,7 @@ func formatTitle(title string) string {
}
func formatBinding(binding *types.Binding) string {
action := keybindings.LabelFromKey(binding.Key)
action := config.LabelForKey(binding.Key)
description := binding.Description
if binding.Alternative != "" {
action += fmt.Sprintf(" (%s)", binding.Alternative)

View file

@ -4,6 +4,7 @@ import (
"strings"
"unicode/utf8"
"github.com/gdamore/tcell/v3"
"github.com/jesseduffield/lazygit/pkg/gocui"
"github.com/samber/lo"
)
@ -73,6 +74,23 @@ var LabelByKey = map[gocui.KeyName]string{
var KeyByLabel = lo.Invert(LabelByKey)
func LabelForKey(key gocui.Key) string {
if !key.IsSet() {
return ""
}
if key.KeyName() == gocui.KeyName(tcell.KeyRune) {
return key.Str()
}
value, ok := LabelByKey[key.KeyName()]
if ok {
return value
}
return "unknown"
}
func KeyFromLabel(label string) (gocui.Key, bool) {
if label == "" || label == "<disabled>" {
return gocui.Key{}, true

View file

@ -4,7 +4,7 @@ import (
"errors"
"strings"
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
"github.com/jesseduffield/lazygit/pkg/config"
"github.com/jesseduffield/lazygit/pkg/gui/style"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/i18n"
@ -73,7 +73,7 @@ func NewMenuViewModel(c *ContextCommon) *MenuViewModel {
func() []*types.MenuItem { return self.menuItems },
func(item *types.MenuItem) []string {
if filterKeybindings {
return []string{keybindings.LabelFromKey(item.Key)}
return []string{config.LabelForKey(item.Key)}
}
return item.LabelColumns
@ -139,7 +139,7 @@ func (self *MenuViewModel) GetDisplayStrings(_ int, _ int) [][]string {
keyLabel := ""
if item.Key.IsSet() {
keyLabel = style.FgCyan.Sprint(keybindings.LabelFromKey(item.Key))
keyLabel = style.FgCyan.Sprint(config.LabelForKey(item.Key))
}
checkMark := ""

View file

@ -3,28 +3,10 @@ package keybindings
import (
"log"
"github.com/gdamore/tcell/v3"
"github.com/jesseduffield/lazygit/pkg/config"
"github.com/jesseduffield/lazygit/pkg/gocui"
)
func LabelFromKey(key gocui.Key) string {
if !key.IsSet() {
return ""
}
if key.KeyName() == gocui.KeyName(tcell.KeyRune) {
return key.Str()
}
value, ok := config.LabelByKey[key.KeyName()]
if ok {
return value
}
return "unknown"
}
func GetKey(label string) gocui.Key {
key, ok := config.KeyFromLabel(label)
if !ok {

View file

@ -5,10 +5,10 @@ import (
"strings"
"github.com/jesseduffield/generics/set"
"github.com/jesseduffield/lazygit/pkg/config"
"github.com/jesseduffield/lazygit/pkg/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/context"
"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/theme"
@ -60,7 +60,7 @@ func (self *OptionsMapMgr) renderContextOptionsMap() {
}
return bindingInfo{
key: keybindings.LabelFromKey(binding.Key),
key: config.LabelForKey(binding.Key),
description: binding.GetShortDescription(),
style: displayStyle,
}