core

package
v0.0.0-...-8aadb99 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Stdin is used by the Keys struct to read and write keys. It can be overwritten to use other file descriptors or custom io.Readers, such as the one used on Windows.

Functions

func CoordinatesCursor

func CoordinatesCursor(cur *Cursor, indent int) (x, y int)

CoordinatesCursor returns the number of real terminal lines above the cursor position (y value), and the number of columns since the beginning of the current line (x value). @indent - Used to align all lines (except the first) together on a single column.

func CoordinatesLine

func CoordinatesLine(l *Line, indent int) (x, y int)

CoordinatesLine returns the number of real terminal lines on which the input line spans, considering any contained newlines, any overflowing line, and the indent passed as parameter. The values also take into account an eventual suggestion added to the line before printing. Params: @indent - Coordinates to align all lines (except the first) together on a single column. Returns: @x - The number of columns, starting from the terminal left, to the end of the last line. @y - The number of actual lines on which the line spans, accounting for line wrap.

func DisplayLine

func DisplayLine(l *Line, indent int)

DisplayLine prints the line to stdout, starting at the current terminal cursor position, assuming it is at the end of the shell prompt string. Params: @indent - Used to align all lines (except the first) together on a single column.

func FlushUsed

func FlushUsed(keys *Keys)

FlushUsed drops the keys that have matched a given command.

func HighlightMatchers

func HighlightMatchers(sel *Selection)

HighlightMatchers adds highlighting to matching parens when the cursor is on one of them.

func MacroKeys

func MacroKeys(keys *Keys) []rune

MacroKeys returns the keys that have matched a given command, and thus can be recorded as a part of the current macro. This function is different from keys.Caller() in that it won't return keys that have only matched a prefix, to avoid recording them twice.

func MatchedKeys

func MatchedKeys(keys *Keys, matched []byte, args ...byte)

MatchedKeys is used to indicate how many keys have been evaluated against the shell commands in the dispatching process (regardless of if a command was matched or not). This function should normally not be used by external users of the library.

func MatchedPrefix

func MatchedPrefix(keys *Keys, prefix ...byte)

MatchedPrefix is similar to MatchedKeys, except that the provided keys should not be flushed, since they only matched some binds by prefix and that we need more keys for an exact match (or failure).

func PeekKey

func PeekKey(keys *Keys) (key byte, empty bool)

PeekKey returns the first key in the stack, without removing it.

func PopForce

func PopForce(keys *Keys) (key byte, empty bool)

PopForce is used to force-remove a key from the buffer, without marking it as having matched a bind command. This is used, for example, when the escape has been handled specially as a Vim escape.

func PopKey

func PopKey(keys *Keys) (key byte, empty bool)

PopKey is used to pop a key off the key stack without yet marking this key as having matched a bind command.

func ResetMatchers

func ResetMatchers(sel *Selection)

ResetMatchers is used by the display engine to reset matching parens highlighting regions.

func ResetPostRunIterations

func ResetPostRunIterations(iter *Iterations) (hint string)

ResetPostRunIterations resets the iterations if the last command didn't set them. If the reset operated on active iterations, this function returns true.

func WaitAvailableKeys

func WaitAvailableKeys(keys *Keys, cfg *inputrc.Config)

WaitAvailableKeys waits until an input key is either read from standard input, or directly returns if the key stack still/already has available keys.

Types

type Cursor

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

Cursor is the cursor position in the current line buffer. Contains methods to set, move, describe and check itself.

func NewCursor

func NewCursor(line *Line) *Cursor

NewCursor is a required constructor for the line cursor, because some default numeric values must be negative.

func (*Cursor) AtBeginningOfLine

func (c *Cursor) AtBeginningOfLine() bool

AtBeginningOfLine returns true if the cursor is either at the beginning of the line buffer, or on the first character after the previous newline.

func (*Cursor) AtEndOfLine

func (c *Cursor) AtEndOfLine() bool

AtEndOfLine returns true if the cursor is either at the end of the buffer, or if the character immediately following it is a newline.

func (*Cursor) BeginningOfLine

func (c *Cursor) BeginningOfLine()

BeginningOfLine moves the cursor to the beginning of the current line, (marked by a newline) or if no newline found, to the beginning of the buffer.

func (*Cursor) Char

func (c *Cursor) Char() rune

Char returns the rune (unicode point) under the cursor. If the line is empty, or if the cursor is appending to the line, the returned rune is 0 (rune(0)).

func (*Cursor) CheckAppend

func (c *Cursor) CheckAppend()

CheckAppend verifies that the current cursor position is neither negative, nor greater than the length of the input line. If either is true, the cursor will set its value as either 0, or the length of the line.

func (*Cursor) CheckCommand

func (c *Cursor) CheckCommand()

CheckCommand is like CheckAppend, but ensures the cursor position is never greater than the length of the line minus 1, since in Vim command mode, the cursor is on a char.

func (*Cursor) Dec

func (c *Cursor) Dec()

Dec decrements the cursor position by 1, if it's not at the beginning of the line.

func (*Cursor) EndOfLine

func (c *Cursor) EndOfLine()

EndOfLine moves the cursor to the end of the current line, (marked by a newline) or if no newline found, to the position of the last character in the buffer.

func (*Cursor) EndOfLineAppend

func (c *Cursor) EndOfLineAppend()

EndOfLineAppend moves the cursor to the end of either current line (if buffer is multiline), or the whole buffer, in append-mode.

func (*Cursor) Inc

func (c *Cursor) Inc()

Inc increments the cursor position by 1, if it's not at the end of the line.

func (*Cursor) InsertAt

func (c *Cursor) InsertAt(r ...rune)

InsertAt inserts the given runes into the line at the current cursor position.

func (*Cursor) LineMove

func (c *Cursor) LineMove(lines int)

LineMove moves the cursor by n lines either up (if the value is negative), or down (if positive). If greater than the length of possible lines above/below, the cursor will be set to either the first, or the last line of the buffer.

func (*Cursor) LinePos

func (c *Cursor) LinePos() int

LinePos returns the index of the current line on which the cursor is. A line is defined as a sequence of runes between one or two newline characters, between end and/or beginning of buffer, or a mix of both.

func (*Cursor) Mark

func (c *Cursor) Mark() int

Mark returns the current mark value of the cursor, or -1 if not set.

func (*Cursor) Move

func (c *Cursor) Move(offset int)

Move moves the cursor position by a relative value. If the end result is negative, the cursor is set to 0. If longer than the line, the cursor is set to length of line.

func (*Cursor) OnEmptyLine

func (c *Cursor) OnEmptyLine() bool

OnEmptyLine returns true if the rune under the current cursor position is a newline and that the preceding rune in the line is also a newline, or returns false.

func (*Cursor) Pos

func (c *Cursor) Pos() int

Pos returns the current cursor position. This function cannot return an invalid cursor position: it cannot be negative, nor it can be greater than the length of the line (note that it still can be out of line by 1).

func (*Cursor) ReplaceWith

func (c *Cursor) ReplaceWith(char rune)

ReplaceWith replaces the rune (unicode point) under the cursor with the provided one. If the cursor is appending to the line, the character is simply added at the end of it.

func (*Cursor) ResetMark

func (c *Cursor) ResetMark()

ResetMark resets the insertion point mark (-1).

func (*Cursor) Set

func (c *Cursor) Set(pos int)

Set sets the position of the cursor to an absolute value. If either negative or greater than the length of the line, the cursor will be set to either 0, or the length of the line.

func (*Cursor) SetMark

func (c *Cursor) SetMark()

SetMark sets the current cursor position as the mark.

func (*Cursor) ToFirstNonSpace

func (c *Cursor) ToFirstNonSpace(forward bool)

ToFirstNonSpace moves the cursor either backward or forward to the first character in the line that is not a space, a tab or a newline. If the current is not one, the cursor doesn't move. If the cursor is at the end of the line, the move is performed backward, regardless of the forward parameter value.

