Cursor is the cursor position in the current line buffer.
Contains methods to set, move, describe and check itself. AtBeginningOfLine returns true if the cursor is either at the beginning
of the line buffer, or on the first character after the previous newline. AtEndOfLine returns true if the cursor is either at the end of the
buffer, or if the character immediately following it is a newline. 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. 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)). 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. 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. Dec decrements the cursor position by 1,
if it's not at the beginning of the line. 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. EndOfLineAppend moves the cursor to the end of either current line
(if buffer is multiline), or the whole buffer, in append-mode. Inc increments the cursor position by 1,
if it's not at the end of the line. InsertAt inserts the given runes into the line at the current cursor position. 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. 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. Mark returns the current mark value of the cursor, or -1 if not set. 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. 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. 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). 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. ResetMark resets the insertion point mark (-1). 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. SetMark sets the current cursor position as the mark. 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.
func NewCursor(line *Line) *Cursor
func github.com/reeflective/readline/internal/completion.(*Engine).GetBuffer() (*Line, *Cursor, *Selection)
func github.com/reeflective/readline/internal/completion.(*Engine).Line() (*Line, *Cursor)
func github.com/reeflective/readline.(*Shell).Cursor() *Cursor
func CoordinatesCursor(cur *Cursor, indent int) (x, y int)
func NewSelection(line *Line, cursor *Cursor) *Selection
func github.com/reeflective/readline/internal/completion.AutopairDelete(line *Line, cur *Cursor)
func github.com/reeflective/readline/internal/completion.AutopairInsertOrJump(key rune, line *Line, cur *Cursor) (skipInsert bool)
func github.com/reeflective/readline/internal/completion.Init(eng *completion.Engine, k *Keys, l *Line, cur *Cursor, s *Selection, comp completion.Completer)
func github.com/reeflective/readline/internal/history.NewSources(line *Line, cur *Cursor, hint *ui.Hint, opts *inputrc.Config) *history.Sources
func github.com/reeflective/readline/internal/history.(*Sources).InsertMatch(line *Line, cur *Cursor, usePos, fwd, regexp bool)
func github.com/reeflective/readline/internal/ui.NewPrompt(line *Line, cursor *Cursor, keymaps *keymap.Engine, opts *inputrc.Config) *ui.Prompt
Iterations manages iterations for commands. 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. Get returns the number of iterations (possibly
negative), and resets the iterations to 1. IsPending returns true if the very last command executed was an
iteration one. This is only meant for the main readline loop/run. IsSet returns true if an iteration/numeric argument is active. Reset resets the iterations (drops them).
func ResetPostRunIterations(iter *Iterations) (hint string)
func github.com/reeflective/readline/internal/keymap.NewEngine(keys *Keys, i *Iterations, opts ...inputrc.Option) (*keymap.Engine, *inputrc.Config)
Keys is used read, manage and use keys input by the shell user. Caller returns the keys that have matched the command currently being ran. 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. GetCursorPos returns the current cursor position in the terminal.
It is safe to call this function even if the shell is reading input. 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.) 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.
func FlushUsed(keys *Keys)
func MacroKeys(keys *Keys) []rune
func MatchedKeys(keys *Keys, matched []byte, args ...byte)
func MatchedPrefix(keys *Keys, prefix ...byte)
func PeekKey(keys *Keys) (key byte, empty bool)
func PopForce(keys *Keys) (key byte, empty bool)
func PopKey(keys *Keys) (key byte, empty bool)
func WaitAvailableKeys(keys *Keys, cfg *inputrc.Config)
func github.com/reeflective/readline/internal/completion.Init(eng *completion.Engine, k *Keys, l *Line, cur *Cursor, s *Selection, comp completion.Completer)
func github.com/reeflective/readline/internal/display.NewEngine(k *Keys, s *Selection, h *history.Sources, p *ui.Prompt, i *ui.Hint, c *completion.Engine, opts *inputrc.Config) *display.Engine
func github.com/reeflective/readline/internal/keymap.NewEngine(keys *Keys, i *Iterations, opts ...inputrc.Option) (*keymap.Engine, *inputrc.Config)
func github.com/reeflective/readline/internal/macro.NewEngine(keys *Keys, hint *ui.Hint) *macro.Engine
Line is an input line buffer.
Contains methods to search and modify its contents,
split itself with tokenizers, and displaying itself. Backward returns the offset to the beginning position of the previous
(backward) token determined by the tokenizer function. 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. CutRune deletes a rune at the given position in the line.
If the position is out of bounds, nothing is deleted. Find returns the index position of a target rune, or -1 if not found. 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. Forward returns the offset to the beginning of the next
(forward) token determined by the tokenizer function. ForwardEnd returns the offset to the end of the next
(forward) token determined by the tokenizer function. 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. 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. 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. 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. SelectBlankWord returns the begin and end index positions
of a full bigword (blank word) around the specified position. SelectWord returns the begin and end index positions of a word
(separated by punctuation or spaces) around the specified position. Set replaces the line contents altogether with a new slice of characters.
If no characters are passed, the line is thus made empty. 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. Tokenize splits the line on each word, that is, split on every punctuation or space. TokenizeBlock splits the line into arguments delimited either by
brackets, braces and parenthesis, and/or single and double quotes. TokenizeSpace splits the line on each WORD (blank word), that is, split on every space.
func github.com/reeflective/readline/internal/completion.(*Engine).GetBuffer() (*Line, *Cursor, *Selection)
func github.com/reeflective/readline/internal/completion.(*Engine).Line() (*Line, *Cursor)
func github.com/reeflective/readline/internal/history.(*Sources).Suggest(line *Line) Line
func github.com/reeflective/readline.(*Shell).Line() *Line
func CoordinatesLine(l *Line, indent int) (x, y int)
func DisplayLine(l *Line, indent int)
func NewCursor(line *Line) *Cursor
func NewSelection(line *Line, cursor *Cursor) *Selection
func github.com/reeflective/readline/internal/completion.AutopairDelete(line *Line, cur *Cursor)
func github.com/reeflective/readline/internal/completion.AutopairInsertOrJump(key rune, line *Line, cur *Cursor) (skipInsert bool)
func github.com/reeflective/readline/internal/completion.Init(eng *completion.Engine, k *Keys, l *Line, cur *Cursor, s *Selection, comp completion.Completer)
func github.com/reeflective/readline/internal/history.NewSources(line *Line, cur *Cursor, hint *ui.Hint, opts *inputrc.Config) *history.Sources
func github.com/reeflective/readline/internal/history.(*Sources).InsertMatch(line *Line, cur *Cursor, usePos, fwd, regexp bool)
func github.com/reeflective/readline/internal/history.(*Sources).Suggest(line *Line) Line
func github.com/reeflective/readline/internal/ui.NewPrompt(line *Line, cursor *Cursor, keymaps *keymap.Engine, opts *inputrc.Config) *ui.Prompt
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. // Can be a normal one, surrounding (pairs), (cursor) matchers, etc. Active return true if the selection is active.
When created, all selections are marked active,
so that visual modes in Vim can work properly. Cursor returns what should be the cursor position if the active
selection is to be deleted, but also works for yank operations. 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. Highlights returns the highlighting sequences for the selection. 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. IsVisual indicates whether the selection should be highlighted. Len returns the length of the current selection. If any
of begin/end pos is not set, the cursor position is used. 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. 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. 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. 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. 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. 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. Reset makes the current selection inactive, resetting all of its values. 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. 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. 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. 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. 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. Surrounds returns all surround-selected regions contained by the selection. Text returns the current selection as a string, but does not reset it. 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.
func NewSelection(line *Line, cursor *Cursor) *Selection
func (*Selection).Surrounds() []Selection
func github.com/reeflective/readline/internal/completion.(*Engine).GetBuffer() (*Line, *Cursor, *Selection)
func github.com/reeflective/readline.(*Shell).Selection() *Selection
func HighlightMatchers(sel *Selection)
func ResetMatchers(sel *Selection)
func github.com/reeflective/readline/internal/completion.Init(eng *completion.Engine, k *Keys, l *Line, cur *Cursor, s *Selection, comp completion.Completer)
func github.com/reeflective/readline/internal/display.NewEngine(k *Keys, s *Selection, h *history.Sources, p *ui.Prompt, i *ui.Hint, c *completion.Engine, opts *inputrc.Config) *display.Engine
Tokenizer is a method used by a (line) type to split itself according to
different rules (split between spaces, punctuation, brackets, quotes, etc.).
func (*Line).Backward(tokenizer Tokenizer, pos int) (adjust int)
func (*Line).Forward(tokenizer Tokenizer, pos int) (adjust int)
func (*Line).ForwardEnd(tokenizer Tokenizer, pos int) (adjust int)
Package-Level Functions (total 16)
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.
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.
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.
FlushUsed drops the keys that have matched a given command.
HighlightMatchers adds highlighting to matching
parens when the cursor is on one of them.
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.
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.
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).
NewCursor is a required constructor for the line cursor,
because some default numeric values must be negative.
NewSelection is a required constructor to use for initializing
a selection, as some numeric values must be negative by default.
PeekKey returns the first key in the stack, without removing it.
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.
PopKey is used to pop a key off the key stack without
yet marking this key as having matched a bind command.
ResetMatchers is used by the display engine
to reset matching parens highlighting regions.
ResetPostRunIterations resets the iterations if the last command didn't set them.
If the reset operated on active iterations, this function returns true.
WaitAvailableKeys waits until an input key is either read from standard input,
or directly returns if the key stack still/already has available keys.
Package-Level Variables (only one)
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.
The pages are generated with Goldsv0.8.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.