Documentation ¶
Overview ¶
Package prompt provides an interactive command line interface with customizable completion of commands using github.com/peterh/liner as the line editor.
It's meant to be similar to the command line interface on some networking equipment.
Index ¶
- Variables
- func Grep(r io.Reader, w io.Writer, args []string)
- type Command
- type CommandSet
- type Completer
- type Filter
- type Prompt
- func (p *Prompt) Close() error
- func (p *Prompt) CurrentCommandSet() *CommandSet
- func (p *Prompt) NewCommandSet(name string) *CommandSet
- func (p *Prompt) PopCommandSet() error
- func (p *Prompt) Prompt() bool
- func (p *Prompt) PushCommandSet(name string) error
- func (p *Prompt) RegisterCompleter(name string, fn Completer) error
- func (p *Prompt) RegisterFilter(name string, fn Filter) error
Constants ¶
This section is empty.
Variables ¶
var CompleteDirectory = completeFileDir(dirsOnly)
CompleteDirectory is a pre-defined completer that is used to complete a directory name.
var CompleteFile = completeFileDir(filesOnly)
CompleteFile is a pre-defined completer that is used to complete a file name.
var CompleteFileOrDirectory = completeFileDir(filesAndDirs)
CompleteFileOrDirectory is a pre-defined completer that is used to complete a file or directory name.
Functions ¶
Types ¶
type Command ¶
Command is a function representing a command to be executed. Arguments are passed as args, and all output should be written to w to allow for filtering.
func PopCommandSet ¶
PopCommandSet returns a command that enters a leaves the current command set.
func PushCommandSet ¶
PushCommandSet returns a command that enters a named command set.
func PushCommandSetArg ¶
PushCommandSetArg returns a command that enters the command set passed in as an argument. It should be registered with a description like "enter $1" to specify that it takes a single argument.
type CommandSet ¶
type CommandSet struct {
// contains filtered or unexported fields
}
CommandSet is a set of commands, usually related. Command sets can be switched between by registering commands that call PushCommandSet/PopCommandSet on the Prompt.
func (*CommandSet) RegisterCommandFunc ¶
func (cs *CommandSet) RegisterCommandFunc(desc string, fn Command) error
RegisterCommandFunc registers a command. The description syntax is:
cmd [arg1 arg2...] [$n:[completionType] ...] [$*:[completionType]]
$n - n is a digit, and it matches a single argument. This can be used to reorder arguments (e.g. "foo $2 $1", when called with "foo a b", will have []args{"b","a"}) when the command is executed.)
$* - wildcard, matches all arguments to the end of the line
type Completer ¶
Completer is used to provide context-sensitive completions for placeholders. Completers are registered, and then are called retrieve completions for the registered placeholder types.
type Filter ¶
Filter is the type of function used for filtering command output. They should synchronously read from r, apply any filtering logic and write the result to the w.
type Prompt ¶
type Prompt struct { LineState *liner.State // the liner used for input, visibile to allow direct manipulation/changes Prompter func() string // Prompt is the function called to return the prompt // contains filtered or unexported fields }
Prompt is the user prompt.
func (*Prompt) CurrentCommandSet ¶
func (p *Prompt) CurrentCommandSet() *CommandSet
CurrentCommandSet returns the current command set in use.
func (*Prompt) NewCommandSet ¶
func (p *Prompt) NewCommandSet(name string) *CommandSet
NewCommandSet constructs and registers a new command set.
func (*Prompt) PopCommandSet ¶
PopCommandSet removes the latest command set pushed.
func (*Prompt) PushCommandSet ¶
PushCommandSet enters a new command set and pushes it to the stack.
func (*Prompt) RegisterCompleter ¶
RegisterCompleter registers a function to be used for context sensitive completion of command placeholders.