completion

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: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AutopairDelete

func AutopairDelete(line *core.Line, cur *core.Cursor)

AutopairDelete checks if the character under the cursor is an opening pair character which is immediately followed by its closing equivalent. If yes, the closing character is removed.

func AutopairInsertOrJump

func AutopairInsertOrJump(key rune, line *core.Line, cur *core.Cursor) (skipInsert bool)

AutopairInsertOrJump checks if the character to be inserted in the line is a pair character. If the character is an opening one, its inserted along with its closing equivalent. If it's a closing one and the next character in line is the same, the cursor jumps over it.

func Coordinates

func Coordinates(e *Engine) int

Coordinates returns the number of terminal rows used when displaying the completions with Display().

func Display

func Display(eng *Engine, maxRows int)

Display prints the current completion list to the screen, respecting the current display and completion settings.

func Init

func Init(eng *Engine, k *core.Keys, l *core.Line, cur *core.Cursor, s *core.Selection, comp Completer)

Init is used once at shell creation time to pass further parameters to the engine.

func UpdateInserted

func UpdateInserted(eng *Engine)

UpdateInserted should be called only once in between the two shell keymaps (local/main) in the main readline loop, to either drop or confirm a virtually inserted candidate.

Types

type Candidate

type Candidate struct {
	Value       string // Value is the value of the completion as actually inserted in the line
	Display     string // When display is not nil, this string is used to display the completion in the menu.
	Description string // A description to display next to the completion candidate.
	Style       string // An arbitrary string of color/text effects to use when displaying the completion.
	Tag         string // All completions with the same tag are grouped together and displayed under the tag heading.
	// contains filtered or unexported fields
}

Candidate represents a completion candidate.

type Completer

type Completer func() Values

Completer is a function generating completions. This is generally used so that a given completer function (history, registers, etc) can be cached and reused by the engine.

type Engine

type Engine struct {

	// Incremental search
	IsearchRegex *regexp.Regexp // Holds the current search regex match
	// contains filtered or unexported fields
}

Engine is responsible for all completion tasks: generating, computing, displaying and updating completion values and inserted candidates.

func NewEngine

func NewEngine(h *ui.Hint, km *keymap.Engine, o *inputrc.Config) *Engine

NewEngine initializes a new completion engine with the shell operating parameters.

func (*Engine) AutoCompleting

func (e *Engine) AutoCompleting() bool

AutoCompleting returns true if the completion engine is an autocompletion mode that has been triggered by a particular command (like history-search-forward/backward).

func (*Engine) Autocomplete

func (e *Engine) Autocomplete()

Autocomplete generates the correct completions in autocomplete mode. We don't do it when we are currently in the completion keymap, since that means completions have already been computed.

func (*Engine) AutocompleteForce

func (e *Engine) AutocompleteForce()

AutocompleteForce forces as-you-type autocomplete on the real input line, even if the current cursor position is 0.

func (*Engine) Cancel

func (e *Engine) Cancel(inserted, cached bool)

Cancel exits the current completions with the following behavior: - If inserted is true, any inserted candidate is removed. - If cached is true, any cached completer function is dropped.

This function does not exit the completion keymap, so any active completion menu will still be kept/displayed.

func (*Engine) ClearMenu

func (e *Engine) ClearMenu(completions bool)

ClearMenu exits the current completion keymap (if set) and clears the current list of generated completions (if completions is true).

func (*Engine) CompleteSyntax

func (e *Engine) CompleteSyntax(completer func([]rune, int) ([]rune, int))

CompleteSyntax updates the line with either user-defined syntax completers, or with the builtin ones.

func (*Engine) Generate

func (e *Engine) Generate(completions Values)

Generate uses a list of completions to group/order and prepares completions before printing them. If either no completions or only one is available after all constraints are applied, the engine will automatically insert/accept and/or reset itself.

func (*Engine) GenerateWith

func (e *Engine) GenerateWith(completer Completer)

GenerateWith generates completions with a completer function, itself cached so that the next time it must update its results, it can reuse this completer.

func (*Engine) GetBuffer

func (e *Engine) GetBuffer() (*core.Line, *core.Cursor, *core.Selection)

GetBuffer returns the correct input line buffer (and its cursor/ selection) depending on the context and active components: - If in non/incremental-search mode, the minibuffer. - If a completion is currently inserted, the completed line. - If neither of the above, the normal input line.

func (*Engine) IsActive

func (e *Engine) IsActive() bool

IsActive indicates if the engine is currently in possession of a non-empty list of generated completions (following all constraints).

func (*Engine) IsInserting

func (e *Engine) IsInserting() bool

IsInserting returns true if a candidate is currently virtually inserted.

func (*Engine) IsearchStart

func (e *Engine) IsearchStart(name string, autoinsert, replaceLine bool)

IsearchStart starts incremental search (fuzzy-finding) with values matching the isearch minibuffer as a regexp.

func (*Engine) IsearchStop

func (e *Engine) IsearchStop(revertLine bool)

IsearchStop exists the incremental search mode, and drops the currently used regexp matcher. If revertLine is true, the original line is restored.

func (*Engine) Line

func (e *Engine) Line() (*core.Line, *core.Cursor)

