bind

package
v1.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 10, 2026 License: MIT Imports: 10 Imported by: 0

README

bind

Package bind is a key binding engine. It checks incoming key events against all registered key bindings to determine whether an action should be fired. bind uses a trie data structure, implemented in the bind/trie package, to describe sequences of keys.

As distinct from a traditional trie, in which nodes have a fixed value, bind's trie also supports regex values. Key events are stringified and then compared against the regex pattern to determine if the state machine should transition to that node.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewScope

func NewScope[T any](source interface{}) *trie.Trie[T]

Types

type Action added in v0.1.5

type Action struct {
	// An arbitrary string tag stored alongside the binding.
	// Used just for docs, for now.
	Tag string
	// The Janet callback invoked when this binding is fired.
	Callback *janet.Function
}

type ActionEvent

type ActionEvent[T any] struct {
	Action   T
	Engine   *Engine[T]
	Source   *trie.Trie[T]
	Sequence []string
	// Any regex traversals that matched
	Args []string
}

An action was triggered

type BindEvent added in v0.1.5

type BindEvent = ActionEvent[Action]

type BindScope added in v0.1.5

type BindScope = trie.Trie[Action]

func NewBindScope added in v0.1.5

func NewBindScope(source interface{}) *BindScope

type Engine

type Engine[T any] struct {
	deadlock.RWMutex
	// contains filtered or unexported fields
}

func NewEngine

func NewEngine[T any]() *Engine[T]

func Run added in v0.1.16

func Run[T any](ctx context.Context, binds *trie.Trie[T]) *Engine[T]

func (*Engine[T]) Input

func (e *Engine[T]) Input(data []byte)

Process input and produce events.

Bracketed paste sequences (\x1b[200~...\x1b[201~) require both markers to be present for the parser to recognize them. Some terminal emulators split the paste across multiple Write calls, so the start and end markers arrive in separate Input invocations. Without buffering, the orphaned start marker would be consumed as an UnknownCSISequenceEvent and the paste content would be misinterpreted as individual key events. To handle this, when we see a start marker with no matching end marker, we save the trailing bytes and prepend them to the next call.

func (*Engine[T]) InputMessage added in v0.1.5

func (e *Engine[T]) InputMessage(msg taro.Msg) (consumed bool)

InputMessage directly passes a taro.Msg (which is typically a taro.KeyMsg) into the binding engine. If the key was "consumed", or produced either a partial or full match, InputMessage returns true.

func (*Engine[T]) Poll

func (e *Engine[T]) Poll(ctx context.Context)

func (*Engine[T]) Recv

func (e *Engine[T]) Recv() <-chan Event

func (*Engine[T]) Scopes

func (e *Engine[T]) Scopes() []*trie.Trie[T]

func (*Engine[T]) SetScopes

func (e *Engine[T]) SetScopes(scopes ...*trie.Trie[T])

type Event

type Event interface{}

type Match

type Match[T any] struct {
	Bind   trie.Leaf[T]
	Source *trie.Trie[T]
}

type PartialEvent

type PartialEvent[T any] struct {
	Prefix  []string
	Matches []Match[T]
}

There are partial matches

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL