Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(key): accept any stringer interface to match keys #584

Merged
merged 3 commits into from
Aug 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading