prompt

package
v0.0.0-...-e2c65c2 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2018 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Func

type Func func(prior Prompt) (next Prompt, required bool)

Func is a convenient way to implement Runner arounnd a single function.

func (Func) RunPrompt

func (f Func) RunPrompt(pr Prompt) (Prompt, bool)

RunPrompt calls the aliased function.

type Prompt

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

Prompt represents a set of actions that the user may select from. Each action has an associated key rune, message, and action. Prompts may be chained, i.e. the user is being shown a sub-prompt. Prompts may be left or right aligned when rendered.

func (*Prompt) AddAction

func (pr *Prompt) AddAction(ch rune, run Runner, mess string, args ...interface{}) bool

AddAction adds a new action to the prompt with the given activation rune, display message, and action to run; if the rune conflicts with an already added action, then the addition fails and false is returned; otherwise true is returned.

func (*Prompt) Clear

func (pr *Prompt) Clear()

Clear prompt state, by unwinding the prompt, clearing its mesage, and truncating its actions.

func (*Prompt) Handle

func (pr *Prompt) Handle(k view.KeyEvent) (handled, canceled, required bool)

Handle a key event, returning: whether the event was handled, if the prompt was canceled, and whether more user input is required (to take semantically take an action).

func (Prompt) IsRoot

func (pr Prompt) IsRoot() bool

IsRoot returns true only if this prompt is not a sub-prompt.

func (Prompt) Len

func (pr Prompt) Len() int

Len returns how many actions are in this prompt.

func (Prompt) Pop

func (pr Prompt) Pop() Prompt

Pop returns the parent prompt, if any, or this prompt if it has no parent.

func (*Prompt) RemoveAction

func (pr *Prompt) RemoveAction(ch rune, run Runner, mess string) bool

RemoveAction removes an action matching the given rune, runner, or message (in that order of precedence); zero values will not match. Returns true if an action was removed, false otherwise.

func (*Prompt) Render

func (pr *Prompt) Render(g view.Grid)

Render the prompt within the given space.

func (*Prompt) RenderSize

func (pr *Prompt) RenderSize() (wanted, needed point.Point)

RenderSize calculates how much space the prompt could use and how much it needs. TODO: not yet paginated.

func (Prompt) Run

func (pr Prompt) Run(i int) (next Prompt, required, handled bool)

Run runs the i( >= 0 && <= Len())-th action, returning its next and required return values with handled=true if there is an ith-action; the current prompt, required=false and handled=false are retured if i is invalid.

func (Prompt) RunPrompt

func (pr Prompt) RunPrompt(prior Prompt) (Prompt, bool)

RunPrompt runs the prompt as a sub-prompt of another; causes Prompt to implement Runner, allowing prompts to be added as actions to other prompts.

func (*Prompt) SetActionMess

func (pr *Prompt) SetActionMess(ch rune, run Runner, mess string, args ...interface{}) bool

SetActionMess updates the message on an existing action, matched by run or runner; it returns true only if an action was updated.

func (*Prompt) SetAlign

func (pr *Prompt) SetAlign(align view.Align)

SetAlign ment for this prompt; only horizontal left/right bits matter.

func (*Prompt) SetMess

func (pr *Prompt) SetMess(mess string, args ...interface{})

SetMess sets the header message.

func (Prompt) Sub

func (pr Prompt) Sub(mess string, args ...interface{}) Prompt

Sub returns a new sub-prompt of the current one with the given header message.

func (Prompt) Unwind

func (pr Prompt) Unwind() Prompt

Unwind the prompt, returning the root prompt (which may be the current prompt if not a sub-prompt).

type Runner

type Runner interface {
	RunPrompt(prior Prompt) (next Prompt, required bool)
}

Runner represents an action invoked by a Prompt. RunPrompt is called when a Prompt action has been invoked by the user. It gets the prior Prompt value, and is expected to return a new Prompt value to display to the user. The `required` boolean argument indicates whether, semantically, an action was taken or whether further input is needed from the user (presumably underneath the returned `next` Prompt).

Jump to

Keyboard shortcuts

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