type Iterations

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

Iterations manages iterations for commands.

func (*Iterations) Add

func (i *Iterations) Add(times string)

Add accepts a string to be converted as an integer representing the number of times some action should be performed. The times parameter can also be a negative sign, in which case the iterations value will be negative until those are reset.

func (*Iterations) Get

func (i *Iterations) Get() int

Get returns the number of iterations (possibly negative), and resets the iterations to 1.

func (*Iterations) IsPending

func (i *Iterations) IsPending() bool

IsPending returns true if the very last command executed was an iteration one. This is only meant for the main readline loop/run.

func (*Iterations) IsSet

func (i *Iterations) IsSet() bool

IsSet returns true if an iteration/numeric argument is active.

func (*Iterations) Reset

func (i *Iterations) Reset()

Reset resets the iterations (drops them).

type Keys

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

Keys is used read, manage and use keys input by the shell user.

func (*Keys) Caller

func (k *Keys) Caller() (keys []rune)

Caller returns the keys that have matched the command currently being ran.

func (*Keys) Feed

func (k *Keys) Feed(begin bool, keys ...rune)

Feed can be used to directly add keys to the stack. If begin is true, the keys are added on the top of the stack, otherwise they are being appended to it.

func (*Keys) GetCursorPos

func (k *Keys) GetCursorPos() (x, y int)

GetCursorPos returns the current cursor position in the terminal. It is safe to call this function even if the shell is reading input.

func (*Keys) Pop

func (k *Keys) Pop() (key byte, empty bool)

Pop removes the first byte in the key stack (first read) and returns it. It returns either a key and the empty boolean set to false, or if no keys are present, returns a zero rune and empty set to true. The key bytes returned by this function are not those that have been matched against the current command. The keys returned here are only keys that have not yet been dispatched. (ex: di" will match vim delete-to, then select-inside, but the quote won't match a command and will be passed to select-inside. This function Pop() will thus return the quote.)

func (*Keys) ReadKey

func (k *Keys) ReadKey() (key rune, isAbort bool)

ReadKey reads keys from stdin like Read(), but immediately returns them instead of storing them in the stack, along with an indication on whether this key is an escape/abort one.

type Line

type Line []rune

Line is an input line buffer. Contains methods to search and modify its contents, split itself with tokenizers, and displaying itself.

func (*Line) Backward

func (l *Line) Backward(tokenizer Tokenizer, pos int) (adjust int)

Backward returns the offset to the beginning position of the previous (backward) token determined by the tokenizer function.

func (*Line) Cut

func (l *Line) Cut(bpos, epos int)

Cut deletes a slice of runes between a beginning and end position on the line. If the begin/end pos is negative/greater than the line, all runes located on valid indexes in the given range are removed.

func (*Line) CutRune

func (l *Line) CutRune(pos int)

CutRune deletes a rune at the given position in the line. If the position is out of bounds, nothing is deleted.

func (*Line) Find

func (l *Line) Find(char rune, pos int, forward bool) int

Find returns the index position of a target rune, or -1 if not found.

func (*Line) FindSurround

func (l *Line) FindSurround(char rune, pos int) (bpos, epos int, bchar, echar rune)

FindSurround returns the beginning and end positions of an enclosing rune (either matching signs -brackets- or the rune itself -quotes/letters-) and the enclosing chars.

func (*Line) Forward

func (l *Line) Forward(tokenizer Tokenizer, pos int) (adjust int)

Forward returns the offset to the beginning of the next (forward) token determined by the tokenizer function.

func (*Line) ForwardEnd

func (l *Line) ForwardEnd(tokenizer Tokenizer, pos int) (adjust int)

ForwardEnd returns the offset to the end of the next (forward) token determined by the tokenizer function.

func (*Line) Insert

func (l *Line) Insert(pos int, chars ...rune)

Insert inserts one or more runes at the given position. If the position is either negative or greater than the length of the line, nothing is inserted.

func (*Line) InsertBetween

func (l *Line) InsertBetween(bpos, epos int, chars ...rune)

InsertBetween inserts one or more runes into the line, between the specified begin and end position, effectively deleting everything in between those. If either or these positions is equal to -1, the selection content is inserted at the other position. If both are -1, nothing is done.

func (*Line) Len

func (l *Line) Len() int

Len returns the length of the line, as given by ut8.RuneCount. This should NOT confused with the length of the line in terms of how many terminal columns its printed representation will take.

func (*Line) Lines

func (l *Line) Lines() int

Lines returns the number of real lines in the input buffer. If there are no newlines, the result is 0, otherwise it's the number of lines - 1.

func (*Line) SelectBlankWord

func (l *Line) SelectBlankWord(pos int) (bpos, epos int)

SelectBlankWord returns the begin and end index positions of a full bigword (blank word) around the specified position.

func (*Line) SelectWord

func (l *Line) SelectWord(pos int) (bpos, epos int)

SelectWord returns the begin and end index positions of a word (separated by punctuation or spaces) around the specified position.

func (*Line) Set

func (l *Line) Set(chars ...rune)

Set replaces the line contents altogether with a new slice of characters. If no characters are passed, the line is thus made empty.

func (*Line) SurroundQuotes

func (l *Line) SurroundQuotes(single bool, pos int) (bpos, epos int)

SurroundQuotes returns the index positions of enclosing quotes around the given cursor position, provided that these quotes are really enclosing the inner selection (that is, that each of those quotes is not paired with another, outer quote). bpos or epos can be -1 if no quotes have been forward/backward found.

func (*Line) Tokenize

func (l *Line) Tokenize(cpos int) ([]string, int, int)

Tokenize splits the line on each word, that is, split on every punctuation or space.

func (*Line) TokenizeBlock

func (l *Line) TokenizeBlock(cpos int) ([]string, int, int)

TokenizeBlock splits the line into arguments delimited either by brackets, braces and parenthesis, and/or single and double quotes.

func (*Line) TokenizeSpace

func (l *Line) TokenizeSpace(cpos int) ([]string, int, int)

TokenizeSpace splits the line on each WORD (blank word), that is, split on every space.

type Selection

type Selection struct {
	Type string // Can be a normal one, surrounding (pairs), (cursor) matchers, etc.
	// contains filtered or unexported fields
}

Selection contains all regions of an input line that are currently selected/marked with either a begin and/or end position. The main selection is the visual one, used with the default cursor mark and position, and contains a list of additional surround selections used to change/select multiple parts of the line at once.

func NewSelection

func NewSelection(line *Line, cursor *Cursor) *Selection

NewSelection is a required constructor to use for initializing a selection, as some numeric values must be negative by default.

func (*Selection) Active

func (s *Selection) Active() bool

Active return true if the selection is active. When created, all selections are marked active, so that visual modes in Vim can work properly.

func (*Selection) Cursor

func (s *Selection) Cursor() int

Cursor returns what should be the cursor position if the active selection is to be deleted, but also works for yank operations.

func (*Selection) Cut

func (s *Selection) Cut() (buf string)

Cut deletes the current selection from the line, updates the cursor position and returns the deleted content, which can then be passed to the shell registers. After deletion, the selection is reset.

func (*Selection) Highlights

func (s *Selection) Highlights() (fg, bg string)

Highlights returns the highlighting sequences for the selection.

func (*Selection) InsertAt

func (s *Selection) InsertAt(bpos, epos int)

InsertAt insert the contents of the selection into the line, between the begin and end position, effectively deleting everything in between those.

If either or these positions is equal to -1, the selection content is inserted at the other position. If both are negative, nothing is done. This is equivalent to selection.Pop(), and line.InsertAt() combined.

After insertion, the selection is reset.

func (*Selection) IsVisual

func (s *Selection) IsVisual() bool

IsVisual indicates whether the selection should be highlighted.

func (*Selection) Len

func (s *Selection) Len() int

Len returns the length of the current selection. If any of begin/end pos is not set, the cursor position is used.

func (*Selection) Mark

func (s *Selection) Mark(pos int)

Mark starts a pending selection at the specified position in the line. If the position is out of the line bounds, no selection is started. If this function is called on a surround selection, nothing happens.

func (*Selection) MarkRange

func (s *Selection) MarkRange(bpos, epos int)

MarkRange starts a selection as a range in the input line. If either of begin/end pos are negative, it is replaced with the current cursor position. Any out of range positive value is replaced by the length of the line.

func (*Selection) MarkSurround

func (s *Selection) MarkSurround(bpos, epos int)

MarkSurround creates two distinct selections each containing one rune. The first area starts at bpos, and the second one at epos. If either bpos is negative or epos is > line.Len()-1, no selection is created.

func (*Selection) Pop

func (s *Selection) Pop() (buf string, bpos, epos, cpos int)

Pop returns the contents of the current selection as a string, as well as its begin and end position in the line, and the cursor position as given by the Cursor() method. Then, the selection is reset.

func (*Selection) Pos

func (s *Selection) Pos() (bpos, epos int)

Pos returns the begin and end positions of the selection. If any of these is not set, it is set to the cursor position. This is generally the case with "pending" visual selections.

func (*Selection) ReplaceWith

func (s *Selection) ReplaceWith(replacer func(r rune) rune)

ReplaceWith replaces all characters of the line within the current selection range by applying to each rune the provided replacer function. After replacement, the selection is reset.

func (*Selection) Reset

func (s *Selection) Reset()

Reset makes the current selection inactive, resetting all of its values.

func (*Selection) SelectABlankWord

func (s *Selection) SelectABlankWord() (bpos, epos int)

SelectABlankWord selects a bigword around the current cursor position, selecting leading or trailing spaces depending on where the cursor is: if on a blank space, in a word, or at the end of the line.

func (*Selection) SelectAShellWord

func (s *Selection) SelectAShellWord() (bpos, epos int)

SelectAShellWord selects a shell word around the cursor position, selecting leading or trailing spaces depending on where the cursor is: if on a blank space, in a word, or at the end of the line.

func (*Selection) SelectAWord

func (s *Selection) SelectAWord() (bpos, epos int)

SelectAWord selects a word around the current cursor position, selecting leading or trailing spaces depending on where the cursor is: if on a blank space, in a word, or at the end of the line.

func (*Selection) SelectKeyword

func (s *Selection) SelectKeyword(bpos, epos int, next bool) (kbpos, kepos int, match bool)

SelectKeyword attempts to find a pattern in the current blank word around the current cursor position, using various regular expressions. Repeatedly calling this function will cycle through all regex matches, or if a matcher captured multiple subgroups, through each of those groups.

Those are, in the order in which they are tried: URI / URL / Domain|IPv4|IPv6 / URL path component / URL parameters.

The returned positions are the beginning and end positions of the match on the line (absolute position, not relative to cursor), or if no matcher succeeds, the bpos and epos parameters are returned unchanged. If found is true, it means a match occurred, otherwise false is returned.

func (*Selection) Surround

func (s *Selection) Surround(bchar, echar rune)

Surround surrounds the selection with a begin and end character, effectively inserting those characters into the current input line. If epos is greater than the line length, the line length is used. After insertion, the selection is reset.

func (*Selection) Surrounds

func (s *Selection) Surrounds() []Selection

Surrounds returns all surround-selected regions contained by the selection.

func (*Selection) Text

func (s *Selection) Text() string

Text returns the current selection as a string, but does not reset it.

func (*Selection) Visual

func (s *Selection) Visual(line bool)

Visual sets the selection as a visual one (highlighted), which is commonly seen in Vim edition mode. If line is true, the visual is extended to entire lines.

type Tokenizer

type Tokenizer func(cursorPos int) (split []string, index int, newPos int)

Tokenizer is a method used by a (line) type to split itself according to different rules (split between spaces, punctuation, brackets, quotes, etc.).

Jump to

Keyboard shortcuts

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