dialog

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var InvalidSelection = SimpleOption{/* contains filtered or unexported fields */}

InvalidSelection is a predefined selection representing choices that errored out.

Functions

func DoBackgroundLoading added in v1.1.0

func DoBackgroundLoading(funcs ...func(wg *sync.WaitGroup))

DoBackgroundLoading presents the loading animation in a separate goroutine, and executes any number of other functions in their own goroutines in the background. Loading will complete once ALL of the passed funcs complete. See SyncedFunc to help generate appropriate functions

func DoBackgroundLoadingWithMessage added in v1.1.0

func DoBackgroundLoadingWithMessage(msg string, funcs ...func(wg *sync.WaitGroup))

DoBackgroundLoadingWithMessage is identical to DoBackgroundLoading, except the given message will be disabled instead of "Loading"

func MkBasicSelect

func MkBasicSelect(inputStream io.ReadCloser) promptui.Select

MkBasicSelect provides a base for any Select operation. This essentially ensures that the given Select struct will read input from the proper source

func SearcherContainsCI

func SearcherContainsCI(optionLabels []string) func(input string, index int) bool

SearcherContainsCI provides a basic searcher with the logic that a given label will match if, **ignoring case**, the given input matches some portion of the given label; specifically, if the input is a substring of the label

func ShowLoadingAnimation

func ShowLoadingAnimation(text string, stopCheck *bool)

ShowLoadingAnimation presents the given text plus a looping dot animation. Should be called as a goroutine, otherwise this is likely to be an infinite loop

To stop, set the stopCheck parameter to true

A common solution can be used with the DoBackgroundLoading function

func SyncedFunc added in v1.1.0

func SyncedFunc(fn func()) func(*sync.WaitGroup)

SyncedFunc wraps the provided function in a wait group, and sends a Done signal once the provided function completes

func UserQuery

func UserQuery(question string, defaultValue *string, inputStream io.ReadCloser) (string, error)

UserQuery presents a free-answer dialog to the user with the given question (and default value, if one is provided). Returns the answer to the question, or an error if one is encountered.

func YesNoPrompt

func YesNoPrompt(label, details string, inputStream io.ReadCloser) (bool, error)

YesNoPrompt spans a "Select" dialog, where a given user will be propted with a yes/no question (plus, optional details, if details is not the empty string) will return (true, nil) if the user selected "Yes", (false, nil) if the user selected "No" (false, <error>) if some error occurred.

Types

type QueryResponse added in v1.1.0

type QueryResponse struct {
	Value  *string
	Action UserAction
	Err    error
}

QueryResponse condenses the response from a free text prompt. See HandleUserQuery for more details. This is also mirrored by SelectResponse for multiple-choice user queries.

func HandleUserQuery added in v1.1.0

func HandleUserQuery(question string, defaultValue *string, inputStream io.ReadCloser, bailFunc func()) QueryResponse

HandleUserQuery provides a small wrapper around UserQuery. This function will generate a free-text prompt, then interpret the results to check if some error was encountered, or if the user pressed ^d or ^c to exit out of the select menu. If so, bailFunc is executed. This data is all captured, then returned in a SelectResponse, which can be pulled apart to retrieve the selection or error as before

func (*QueryResponse) IsKillSignal added in v1.1.0

func (resp *QueryResponse) IsKillSignal() bool

IsKillSignal checks to see if the user action was either a UserActionExit or UserActionCancel -- i.e. the user tried to back out of the interaction point

func (*QueryResponse) SafeValue added in v1.1.0

func (resp *QueryResponse) SafeValue() string

SafeValue returns back the actual value of the response, or an empty string if the Value is nil

type SelectResponse added in v1.1.0

type SelectResponse struct {

	// Selection represents the specfic selection that was made by a user in the select menu.
	Selection SimpleOption

	// Action represents how the user interacted with the select menu -- specifically, did they enter
	// a value, or did they try to avoid entering value, or did the select menu generate an error
	Action UserAction

	// Err is the actual error encountered by the user, if any. Note that the underlying system treats
	// ^c and ^d as errors, whereas these errors are instead translated into actions for
	// this system, and are not represented as errors here.
	Err error
}

SelectResponse captures the net result from a Select Menu selection. See HandlePlainSelect for more details. Also note that this struture is mirrored by QueryResponse, for free text entry.

func HandlePlainSelect added in v1.1.0

func HandlePlainSelect(label string, options []SimpleOption, inputStream io.ReadCloser, bailFunc func() SimpleOption) SelectResponse

HandlePlainSelect provides a small wrapper around PlainSelect. This function will generate a CLI Select menu, then interpret the results to check if some error was encountered, or if the user pressed ^d or ^c to exit out of the select menu. If so, bailFunc is executed, and the caller may supply a replacement value in these sencarios. This data is all captured, then returned in a SelectResponse, which can be pulled apart to retrieve the selection or error as before

func (*SelectResponse) IsKillSignal added in v1.1.0

func (resp *SelectResponse) IsKillSignal() bool

IsKillSignal checks to see if the user action was either a UserActionExit or UserActionCancel -- i.e. the user tried to back out of the interaction point

type SimpleOption added in v1.1.0

type SimpleOption struct {
	Label string
	Data  interface{}
	// contains filtered or unexported fields
}

func PlainSelect added in v1.1.0

func PlainSelect(label string, options []SimpleOption, inputStream io.ReadCloser) (SimpleOption, error)

PlainSelect constructs a question, with pre-defined answers. Users must "select" an answer. This version works off of SimpleOption, and returns back the selected option and what error occurred while making that selection, if any.

func (*SimpleOption) IsValid added in v1.1.0

func (s *SimpleOption) IsValid() bool

type UserAction added in v1.1.0

type UserAction string

UserAction is an effective enum representing the various states a user can get into when prompted for a response (referred to in documentation as an "interaction point")

const (
	// UserActionCancel represents a user pressing ^c (Interrupt) when given an interaction point
	UserActionCancel UserAction = "cancel"
	// UserActionExit represents a user pressing ^d (EOF) when given an interaction point
	UserActionExit UserAction = "exit"
	// UserActionEntered represents a user providing a value when given an interaction point (i.e. the normal expectation)
	UserActionEntered UserAction = ""
	// UserActionErrored represents a user encountering an error during an interaction point
	UserActionErrored UserAction = "error"
)

Jump to

Keyboard shortcuts

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