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

add type alias for Key

This commit is contained in:
Jesse Duffield
2022-03-26 15:02:32 +11:00
parent 7128d822cb
commit 98e7ec0905
5 changed files with 10 additions and 8 deletions

View File

@ -76,7 +76,7 @@ var keyMapReversed = map[gocui.Key]string{
gocui.MouseWheelDown: "mouse wheel down",
}
var keymap = map[string]interface{}{
var keymap = map[string]types.Key{
"<c-a>": gocui.KeyCtrlA,
"<c-b>": gocui.KeyCtrlB,
"<c-c>": gocui.KeyCtrlC,
@ -153,7 +153,7 @@ func (gui *Gui) getKeyDisplay(name string) string {
return GetKeyDisplay(key)
}
func GetKeyDisplay(key interface{}) string {
func GetKeyDisplay(key types.Key) string {
keyInt := 0
switch key := key.(type) {
@ -170,7 +170,7 @@ func GetKeyDisplay(key interface{}) string {
return fmt.Sprintf("%c", keyInt)
}
func (gui *Gui) getKey(key string) interface{} {
func (gui *Gui) getKey(key string) types.Key {
runeCount := utf8.RuneCountInString(key)
if runeCount > 1 {
binding := keymap[strings.ToLower(key)]

View File

@ -23,7 +23,7 @@ func NewClient(
git *commands.GitCommand,
contexts *context.ContextTree,
helpers *helpers.Helpers,
getKey func(string) interface{},
getKey func(string) types.Key,
) *Client {
sessionStateLoader := NewSessionStateLoader(contexts, helpers)
handlerCreator := NewHandlerCreator(c, os, git, sessionStateLoader)

View File

@ -14,10 +14,10 @@ import (
// KeybindingCreator takes a custom command along with its handler and returns a corresponding keybinding
type KeybindingCreator struct {
contexts *context.ContextTree
getKey func(string) interface{}
getKey func(string) types.Key
}
func NewKeybindingCreator(contexts *context.ContextTree, getKey func(string) interface{}) *KeybindingCreator {
func NewKeybindingCreator(contexts *context.ContextTree, getKey func(string) types.Key) *KeybindingCreator {
return &KeybindingCreator{
contexts: contexts,
getKey: getKey,

View File

@ -97,7 +97,7 @@ type OnFocusOpts struct {
type ContextKey string
type KeybindingsOpts struct {
GetKey func(key string) interface{}
GetKey func(key string) Key
Config config.KeybindingConfig
Guards KeybindingGuards
}

View File

@ -2,6 +2,8 @@ package types
import "github.com/jesseduffield/gocui"
type Key interface{} // FIXME: find out how to get `gocui.Key | rune`
// Binding - a keybinding mapping a key and modifier to a handler. The keypress
// is only handled if the given view has focus, or handled globally if the view
// is ""
@ -9,7 +11,7 @@ type Binding struct {
ViewName string
Contexts []string
Handler func() error
Key interface{} // FIXME: find out how to get `gocui.Key | rune`
Key Key
Modifier gocui.Modifier
Description string
Alternative string