package keybindings import ( "fmt" "log" "strings" "unicode/utf8" "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazygit/pkg/constants" "github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/samber/lo" ) var labelByKey = map[gocui.Key]string{ gocui.KeyF1: "", gocui.KeyF2: "", gocui.KeyF3: "", gocui.KeyF4: "", gocui.KeyF5: "", gocui.KeyF6: "", gocui.KeyF7: "", gocui.KeyF8: "", gocui.KeyF9: "", gocui.KeyF10: "", gocui.KeyF11: "", gocui.KeyF12: "", gocui.KeyInsert: "", gocui.KeyDelete: "", gocui.KeyHome: "", gocui.KeyEnd: "", gocui.KeyPgup: "", gocui.KeyPgdn: "", gocui.KeyArrowUp: "", gocui.KeyArrowDown: "", gocui.KeyArrowLeft: "", gocui.KeyArrowRight: "", gocui.KeyTab: "", // gocui.KeyBacktab: "", gocui.KeyEnter: "", // gocui.KeyAltEnter: "", gocui.KeyEsc: "", // , gocui.KeyBackspace: "", // gocui.KeyCtrlSpace: "", // , gocui.KeyCtrlSlash: "", // gocui.KeySpace: "", gocui.KeyCtrlA: "", gocui.KeyCtrlB: "", gocui.KeyCtrlC: "", gocui.KeyCtrlD: "", gocui.KeyCtrlE: "", gocui.KeyCtrlF: "", gocui.KeyCtrlG: "", gocui.KeyCtrlJ: "", gocui.KeyCtrlK: "", gocui.KeyCtrlL: "", gocui.KeyCtrlN: "", gocui.KeyCtrlO: "", gocui.KeyCtrlP: "", gocui.KeyCtrlQ: "", gocui.KeyCtrlR: "", gocui.KeyCtrlS: "", gocui.KeyCtrlT: "", gocui.KeyCtrlU: "", gocui.KeyCtrlV: "", gocui.KeyCtrlW: "", gocui.KeyCtrlX: "", gocui.KeyCtrlY: "", gocui.KeyCtrlZ: "", gocui.KeyCtrl4: "", // gocui.KeyCtrl5: "", // gocui.KeyCtrl6: "", gocui.KeyCtrl8: "", gocui.MouseWheelUp: "mouse wheel up", gocui.MouseWheelDown: "mouse wheel down", } var keyByLabel = lo.Invert(labelByKey) 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 := 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 runeCount > 1 { binding, ok := 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) } else { return binding } } else if runeCount == 1 { return []rune(key)[0] } return nil }