ui

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: May 14, 2018 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Keyboard

type Keyboard interface {
	GetKey() (string, rune)
}
type Menu struct {
	// contains filtered or unexported fields
}

Menu helps create a searchable, flexible, on-screen menu.

func NewMenu

func NewMenu(screen Screen, keyboard Keyboard) *Menu

NewMenu creates a new Menu object.

func (menu *Menu) Choose(choices []string, idx int, searchStr string,
	keys ...string) (int, string)

Choose is the main interaction loop for the menu. It takes three required inputs: a list of choices (strings), a current-selection-index (int), and an initial search string (often ""). Optionally you can also pass a list of "keys" (strings) to listen for.

The function returns two things: the integer index of the current selection, and the string description of the key that caused the program to exit.

func (menu *Menu) Clear()

Clear clears the on-screen menu.

func (menu *Menu) Search(choices []string, searchStr string) int

Search searches menu options for a partial string match.

func (menu *Menu) SearchNext(choices []string, searchStr string) int

SearchNext searches menu options from the current option on.

func (menu *Menu) Show(choices []string)

Show displays a menu of choices on the screen.

type Prompt

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

Prompt is a user-input prompt.

func MakePrompt

func MakePrompt(screen Screen, keyboard Keyboard) Prompt

MakePrompt creates a new prompt object.

func (*Prompt) Ask

func (prompt *Prompt) Ask(question string, history []string, completers ...func(string) []string) (string, error)

Ask asks the user a question, expecting a string response.

func (*Prompt) AskYesNo

func (prompt *Prompt) AskYesNo(question string) (bool, error)

AskYesNo expects either y or n as an answer.

func (*Prompt) GetAnswer

func (prompt *Prompt) GetAnswer(question string, history *[]string, completers ...func(string) []string) string

GetPromptAnswer is a wrapper arount Ask, which handles some history stuff.

func (*Prompt) GetRune

func (prompt *Prompt) GetRune(question string) rune

GetRune expects a single keypress answer and returns the rune.

type Screen

type Screen interface {
	Flush()
	Highlight(row, col int)
	WriteString(row, col int, text string)
	WriteStringColor(row, col int, text string, fg, bg terminal.Attribute)
	Size() (cols, rows int)
	WriteMessage(msg string)
	Row() int
	Col() int
	SetCursor(r, c int)
}

Jump to

Keyboard shortcuts

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