input

package
v0.9.11 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

TODO: this should be moved to 'control/editor' imo

Index

Constants

View Source
const (
	// TextEditModeNormal is the "normal mode" of the editor, i.E. key inputs are
	// not used for input directly, but for navigation and manipulation of the
	// text.
	TextEditModeNormal = 0
	// TextEditModeInsert is the "insert mode" of the editor, i.E. key inputs are
	// used for input directly.
	TextEditModeInsert = 1
)

Variables

This section is empty.

Functions

func ToConfigIdentifierString

func ToConfigIdentifierString(k Key) string

ToConfigIdentifierString converts the given key to its configuration identfier.

Types

type Actionspec added in v0.8.0

type Actionspec string

type CapturingOverlay

type CapturingOverlay struct {
	Processor SimpleInputProcessor
}

CapturingOverlay is a wrapper over a SimpleInputProcessor that always claims to capture input, which can be a desirable behavior for modal overlays.

func CapturingOverlayWrap

func CapturingOverlayWrap(s SimpleInputProcessor) *CapturingOverlay

CapturingOverlayWrap returns a wrapper over the given SimpleInputProcessor that always captures all input.

func (*CapturingOverlay) CapturesInput

func (o *CapturingOverlay) CapturesInput() bool

CapturesInput returns whether this processor "captures" input, i.E. whether it ought to take priority in processing over other processors; this is always the case for the capturing overlay.

func (*CapturingOverlay) GetHelp

func (o *CapturingOverlay) GetHelp() Help

GetHelp returns the input help map for this processor.

func (*CapturingOverlay) ProcessInput

func (o *CapturingOverlay) ProcessInput(k Key) bool

ProcessInput attempts to process the provided input. Returns whether the provided input "applied", i.E. the processor performed an action based on the input. This defers to the underlying processor.

type Help

type Help = map[string]string

Help describes an input-description to action-description mapping.

type InputConfig added in v0.8.0

type InputConfig struct {
	Editor       map[Keyspec]Actionspec `yaml:"editor"`
	StringEditor ModedSpec              `yaml:"string-editor"`
}

type Key

type Key struct {
	Mod tcell.ModMask
	Key tcell.Key
	Ch  rune
}

Key represents a key input.

NOTE:

currently barely generifying tcell's input type; could eventually be
properly generified for other input sources.

func ConfigKeyspecToKeys

func ConfigKeyspecToKeys(spec Keyspec) ([]Key, error)

ConfigKeyspecToKeys converts full key sequence specification strings (e.g. "<space>qw" meaning the SPACE key, then the Q key, then the W key) to the appropriate sequence of Keys (or an error, if invalid).

func KeyFromTcellEvent

func KeyFromTcellEvent(e *tcell.EventKey) Key

KeyFromTcellEvent formats a tcell.EventKey to a Key as this package expects it. Any Key for a tcell.EventKey should be converted by this function.

func KeyIdentifierToKey

func KeyIdentifierToKey(identifier string) (Key, error)

KeyIdentifierToKey converts the given special identifier to the appropriate key (or an error, if invalid).

func (*Key) ToDebugString

func (k *Key) ToDebugString() string

ToDebugString returns a debug string for this key.

type Keyspec added in v0.8.0

type Keyspec string

type ModalInputProcessor

type ModalInputProcessor interface {
	SimpleInputProcessor

	// ApplyModalOverlay applies an overlay to this processor.
	// It returns the processors index, by which in the future, all overlays down
	// to and including this overlay can be removed
	ApplyModalOverlay(SimpleInputProcessor) (index uint)

	// PopModalOverlay removes the topmost overlay from this processor.
	PopModalOverlay() error

	// PopModalOverlays pops all overlays down to and including the one at the
	// specified index.
	PopModalOverlays(index uint)
}

ModalInputProcessor is an input processor that (additionally to SimpleInputProcessor) can be temporarily overlaid with any number of additional input processors, which can be removed one-by-one of the top or by their indices.

type ModedSpec added in v0.8.0

type ModedSpec struct {
	Normal map[Keyspec]Actionspec `yaml:"normal"`
	Insert map[Keyspec]Actionspec `yaml:"insert"`
}

type Modename added in v0.8.0

type Modename string

type Node

type Node struct {
	Children map[Key]*Node
	Action   action.Action
}

Node is a node in a Tree. It can have child nodes or an action.

NOTE:

must not have children if it has an action, and must not have an action if
it has children.

func NewLeaf

func NewLeaf(action action.Action) *Node

NewLeaf returns a pointer to a new action leaf Node without children.

NOTE: to construct an intermediate node with no aciton, prefer NewNode.

func NewNode

func NewNode() *Node

NewNode returns a pointer to a new empty node Node with initialized children.

NOTE: to construct a leaf with an action, prefer NewLeaf.

func (*Node) Child

func (n *Node) Child(k Key) (child *Node)

Child returns the child node for the given Key. Returns nil, if there is no child node for the key.

func (*Node) GetHelp

func (n *Node) GetHelp() Help

GetHelp returns help for this Node.

type SimpleInputProcessor

type SimpleInputProcessor interface {

	// CapturesInput returns whether this processor "captures" input, i.E. whether
	// it ought to take priority in processing over other processors.
	// This is useful, e.g., for prioritizing processors with partial input
	// sequences or for such overlays, that are to take complete priority by
	// completely gobbling all input.
	CapturesInput() bool

	// ProcessInput attempts to process the provided input.
	// Returns whether the provided input "applied", i.E. the processor performed
	// an action based on the input.
	ProcessInput(key Key) bool

	// GetHelp returns the input help map for this processor.
	GetHelp() Help
}

SimpleInputProcessor can process the input it is configured for and provide help information for that configuration. It can also "capture" input to ensure its precedence over other processors, e.g. when it has partial input.

type TextEditMode

type TextEditMode = int

TextEditMode enumerates the possible modes of modal text editing.

type Tree

type Tree struct {
	Root    *Node
	Current *Node
}

Tree represents an input tree, which can contain various input sequences that terminate in an action.

Example:

tree:                       mapping:

x
+-y
| +-z   -> action1          "xyz" -> action1
+-z     -> action2          "xz"  -> action2
z       -> action3          "z"   -> action3

func ConstructInputTree

func ConstructInputTree(
	spec map[Keyspec]action.Action,
) (*Tree, error)

ConstructInputTree construct a Tree for the given mappings of input sequence strings to actions. If the given mapping is invalid, this returns an error.

func EmptyTree

func EmptyTree() *Tree

EmptyTree returns a pointer to an empty tree.

func (*Tree) CapturesInput

func (t *Tree) CapturesInput() bool

CapturesInput returns whether this processor "captures" input, i.E. whether it ought to take priority in processing over other processors. This is useful, e.g., for prioritizing processors with partial input sequences or for such overlays, that are to take complete priority by completely gobbling all input.

func (*Tree) GetHelp

func (t *Tree) GetHelp() Help

GetHelp returns help for this Tree.

func (*Tree) ProcessInput

func (t *Tree) ProcessInput(k Key) (applied bool)

ProcessInput attempts to process the provided input. Returns whether the provided input "applied", i.E. the processor performed an action based on the input.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