completion

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2017 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CallbackCompleter

type CallbackCompleter struct {
	Completer
	// contains filtered or unexported fields
}

func NewCallbackCompleter

func NewCallbackCompleter(m ...Matcher) *CallbackCompleter

func (*CallbackCompleter) Complete

func (c *CallbackCompleter) Complete(line string, pos int, key rune) (string, int, bool)

type Combine

type Combine struct {
	Matchers []Matcher
	Next     []Matcher
}

Combine aggregates the matches of it's children. If any of the Matchers match, Accept will return all the Next. Use this when you have multiple choices that all result in the same continuation, e.g.:

         /-- create --\
command ---- update ---- <id>
         \-- delete --/

The "create", "update" and "delete" are the Matchers of the Combine, "<id>" is the Next.

func (*Combine) Accept

func (s *Combine) Accept(word string) (bool, []Matcher)

func (*Combine) AddNext

func (s *Combine) AddNext(m Matcher)

func (*Combine) Help

func (s *Combine) Help(esc *terminal.EscapeCodes) []string

func (*Combine) Match

func (s *Combine) Match(word string) []Word

type Completer

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

A Completer provides line completion functionality based on Matchers.

func NewCompleter

func NewCompleter(m ...Matcher) Completer

NewCompleter returns a new Completer based on the aggregation of the given Matchers.

func (Completer) Complete

func (c Completer) Complete(line string, pos int) (head string, comps []Word, tail string)

Complete returns the possible continuation of the given line.

func (Completer) PrintHelp

func (c Completer) PrintHelp(out io.Writer, esc *terminal.EscapeCodes)

type Literal

type Literal struct {
	Value string
	Next  []Matcher
}

Literal matches any prefix to String, even the empty string.

func (*Literal) Accept

func (l *Literal) Accept(word string) (bool, []Matcher)

func (*Literal) AddNext

func (l *Literal) AddNext(m Matcher)

func (*Literal) Help

func (l *Literal) Help(esc *terminal.EscapeCodes) []string

func (*Literal) Match

func (l *Literal) Match(word string) []Word

type Matcher

type Matcher interface {
	Match(word string) []Word
	Accept(word string) (bool, []Matcher)
	AddNext(m Matcher)
	Help(*terminal.EscapeCodes) []string
}

A Matcher provides word completion functionality.

type Regexp

type Regexp struct {
	Exp         *regexp.Regexp
	Placeholder string
	Optional    bool
	Next        []Matcher
}

Regexp matches any word that matches Exp.

func (*Regexp) Accept

func (r *Regexp) Accept(word string) (bool, []Matcher)

func (*Regexp) AddNext

func (r *Regexp) AddNext(m Matcher)

func (*Regexp) Help

func (r *Regexp) Help(esc *terminal.EscapeCodes) []string

func (*Regexp) Match

func (r *Regexp) Match(word string) []Word

type Word

type Word struct {
	Value       string
	Placeholder bool
}

type WordCompleter

type WordCompleter struct {
	Completer
}

A WordCompleter provides line completion functionality based on Matchers.

func NewWordCompleter

func NewWordCompleter(m ...Matcher) WordCompleter

NewWordCompleter returns a new Completer based on the aggregation of the given Matchers.

func (WordCompleter) Complete

func (c WordCompleter) Complete(line string, pos int) (string, []string, string)

Complete returns the possible continuation of the given line. This satisfies the github.com/peterh/liner.WordCompleter type.

Jump to

Keyboard shortcuts

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