Line returns the relevant input line at the time this function is called: if a candidate is currently selected, the line returned is the one containing the candidate. If no candidate is selected, the normal input line is returned. When the line returned is the completed one, the corresponding, adjusted cursor.

func (*Engine) Matches

func (e *Engine) Matches() int

Matches returns the number of completion candidates matching the current line/settings requirements.

func (*Engine) NonIncrementallySearching

func (e *Engine) NonIncrementallySearching() (searching, forward, substring bool)

NonIncrementallySearching returns true if the completion engine is currently using a minibuffer for non-incremental search mode.

func (*Engine) NonIsearchStart

func (e *Engine) NonIsearchStart(name string, repeat, forward, substring bool)

NonIsearchStart starts a non-incremental, fake search mode: it does not produce or tries to match against completions, but uses a minibuffer similarly to incremental search mode.

func (*Engine) NonIsearchStop

func (e *Engine) NonIsearchStop()

NonIsearchStop exits the non-incremental search mode.

func (*Engine) Reset

func (e *Engine) Reset()

Reset accepts the currently inserted candidate (if any), clears the current list of completions and exits the incremental-search mode if active. If the completion engine was not active to begin with, nothing will happen.

func (*Engine) ResetForce

func (e *Engine) ResetForce()

ResetForce drops any currently inserted candidate from the line, drops any cached completer function and generated list, and exits the incremental-search mode. All those steps are performed whether or not the engine is active. If revertLine is true, the line will be reverted to its original state.

func (*Engine) Select

func (e *Engine) Select(row, column int)

Select moves the completion selector by some X or Y value, and updates the inserted candidate in the input line.

func (*Engine) SelectTag

func (e *Engine) SelectTag(next bool)

SelectTag allows to select the first value of the next tag (next=true), or the last value of the previous tag (next=false).

func (*Engine) SkipDisplay

func (e *Engine) SkipDisplay()

SkipDisplay avoids printing completions below the input line, but still enables cycling through them.

func (*Engine) TrimSuffix

func (e *Engine) TrimSuffix()

TrimSuffix removes the last inserted completion's suffix if the required constraints are satisfied (among which the index position, the suffix matching patterns, etc).

func (*Engine) UpdateIsearch

func (e *Engine) UpdateIsearch()

UpdateIsearch recompiles the isearch buffer as a regex and filters matching candidates in the available completions.

type Messages

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

Messages is a list of messages to be displayed below the input line, above completions. It is used to show usage and/or error status hints.

func (*Messages) Add

func (m *Messages) Add(s string)

Add adds a message to the list of messages.

func (Messages) Get

func (m Messages) Get() []string

Get returns the list of messages to display.

func (Messages) IsEmpty

func (m Messages) IsEmpty() bool

IsEmpty returns true if there are no messages to display.

func (*Messages) Merge

func (m *Messages) Merge(other Messages)

Merge merges the given messages into the current list of messages.

func (*Messages) Suppress

func (m *Messages) Suppress(expr ...string) error

Suppress removes messages matching the given regular expressions from the list of messages.

type RawValues

type RawValues []Candidate

RawValues is a list of completion candidates.

func (RawValues) EachTag

func (c RawValues) EachTag(tagF func(tag string, values RawValues))

EachTag iterates over each tag and runs a function for each group.

func (RawValues) Filter

func (c RawValues) Filter(values ...string) RawValues

Filter filters values.

func (RawValues) FilterPrefix

func (c RawValues) FilterPrefix(prefix string, matchCase bool) RawValues

FilterPrefix filters values with given prefix. If matchCase is false, the filtering is made case-insensitive. This function ensures that all spaces are correctly.

func (RawValues) Len

func (c RawValues) Len() int

func (RawValues) Less

func (c RawValues) Less(i, j int) bool

func (RawValues) Swap

func (c RawValues) Swap(i, j int)

type SuffixMatcher

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

SuffixMatcher is a type managing suffixes for a given list of completions.

func (*SuffixMatcher) Add

func (sm *SuffixMatcher) Add(suffixes ...rune)

Add adds new suffixes to the matcher.

func (SuffixMatcher) Matches

func (sm SuffixMatcher) Matches(s string) bool

Matches returns true if the given string matches one of the suffixes.

func (*SuffixMatcher) Merge

func (sm *SuffixMatcher) Merge(other SuffixMatcher)

Merge merges two suffix matchers.

type Values

type Values struct {
	Messages Messages
	NoSpace  SuffixMatcher
	Usage    string
	ListLong map[string]bool
	NoSort   map[string]bool
	ListSep  map[string]string
	Pad      map[string]bool
	Escapes  map[string]bool

	// Initially this will be set to the part of the current word
	// from the beginning of the word up to the position of the cursor.
	// It may be altered to give a prefix for all matches.
	PREFIX string

	// Initially this will be set to the part of the current word,
	// starting from the cursor position up to the end of the word.
	// It may be altered so that inserted completions don't overwrite
	// entirely any suffix when completing in the middle of a word.
	SUFFIX string
	// contains filtered or unexported fields
}

Values is used internally to hold all completion candidates and their associated data.

func AddRaw

func AddRaw(values []Candidate) Values

AddRaw adds completion values in bulk.

func (*Values) Merge

func (c *Values) Merge(other Values)

Merge merges a set of values with the current ones, include usage/message strings, meta settings, etc.

Jump to

Keyboard shortcuts

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