Skip to content

Commit

Permalink
feat(key): accept any stringer interface to match keys (#584)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
aymanbagabas and meowgorithm authored Aug 15, 2024
1 parent ff5fb57 commit 5428d6d
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions key/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 5428d6d

Please sign in to comment.