Merge pull request #636 from peco/split-action-interface

Simplify Action interface
This commit is contained in:
lestrrat 2026-02-17 07:30:52 +09:00 committed by GitHub
commit 62e667cce8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 11 deletions

View file

@ -43,9 +43,9 @@ func (a ActionFunc) registerKeySequence(k keyseq.KeyList) {
defaultKeyBinding[k.String()] = a
}
// Register fulfills the Action interface for AfterFunc. Registers `a`
// into the global action registry by the name `name`, and maps to
// default keys via `defaultKeys`
// Register registers `a` into the global action registry by the name
// `name`, and maps to default keys via `defaultKeys`. Called during
// package init() to set up built-in actions.
func (a ActionFunc) Register(name string, defaultKeys ...keyseq.KeyType) {
nameToActions["peco."+name] = a
for _, k := range defaultKeys {
@ -53,8 +53,9 @@ func (a ActionFunc) Register(name string, defaultKeys ...keyseq.KeyType) {
}
}
// RegisterKeySequence satisfies the Action interface for AfterFunc.
// Registers the action to be mapped against a key sequence
// RegisterKeySequence registers the action to be mapped against a
// multi-key sequence. Called during package init() for actions like
// KonamiCommand.
func (a ActionFunc) RegisterKeySequence(name string, k keyseq.KeyList) {
nameToActions["peco."+name] = a
a.registerKeySequence(k)

View file

@ -281,13 +281,8 @@ type Filter struct {
prevMu sync.Mutex
}
// Action describes an action that can be executed upon receiving user
// input. It's an interface so you can create any kind of Action you need,
// but most everything is implemented in terms of ActionFunc, which is
// callback based Action
// Action describes an action that can be executed upon receiving user input.
type Action interface {
Register(string, ...keyseq.KeyType)
RegisterKeySequence(string, keyseq.KeyList)
Execute(context.Context, *Peco, Event)
}