summaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2022-03-26 15:02:32 +1100
committerJesse Duffield <jessedduffield@gmail.com>2022-03-27 18:16:16 +1100
commit98e7ec090509f089a3196848c324fdce2fb462fc (patch)
treecda5fcc6bf2ee5f442dff68fde121ef9ff3754b9 /pkg
parent7128d822cb82beba890aad4dd39e51270598cf0b (diff)
add type alias for Key
Diffstat (limited to 'pkg')
-rw-r--r--pkg/gui/keybindings.go6
-rw-r--r--pkg/gui/services/custom_commands/client.go2
-rw-r--r--pkg/gui/services/custom_commands/keybinding_creator.go4
-rw-r--r--pkg/gui/types/context.go2
-rw-r--r--pkg/gui/types/keybindings.go4
5 files changed, 10 insertions, 8 deletions
diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go
index e19f42935..8f70045d0 100644
--- a/pkg/gui/keybindings.go
+++ b/pkg/gui/keybindings.go
@@ -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)]
diff --git a/pkg/gui/services/custom_commands/client.go b/pkg/gui/services/custom_commands/client.go
index fc36405c1..3dead7d73 100644
--- a/pkg/gui/services/custom_commands/client.go
+++ b/pkg/gui/services/custom_commands/client.go
@@ -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)
diff --git a/pkg/gui/services/custom_commands/keybinding_creator.go b/pkg/gui/services/custom_commands/keybinding_creator.go
index ed2921359..1d1edb53e 100644
--- a/pkg/gui/services/custom_commands/keybinding_creator.go
+++ b/pkg/gui/services/custom_commands/keybinding_creator.go
@@ -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,
diff --git a/pkg/gui/types/context.go b/pkg/gui/types/context.go
index 1f7d753e7..6f026fe73 100644
--- a/pkg/gui/types/context.go
+++ b/pkg/gui/types/context.go
@@ -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
}
diff --git a/pkg/gui/types/keybindings.go b/pkg/gui/types/keybindings.go
index 7d1befc1b..b4db46336 100644
--- a/pkg/gui/types/keybindings.go
+++ b/pkg/gui/types/keybindings.go
@@ -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