prompt

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2020 License: MIT Imports: 8 Imported by: 0

README

Prompt

PkgGoDev CI

A simple CLI helper module to prompt for user input

User input types

  • YesNo: y/n with defaults
  • Choice: from a list of options
  • Input: any user input
  • Password: accept user input without showing it on screen

Support

Please open an issue for support.

Contributing

Please contribute using Github Flow. Create a branch, add commits, and open a pull request.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidInput = errors.New("invalid input")

ErrInvalidInput implies the imput entered was invalid

Functions

func Choice

func Choice(message string, options []string) (int, string, error)

Choice prompts the user for a choice from a list of options returning the index and the option string. In case of an invalid input, it returns ErrInvalidInput.

func ChoiceWithRetry

func ChoiceWithRetry(message string, options []string) (int, string, error)

ChoiceWithRetry prompts the user for a choice from a list of options returning the index and the option string. In case of an invalid input, it prompts again until a valid response is entered.

func Input

func Input(message string) (string, error)

Input prompts the user for any user input

func Password added in v0.3.0

func Password(message string) (string, error)

Password prompts the user for any user input while hiding the input

func YesNo

func YesNo(message string, defaultValue bool) (bool, error)

YesNo prompts the user for a yes/no response. In case of an invalid input, it returns ErrInvalidInput.

func YesNoWithRetry

func YesNoWithRetry(message string, defaultValue bool) (bool, error)

YesNoWithRetry prompts the user for a yes/no response. In case of an invalid input, it prompts again until a valid response is entered.

Types

type Term added in v0.2.0

type Term interface {
	EnableAltScreenBuffer() Term
	DisableAltScreenBuffer() Term
	ClearScreen() Term
	ClearScreenAndScrollback() Term
	Println(message ...interface{}) Term
	PrintTemp(message ...interface{}) Term
	PrintPrompt(message string, suffix ...string) Term
}

func NewTerm added in v0.4.0

func NewTerm() Term

Terminal returns a new instance of Term

func Terminal added in v0.2.0

func Terminal() Term

Terminal returns an instance of Term

Jump to

Keyboard shortcuts

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