mirror of
https://github.com/peco/peco.git
synced 2026-09-10 07:16:29 -04:00
Merge pull request #636 from peco/split-action-interface
Simplify Action interface
This commit is contained in:
commit
62e667cce8
11
action.go
11
action.go
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue