input

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2021 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AbortSearchAndReturnToNormalMode

func AbortSearchAndReturnToNormalMode(s *state.EditorState)

func BeginNewLineAbove

func BeginNewLineAbove(s *state.EditorState)

func BeginNewLineBelow

func BeginNewLineBelow(s *state.EditorState)

func CommitSearchAndReturnToNormalMode

func CommitSearchAndReturnToNormalMode(s *state.EditorState)

func CursorBack

func CursorBack(s *state.EditorState)

func CursorDown

func CursorDown(s *state.EditorState)

func CursorLeft

func CursorLeft(s *state.EditorState)

func CursorLineEnd

func CursorLineEnd(s *state.EditorState)

func CursorLineEndIncludeEndOfLineOrFile

func CursorLineEndIncludeEndOfLineOrFile(s *state.EditorState)

func CursorLineStart

func CursorLineStart(s *state.EditorState)

func CursorLineStartNonWhitespace

func CursorLineStartNonWhitespace(s *state.EditorState)

func CursorNextParagraph

func CursorNextParagraph(s *state.EditorState)

func CursorNextWordEnd

func CursorNextWordEnd(s *state.EditorState)

func CursorNextWordStart

func CursorNextWordStart(s *state.EditorState)

func CursorPrevParagraph

func CursorPrevParagraph(s *state.EditorState)

func CursorPrevWordStart

func CursorPrevWordStart(s *state.EditorState)

func CursorRight

func CursorRight(s *state.EditorState)

func CursorRightIncludeEndOfLineOrFile

func CursorRightIncludeEndOfLineOrFile(s *state.EditorState)

func CursorStartOfLastLine

func CursorStartOfLastLine(s *state.EditorState)

func CursorUp

func CursorUp(s *state.EditorState)

func DeleteRuneFromMenuSearch

func DeleteRuneFromMenuSearch(s *state.EditorState)

func DeleteRuneFromSearchQuery

func DeleteRuneFromSearchQuery(s *state.EditorState)

func EmptyAction

func EmptyAction(s *state.EditorState)

EmptyAction is an action that does nothing.

func EnterInsertMode

func EnterInsertMode(s *state.EditorState)

func EnterInsertModeAtEndOfLine

func EnterInsertModeAtEndOfLine(s *state.EditorState)

func EnterInsertModeAtNextPos

func EnterInsertModeAtNextPos(s *state.EditorState)

func EnterInsertModeAtStartOfLine

func EnterInsertModeAtStartOfLine(s *state.EditorState)

func ExecuteSelectedMenuItem

func ExecuteSelectedMenuItem(s *state.EditorState)

func FindNextMatch

func FindNextMatch(s *state.EditorState)

func FindPrevMatch

func FindPrevMatch(s *state.EditorState)

func HideMenuAndReturnToNormalMode

func HideMenuAndReturnToNormalMode(s *state.EditorState)

func IndentLine

func IndentLine(s *state.EditorState)

func InsertNewlineAndUpdateAutoIndentWhitespace added in v0.2.0

func InsertNewlineAndUpdateAutoIndentWhitespace(s *state.EditorState)

func InsertTab

func InsertTab(s *state.EditorState)

func JoinLines

func JoinLines(s *state.EditorState)
func MenuSelectionDown(s *state.EditorState)
func MenuSelectionUp(s *state.EditorState)

func OutdentLine

func OutdentLine(s *state.EditorState)

func Redo

func Redo(s *state.EditorState)

func ReturnToNormalMode

func ReturnToNormalMode(s *state.EditorState)

func ReturnToNormalModeAfterInsert added in v0.2.0

func ReturnToNormalModeAfterInsert(s *state.EditorState)

func StartSearchBackward

func StartSearchBackward(s *state.EditorState)

func StartSearchForward

func StartSearchForward(s *state.EditorState)

func ToggleCaseAtCursor

func ToggleCaseAtCursor(s *state.EditorState)

func ToggleVisualModeCharwise

func ToggleVisualModeCharwise(s *state.EditorState)

func ToggleVisualModeLinewise

func ToggleVisualModeLinewise(s *state.EditorState)

func Undo

func Undo(s *state.EditorState)

Types

type Action

type Action func(*state.EditorState)

Action is a function that mutates the editor state.

func AppendRuneToMenuSearch

func AppendRuneToMenuSearch(r rune) Action

func AppendRuneToSearchQuery

func AppendRuneToSearchQuery(r rune) Action

func ChangeAWord

func ChangeAWord(clipboardPageNameArg *rune) Action

func ChangeInnerWord

func ChangeInnerWord(clipboardPageNameArg *rune) Action

func ChangeSelection

func ChangeSelection(clipboardPageNameArg *rune, selectionMode selection.Mode, selectionEndLoc state.Locator) Action

func ChangeToNextMatchingChar added in v0.2.0

func ChangeToNextMatchingChar(inputEvents []*tcell.EventKey, countArg *uint64, clipboardPageNameArg *rune, includeChar bool) Action

func ChangeToPrevMatchingChar added in v0.2.0

func ChangeToPrevMatchingChar(inputEvents []*tcell.EventKey, countArg *uint64, clipboardPageNameArg *rune, includeChar bool) Action

func ChangeToStartOfNextWord added in v0.2.0

func ChangeToStartOfNextWord(clipboardPageNameArg *rune) Action

func CopyAWord added in v0.2.0

func CopyAWord(clipboardPageNameArg *rune) Action

func CopyInnerWord added in v0.2.0

func CopyInnerWord(clipboardPageNameArg *rune) Action

func CopyLines

func CopyLines(clipboardPageNameArg *rune) Action

func CopySelectionAndReturnToNormalMode

func CopySelectionAndReturnToNormalMode(clipboardPageNameArg *rune) Action

func CopyToStartOfNextWord added in v0.2.0

func CopyToStartOfNextWord(clipboardPageNameArg *rune) Action

func CursorStartOfLineNum

func CursorStartOfLineNum(countArg *uint64) Action

func CursorToNextMatchingChar added in v0.2.0

func CursorToNextMatchingChar(inputEvents []*tcell.EventKey, countArg *uint64, includeChar bool) Action

func CursorToPrevMatchingChar added in v0.2.0

func CursorToPrevMatchingChar(inputEvents []*tcell.EventKey, countArg *uint64, includeChar bool) Action

func DeleteAWord

func DeleteAWord(clipboardPageNameArg *rune) Action

func DeleteDown

func DeleteDown(clipboardPageNameArg *rune) Action

func DeleteInnerWord

func DeleteInnerWord(clipboardPageNameArg *rune) Action

func DeleteLines added in v0.2.0

func DeleteLines(countArg *uint64, clipboardPageNameArg *rune) Action

func DeleteNextCharInLine

func DeleteNextCharInLine(countArg *uint64, clipboardPageNameArg *rune) Action

func DeletePrevChar

func DeletePrevChar(clipboardPageNameArg *rune) Action

func DeletePrevCharInLine

func DeletePrevCharInLine(clipboardPageNameArg *rune) Action

func DeleteSelection added in v0.2.0

func DeleteSelection(clipboardPageNameArg *rune, selectionMode selection.Mode, selectionEndLoc state.Locator, replaceWithEmptyLine bool) Action

func DeleteSelectionAndReturnToNormalMode

func DeleteSelectionAndReturnToNormalMode(clipboardPageNameArg *rune, selectionMode selection.Mode, selectionEndLoc state.Locator) Action

func DeleteToEndOfLine

func DeleteToEndOfLine(clipboardPageNameArg *rune) Action

func DeleteToNextMatchingChar added in v0.2.0

func DeleteToNextMatchingChar(inputEvents []*tcell.EventKey, countArg *uint64, clipboardPageNameArg *rune, includeChar bool) Action

func DeleteToPrevMatchingChar added in v0.2.0

func DeleteToPrevMatchingChar(inputEvents []*tcell.EventKey, countArg *uint64, clipboardPageNameArg *rune, includeChar bool) Action

func DeleteToStartOfLine

func DeleteToStartOfLine(clipboardPageNameArg *rune) Action

func DeleteToStartOfLineNonWhitespace

func DeleteToStartOfLineNonWhitespace(clipboardPageNameArg *rune) Action

func DeleteToStartOfNextWord added in v0.2.0

func DeleteToStartOfNextWord(clipboardPageNameArg *rune) Action

func DeleteUp

func DeleteUp(clipboardPageNameArg *rune) Action

func IndentSelectionAndReturnToNormalMode

func IndentSelectionAndReturnToNormalMode(selectionEndLoc state.Locator) Action

func InsertRune

func InsertRune(r rune) Action

func OutdentSelectionAndReturnToNormalMode

func OutdentSelectionAndReturnToNormalMode(selectionEndLoc state.Locator) Action

func PasteAfterCursor

func PasteAfterCursor(clipboardPageNameArg *rune) Action

func PasteBeforeCursor

func PasteBeforeCursor(clipboardPageNameArg *rune) Action

func ReplaceCharacter

func ReplaceCharacter(inputEvents []*tcell.EventKey) Action

func ScrollDown

func ScrollDown(config Config) Action

func ScrollUp

func ScrollUp(config Config) Action

func ShowCommandMenu

func ShowCommandMenu(config Config) Action

func ShowFileMenu

func ShowFileMenu(config Config) Action

func ToggleCaseInSelectionAndReturnToNormalMode

func ToggleCaseInSelectionAndReturnToNormalMode(selectionEndLoc state.Locator) Action

type ActionBuilder

type ActionBuilder func(p ActionBuilderParams) Action

ActionBuilder is invoked when the input parser accepts a sequence of keypresses matching a rule.

type ActionBuilderParams

type ActionBuilderParams struct {
	InputEvents          []*tcell.EventKey
	CountArg             *uint64
	ClipboardPageNameArg *rune
	MacroRecorder        *MacroRecorder
	Config               Config
}

