dialog

package
v0.0.0-...-0e1b269 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2021 License: GPL-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package dialog provides a set of interactive dialogs for user.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrAborted is returned when user pressed ^C.
	ErrAborted = fmt.Errorf("dialog aborted")
)

Functions

func Entry

func Entry(prompt string, keys *input.Input) (string, error)

Entry asks for a free-form input. Example: Search.

func Message

func Message(title, message string, keys *input.Input) error

Message shows a message that's dismissed by pressing enter. Should not fail, but if it's important checking error value is optional. Any errors are logged.

func Question

func Question(title string, opts []Option, keys *input.Input) (string, error)

Question asks the user a multiple-choice question. ^C is always a valid option, and returns ErrAborted. Example: `Should I send that email now?`

func TrimOneChar

func TrimOneChar(s string) string

TrimOneChar removes bytes until the printed size of the string is reduced. This is used by "backspace". TODO: should this use utf8.DecodeLastRuneInString to remove one codepoint at a time?

Types

type Option

type Option struct {
	Key    string
	KeyInt int
	Label  string
}

Option is one option in a multiple-choice dialog.

func Selection

func Selection(opts []*Option, prompt string, free bool, keys *input.Input) (*Option, error)

Selection asks the user for a choice, with populated suggestions that can be searched in. If `free` is `true` then the user can input anything. If `false` then the options listed are the only valid ones. Example: Email recipient choice.

func Strings2Options

func Strings2Options(ss []string) []*Option

Strings2Options takes a slice of strings and turns them into Options.

func (*Option) String

func (o *Option) String() string

String gives string representation usable for showing to the user.

Jump to

Keyboard shortcuts

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