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:
@ -76,7 +76,7 @@ var keyMapReversed = map[gocui.Key]string{
|
|||||||
gocui.MouseWheelDown: "mouse wheel down",
|
gocui.MouseWheelDown: "mouse wheel down",
|
||||||
}
|
}
|
||||||
|
|
||||||
var keymap = map[string]interface{}{
|
var keymap = map[string]types.Key{
|
||||||
"<c-a>": gocui.KeyCtrlA,
|
"<c-a>": gocui.KeyCtrlA,
|
||||||
"<c-b>": gocui.KeyCtrlB,
|
"<c-b>": gocui.KeyCtrlB,
|
||||||
"<c-c>": gocui.KeyCtrlC,
|
"<c-c>": gocui.KeyCtrlC,
|
||||||
@ -153,7 +153,7 @@ func (gui *Gui) getKeyDisplay(name string) string {
|
|||||||
return GetKeyDisplay(key)
|
return GetKeyDisplay(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetKeyDisplay(key interface{}) string {
|
func GetKeyDisplay(key types.Key) string {
|
||||||
keyInt := 0
|
keyInt := 0
|
||||||
|
|
||||||
switch key := key.(type) {
|
switch key := key.(type) {
|
||||||
@ -170,7 +170,7 @@ func GetKeyDisplay(key interface{}) string {
|
|||||||
return fmt.Sprintf("%c", keyInt)
|
return fmt.Sprintf("%c", keyInt)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) getKey(key string) interface{} {
|
func (gui *Gui) getKey(key string) types.Key {
|
||||||
runeCount := utf8.RuneCountInString(key)
|
runeCount := utf8.RuneCountInString(key)
|
||||||
if runeCount > 1 {
|
if runeCount > 1 {
|
||||||
binding := keymap[strings.ToLower(key)]
|
binding := keymap[strings.ToLower(key)]
|
||||||
|
@ -23,7 +23,7 @@ func NewClient(
|
|||||||
git *commands.GitCommand,
|
git *commands.GitCommand,
|
||||||
contexts *context.ContextTree,
|
contexts *context.ContextTree,
|
||||||
helpers *helpers.Helpers,
|
helpers *helpers.Helpers,
|
||||||
getKey func(string) interface{},
|
getKey func(string) types.Key,
|
||||||
) *Client {
|
) *Client {
|
||||||
sessionStateLoader := NewSessionStateLoader(contexts, helpers)
|
sessionStateLoader := NewSessionStateLoader(contexts, helpers)
|
||||||
handlerCreator := NewHandlerCreator(c, os, git, sessionStateLoader)
|
handlerCreator := NewHandlerCreator(c, os, git, sessionStateLoader)
|
||||||
|
@ -14,10 +14,10 @@ import (
|
|||||||
// KeybindingCreator takes a custom command along with its handler and returns a corresponding keybinding
|
// KeybindingCreator takes a custom command along with its handler and returns a corresponding keybinding
|
||||||
type KeybindingCreator struct {
|
type KeybindingCreator struct {
|
||||||
contexts *context.ContextTree
|
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{
|
return &KeybindingCreator{
|
||||||
contexts: contexts,
|
contexts: contexts,
|
||||||
getKey: getKey,
|
getKey: getKey,
|
||||||
|
@ -97,7 +97,7 @@ type OnFocusOpts struct {
|
|||||||
type ContextKey string
|
type ContextKey string
|
||||||
|
|
||||||
type KeybindingsOpts struct {
|
type KeybindingsOpts struct {
|
||||||
GetKey func(key string) interface{}
|
GetKey func(key string) Key
|
||||||
Config config.KeybindingConfig
|
Config config.KeybindingConfig
|
||||||
Guards KeybindingGuards
|
Guards KeybindingGuards
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,8 @@ package types
|
|||||||
|
|
||||||
import "github.com/jesseduffield/gocui"
|
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
|
// 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 only handled if the given view has focus, or handled globally if the view
|
||||||
// is ""
|
// is ""
|
||||||
@ -9,7 +11,7 @@ type Binding struct {
|
|||||||
ViewName string
|
ViewName string
|
||||||
Contexts []string
|
Contexts []string
|
||||||
Handler func() error
|
Handler func() error
|
||||||
Key interface{} // FIXME: find out how to get `gocui.Key | rune`
|
Key Key
|
||||||
Modifier gocui.Modifier
|
Modifier gocui.Modifier
|
||||||
Description string
|
Description string
|
||||||
Alternative string
|
Alternative string
|
||||||
|
Reference in New Issue
Block a user