prompt

package
v0.10.11 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package prompt provides the prompt interface and its implementation.

Index

Constants

This section is empty.

Variables

View Source
var (
	ColorInitial = Color(goprompt.DarkGreen)
	ColorBlue    = Color(goprompt.Blue)
)

InitialColor is the initial color for a prompt prefix.

View Source
var (
	ErrSkip  = errors.New("skip")
	ErrAbort = errors.New("abort")
)
View Source
var New = newPrompt

New instantiates a new Prompt implementation. New will be replaced when e2egen command is executed. Initially, Prompt doesn't have a prefix, so you have to call SetPrefix for displaying it.

Functions

This section is empty.

Types

type Color

type Color goprompt.Color

Color represents a valid color for a prompt prefix.

func (*Color) Next

func (c *Color) Next()

Next returns the next color of c. Note that Next will circular if c is the end of colors.

func (*Color) NextVal added in v0.10.0

func (c *Color) NextVal() Color

NextVal is the same as Next, but return color as value.

type Completer

type Completer interface {
	// Complete receives d that is a piece of input, and returns some suggestions.
	// The prompt shows suggestions from it.
	Complete(d Document) []*Suggest
}

Completer is a mechanism that provides REPL completion.

type Document

type Document interface {
	GetWordBeforeCursor() string
	TextBeforeCursor() string
}

Document is a piece of input that has several information such that text before the cursor, a work before the cursor, etc.

type Option

type Option func(*opt)

func WithCommandHistory

func WithCommandHistory(h []string) Option

type Prompt

type Prompt interface {
	// Input reads keyboard input.
	// If ctrl+d is entered, Input returns io.EOF.
	// If ctrl+c is entered, Input returns ErrAbort.
	Input() (string, error)
	Select(message string, options []string) (idx int, selected string, _ error)

	// SetPrefix changes the current prefix to the passed one.
	SetPrefix(prefix string)

	// SetPrefixColor changes the current color to the passed one.
	SetPrefixColor(color Color)

	// SetCompleter set a completer for prompt completion.
	SetCompleter(c Completer)

	// GetCommandHistory gets a command history. The order of history is asc.
	GetCommandHistory() []string
}

type Suggest

type Suggest struct {
	goprompt.Suggest
}

Suggest is a suggestion for the completion.

func FilterHasPrefix

func FilterHasPrefix(s []*Suggest, sub string, ignoreCase bool) []*Suggest

FilterHasPrefix filters s by whether have sub as the prefix. If ignoreCase is true, differences between upper and lower casing are ignored.

func NewSuggestion

func NewSuggestion(text, description string) *Suggest

NewSuggestion returns a new *Suggest from text and description.

Jump to

Keyboard shortcuts

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