From 5428d6ddecae63f7f06d8939f14f45c4e9bcab9f Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Thu, 15 Aug 2024 15:01:56 -0400 Subject: [PATCH] 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 * Update key/key.go Co-authored-by: Christian Rocha --------- Co-authored-by: Christian Rocha --- key/key.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/key/key.go b/key/key.go index c7888fa..0682665 100644 --- a/key/key.go +++ b/key/key.go @@ -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 {