repl

package
v0.0.0-...-49df695 Latest Latest
Warning

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

Go to latest
Published: May 17, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HistoryItem

type HistoryItem struct {
	// The text displayed by the hint.
	Text string
	// The history time. Used as priority when sorting hints.
	Time int
}

HistoryItem represents a history entry.

type HistoryTrie

type HistoryTrie struct {
	*patricia.Trie

	// Path to the history file.
	Path string

	// List of hints.
	Hints []HistoryItem

	// Used for navigation (Ctrl+N, Ctrl+P).
	NavigationArray []HistoryItem

	// Return true if navigation has started.
	Navigating bool

	// Current index of visible hint.
	NavigationIndex int

	// The offset at which the user provided prefix ends. Must
	// be less than the length of the visible hint text.
	CurrentHintTextOffset int

	// The visible hint text.
	CurrentHintText string
}

func (*HistoryTrie) EndNavigation

func (h *HistoryTrie) EndNavigation()

End history navigation.

func (*HistoryTrie) GoToNextEntry

func (h *HistoryTrie) GoToNextEntry() string

Go to the next history entry and return selected text.

func (*HistoryTrie) GoToPrevEntry

func (h *HistoryTrie) GoToPrevEntry() string

Go to the previous history entry and return selected text.

func (*HistoryTrie) Load

func (h *HistoryTrie) Load(merge bool) error

Load history optionally merging it with the existing trie.

func (*HistoryTrie) Push

func (h *HistoryTrie) Push(prefix patricia.Prefix)

Append a line to history.

func (*HistoryTrie) Save

func (h *HistoryTrie) Save()

Save history.

func (*HistoryTrie) StartNavigation

func (h *HistoryTrie) StartNavigation()

Start history navigation.

type Repl

type Repl struct {
	History   HistoryTrie
	Runner    func(args []string) error
	Suggester Suggester
	// contains filtered or unexported fields
}

Read-print-loop manager.

func NewRepl

func NewRepl() *Repl

Create a new Repl.

func (*Repl) Cleanup

func (r *Repl) Cleanup()

Perform cleanup tasks before quitting.

func (*Repl) HandleKey

func (r *Repl) HandleKey(line []rune, pos int, key rune) ([]rune, int, bool)

User key input handler.

func (*Repl) Start

func (r *Repl) Start() error

Enter the loop.

type Suggester

type Suggester struct {
	Suggestions []*Suggestion
}

Suggester can perform auto-completion.

func (*Suggester) Create

func (suggester *Suggester) Create(s string) *Suggestion

Create a new root suggestion item.

func (*Suggester) Do

func (suggester *Suggester) Do(line []rune, pos int) (suggestions [][]rune, offset int)

Get suggestions/completions.

type Suggestion

type Suggestion struct {
	Prefix string
	// contains filtered or unexported fields
}

Suggestion represents a command-level suggestion which can possess children.

func (*Suggestion) AddChild

func (suggestion *Suggestion) AddChild(value string)

Add a new suggestion string.

Jump to

Keyboard shortcuts

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