mirror of
https://github.com/zoriya/bubbles.git
synced 2026-08-05 04:36:07 +00:00
feat(key): accept any stringer interface to match keys (#584)
* feat(key): accept any stringer interface to match keys This allows any `fmt.Stringer` interface to match key bindings. We need this in the upcoming v2 changes. * Update key/key.go Co-authored-by: Christian Rocha <christian@rocha.is> * Update key/key.go Co-authored-by: Christian Rocha <christian@rocha.is> --------- Co-authored-by: Christian Rocha <christian@rocha.is>
This commit is contained in:
co-authored by
Christian Rocha
parent
ff5fb57861
commit
5428d6ddec
+3
-5
@@ -36,9 +36,7 @@
|
||||
// to render help text for keystrokes in your views.
|
||||
package key
|
||||
|
||||
import (
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
import "fmt"
|
||||
|
||||
// Binding describes a set of keybindings and, optionally, their associated
|
||||
// help text.
|
||||
@@ -128,8 +126,8 @@ type Help struct {
|
||||
Desc string
|
||||
}
|
||||
|
||||
// Matches checks if the given KeyMsg matches the given bindings.
|
||||
func Matches(k tea.KeyMsg, b ...Binding) bool {
|
||||
// Matches checks if the given key matches the given bindings.
|
||||
func Matches[Key fmt.Stringer](k Key, b ...Binding) bool {
|
||||
keys := k.String()
|
||||
for _, binding := range b {
|
||||
for _, v := range binding.keys {
|
||||
|
||||
Reference in New Issue
Block a user