1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-03 00:57:52 +02:00
Files
lazygit/pkg/gui/keybindings/keybindings.go
Stefan Haller ca05a2ccea Enable revive linter, and fix a bunch of warnings
I took the set of enabled checks from revive's recommended configuration [1],
and removed some that I didn't like. There might be other useful checks in
revive that we might want to enable, but this is a nice improvement already.

The bulk of the changes here are removing unnecessary else statements after
returns, but there are a few others too.

[1] https://github.com/mgechev/revive?tab=readme-ov-file#recommended-configuration
2025-06-30 19:13:20 +02:00

51 lines
1.0 KiB
Go

package keybindings
import (
"fmt"
"log"
"strings"
"unicode/utf8"
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/config"
"github.com/jesseduffield/lazygit/pkg/constants"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
func Label(name string) string {
return LabelFromKey(GetKey(name))
}
func LabelFromKey(key types.Key) string {
keyInt := 0
switch key := key.(type) {
case rune:
keyInt = int(key)
case gocui.Key:
value, ok := config.LabelByKey[key]
if ok {
return value
}
keyInt = int(key)
}
return fmt.Sprintf("%c", keyInt)
}
func GetKey(key string) types.Key {
runeCount := utf8.RuneCountInString(key)
if key == "<disabled>" {
return nil
} else if runeCount > 1 {
binding, ok := config.KeyByLabel[strings.ToLower(key)]
if !ok {
log.Fatalf("Unrecognized key %s for keybinding. For permitted values see %s", strings.ToLower(key), constants.Links.Docs.CustomKeybindings)
}
return binding
} else if runeCount == 1 {
return []rune(key)[0]
}
return nil
}