terminal

package
v1.0.17 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2023 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCtrlC = errors.New("Ctrl + C")
View Source
var ErrCtrlD = errors.New("Ctrl + D")
View Source
var ErrFlagNotSet = errors.New("Flag not set")
View Source
var ErrPasteIndicator = pasteIndicatorError{}

ErrPasteIndicator may be returned from ReadLine as the error, in addition to valid line data. It indicates that bracketed paste mode is enabled and that the returned line consists only of pasted data. Programs may wish to interpret pasted data more literally than typed data.

View Source
var ErrTrample = errors.New("Function already registered")

Functions

func MakeHelpText added in v1.0.2

func MakeHelpText(lines ...string) (s string)

Types

type Argument

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

func (*Argument) End

func (bn *Argument) End() int

func (*Argument) Start

func (bn *Argument) Start() int

func (Argument) Type

func (a Argument) Type() string

func (*Argument) Value

func (bn *Argument) Value() string

type Cmd

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

func (*Cmd) End

func (bn *Cmd) End() int

func (*Cmd) Start

func (bn *Cmd) Start() int

func (Cmd) Type

func (c Cmd) Type() string

func (*Cmd) Value

func (bn *Cmd) Value() string

type Command

type Command interface {
	// Returns the expected syntax for the command, used in the autocomplete process with text tokens to indicate where autocomplete can occur
	Expect(line ParsedLine) []string
	// Run the command with the given arguments
	Run(output io.ReadWriter, line ParsedLine) error
	// Give helptext for commands
	Help(explain bool) string
}

type EscapeCodes

type EscapeCodes struct {
	// Foreground colors
	Black, Red, Green, Yellow, Blue, Magenta, Cyan, White []byte

	// Reset all attributes
	Reset []byte
}

EscapeCodes contains escape sequences that can be written to the terminal in order to achieve different styles of text.

type Flag

type Flag struct {
	Args []Argument
	// contains filtered or unexported fields
}

func (*Flag) ArgValues

func (f *Flag) ArgValues() (out []string)

func (*Flag) End

func (bn *Flag) End() int

func (*Flag) Start

func (bn *Flag) Start() int

func (Flag) Type

func (f Flag) Type() string

func (*Flag) Value

func (bn *Flag) Value() string

type Node

type Node interface {
	Value() string
	Start() int
	End() int
	Type() string
}

type ParsedLine

type ParsedLine struct {
	Chunks []string

	FlagsOrdered []Flag
	Flags        map[string]Flag

	Arguments []Argument
	Focus     Node

	Section *Flag

	Command *Cmd

	RawLine string
}

func ParseLine

func ParseLine(line string, cursorPosition int) (pl ParsedLine)

func ParseLineValidFlags

func ParseLineValidFlags(line string, cursorPosition int, validFlags map[string]bool) (pl ParsedLine, err error)

func (*ParsedLine) ArgumentsAsStrings

func (pl *ParsedLine) ArgumentsAsStrings() (out []string)

func (*ParsedLine) Empty added in v1.0.13

func (pl *ParsedLine) Empty() bool

func (*ParsedLine) ExpectArgs

func (pl *ParsedLine) ExpectArgs(flag string, needs int) ([]Argument, error)

func (*ParsedLine) GetArg

func (pl *ParsedLine) GetArg(flag string) (Argument, error)

func (*ParsedLine) GetArgString

func (pl *ParsedLine) GetArgString(flag string) (string, error)

Gets a single argument, will return error if flag is not set, or if it has no contents (e.g --blah)

func (*ParsedLine) GetArgs

func (pl *ParsedLine) GetArgs(flag string) ([]Argument, error)

func (*ParsedLine) GetArgsString

func (pl *ParsedLine) GetArgsString(flag string) ([]string, error)

func (*ParsedLine) IsSet

func (pl *ParsedLine) IsSet(flag string) bool

type Terminal

type Terminal struct {

	// AutoCompleteCallback, if non-null, is called for each keypress with
	// the full input line and the current position of the cursor (in
	// bytes, as an index into |line|). If it returns ok=false, the key
	// press is processed normally. Otherwise it returns a replacement line
	// and the new cursor position.
	AutoCompleteCallback func(term *Terminal, line string, pos int, key rune) (newLine string, newPos int, ok bool)

	// Escape contains a pointer to the escape codes for this terminal.
	// It's always a valid pointer, although the escape codes themselves
	// may be empty if the terminal doesn't support them.
	Escape *EscapeCodes
	// contains filtered or unexported fields
}

Terminal contains the state for running a VT100 terminal that is capable of reading lines of input.

func NewAdvancedTerminal

func NewAdvancedTerminal(c io.ReadWriter, user *internal.User, prompt string) *Terminal

func NewTerminal

func NewTerminal(c io.ReadWriter, prompt string) *Terminal

NewTerminal runs a VT100 terminal on the given ReadWriter. If the ReadWriter is a local terminal, that terminal must first have been put into raw mode. prompt is a string that is written at the start of each input line (i.e. "> ").

func (*Terminal) AddCommands

func (t *Terminal) AddCommands(m map[string]Command) error

func (*Terminal) AddValueAutoComplete

func (t *Terminal) AddValueAutoComplete(placement string, trie *trie.Trie) error

func (*Terminal) DisableRaw

func (t *Terminal) DisableRaw()

func (*Terminal) EnableRaw

func (t *Terminal) EnableRaw()

func (*Terminal) GetWidth added in v1.0.3

func (t *Terminal) GetWidth() int

func (*Terminal) Read

func (t *Terminal) Read(b []byte) (n int, err error)

func (*Terminal) ReadLine

func (t *Terminal) ReadLine() (line string, err error)

ReadLine returns a line of input from the terminal.

func (*Terminal) ReadPassword

func (t *Terminal) ReadPassword(prompt string) (line string, err error)

ReadPassword temporarily changes the prompt and reads a password, without echo, from the terminal.

func (*Terminal) Run

func (t *Terminal) Run() error

func (*Terminal) SetBracketedPasteMode

func (t *Terminal) SetBracketedPasteMode(on bool)

SetBracketedPasteMode requests that the terminal bracket paste operations with markers. Not all terminals support this but, if it is supported, then enabling this mode will stop any autocomplete callback from running due to pastes. Additionally, any lines that are completely pasted will be returned from ReadLine with the error set to ErrPasteIndicator.

func (*Terminal) SetPrompt

func (t *Terminal) SetPrompt(prompt string)

SetPrompt sets the prompt to be used when reading subsequent lines.

func (*Terminal) SetSize

func (t *Terminal) SetSize(width, height int) error

func (*Terminal) Write

func (t *Terminal) Write(buf []byte) (n int, err error)

type TerminalFunctionCallback

type TerminalFunctionCallback func(term *Terminal, args ...string) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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