type Config

type Config struct {
	// InputMode is the current input mode of the editor.
	InputMode state.InputMode

	// ScrollLines is the number of lines to scroll up or down with Ctrl-U / Ctrl-D.
	ScrollLines uint64

	// Glob patterns for directories to hide from file search.
	DirPatternsToHide []string

	// Information about the current selection (visual mode).
	// If not in visual mode, the mode will be selection.ModeNone
	// and the end locator will be nil.
	SelectionMode       selection.Mode
	SelectionEndLocator state.Locator
}

Config controls how user input is interpreted.

type EventMatcher

type EventMatcher struct {
	Wildcard bool      // If true, matches every input key.
	Key      tcell.Key // The kind of key to match (usually tcell.KeyRune)
	Rune     rune      // If the key is tcell.KeyRune, match this rune.
}

EventMatcher matches an input key event.

func (*EventMatcher) Matches

func (em *EventMatcher) Matches(event *tcell.EventKey) bool

Matches returns whether the input event is a match.

type Interpreter

type Interpreter struct {
	// contains filtered or unexported fields
}

Interpreter translates key events to commands.

func NewInterpreter

func NewInterpreter() *Interpreter

NewInterpreter creates a new interpreter.

func (*Interpreter) InputBufferString added in v0.2.0

func (inp *Interpreter) InputBufferString(mode state.InputMode) string

InputBufferString returns a string describing buffered input events. It can be displayed to the user to help them understand the input state.

func (*Interpreter) ProcessEvent

func (inp *Interpreter) ProcessEvent(event tcell.Event, config Config) Action

ProcessEvent interprets a terminal input event as an action. (If there is no action, then EmptyAction will be returned.)

type MacroRecorder

type MacroRecorder struct {
	// contains filtered or unexported fields
}

MacroRecorder records actions to be replayed later.

func NewMacroRecorder

func NewMacroRecorder() *MacroRecorder

NewMacroRecorder constructs a new macro recorder.

func (*MacroRecorder) ClearLastAction

func (m *MacroRecorder) ClearLastAction()

ClearLastAction resets the "last action" to be replayed.

func (*MacroRecorder) LastAction

func (m *MacroRecorder) LastAction() Action

LastAction returns an action that replays the last action. The "last" action is the sequence of all actions recorded since the recorder was created or last cleared. For example, if the user might press "o" in normal mode to start a new line, type "abc" in insert mode, then return to normal mode. The last action in this case would BOTH start a new line AND insert the text "abc".

func (*MacroRecorder) RecordAction

func (m *MacroRecorder) RecordAction(f Action)

RecordAction records an action to be replayed later.

type Mode

type Mode interface {
	// ProcessKeyEvent interprets the key event according to this mode.
	// It will return any user-initiated action resulting from the keypress
	ProcessKeyEvent(event *tcell.EventKey, macroRecorder *MacroRecorder, config Config) Action

	// InputBufferString returns a string describing buffered input events.
	// It can be displayed to the user to help them understand the input state.
	InputBufferString() string
}

Mode represents an input mode, which is a way of interpreting key events.

type ParseResult

type ParseResult struct {
	// Accepted indicates whether the input sequence was accepted.
	// The following fields are set only if Accepted is true.
	Accepted bool

	// Rule is the rule triggered by the sequence of input key events.
	Rule Rule

	// Input is the sequence of key events that triggered the rule.
	Input []*tcell.EventKey

	// Count is the parsed count parameter, if provided.
	// For example, `5x` (delete five characters) would have count set to 5.
	// If provided, the count will always be at least one and at most math.MaxInt64.
	// If no count parameter was provided, this will be nil.
	Count *uint64

	// ClipboardPageName is the name of the page to copy or paste.
	// For example `"ap` means "paste clipboard page named 'a'"
	// If not provided, this will be nil.
	ClipboardPageName *rune
}

ParseResult is the result of parsing an input key event.

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

Parser parses a sequence of input key events based on a set of rules. It parses input incrementally, waiting for a key that will trigger some rule. If the input is rejected by all rules, the parser resets.

func NewParser

func NewParser(rules []Rule) *Parser

NewParser constructs a new parser for a set of rules.

func (*Parser) InputBufferString added in v0.2.0

func (p *Parser) InputBufferString() string

InputBufferString returns a string describing buffered input events. This can be displayed to the user to help them understand the input state.

func (*Parser) ProcessInput

func (p *Parser) ProcessInput(event *tcell.EventKey) ParseResult

ProcessInput processes an input event key. If a rule accepts the sequence of key presses, the parser returns the accepted sequence, triggered rule, and parsed count parameter. If all rules reject the sequence, the parser resets.

type Rule

type Rule struct {
	Name          string
	Pattern       []EventMatcher
	ActionBuilder ActionBuilder
	SkipMacro     bool
}

Rule defines a command that the input parser can recognize. The pattern is a sequence of keypresses that trigger the rule.

Jump to

Keyboard shortcuts

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