Documentation
¶
Overview ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( RenderAskQuestion = func(question string) string { return color.Question.Sprint(strings.TrimRight(question, " ")) } RenderInputRequiredError = fmt.Errorf("Input required") )
var ConfirmNoRegex = regexp.MustCompile(`^(?i)no?$`)
ConfirmNoRegex is the regular expression used to check if the user replied negative
var ConfirmRejection = fmt.Sprintf("%s\n\n", color.Warn.Sprint(`Please respond with "yes" or "no"`))
ConfirmRejection is the message replied to the user if she does not answer with "yes", "y", "no" or "n" (case insensitive)
var ConfirmYesRegex = regexp.MustCompile(`^(?i)y(es)?$`)
ConfirmYesRegex is the regular expression used to check if the user replied positive
var RenderChooseOption = func(key, value string, size int) string { return fmt.Sprintf(" %-"+fmt.Sprintf("%d", size+1)+"s %s\n", color.Notice.Sprint(key+")"), color.Secondary.Sprint(value)) }
RenderChooseOption is the method used by default input `Choose()` method to to render a singular choice into a string. Can be overwritten at users discretion.
var RenderChooseQuery = func() string {
return "Choose: "
}
RenderChooseQuery is the method used by default input `Choose()` method to to render the query prompt choice (after the choices) into a string. Can be overwritten at users discretion.
var RenderChooseQuestion = func(question string) string {
return question + "\n"
}
RenderChooseQuestion is the method used by default input `Choose()` method to to render the question (displayed before listing the choices) into a string. Can be overwritten at users discretion.
Functions ¶
func InputEmptyOk ¶
Types ¶
type DefaultInput ¶
type DefaultInput struct {
// contains filtered or unexported fields
}
DefaultInput is the default used input implementation
func NewDefaultInput ¶
func NewDefaultInput(in io.Reader, out Output) *DefaultInput
NewDefaultInput constructs a new default input implementation on given io reader (if nil, fall back to `os.Stdin`). Requires Output for issuing questions to user.
type DefaultOutput ¶
type DefaultOutput struct {
// contains filtered or unexported fields
}
DefaultOutput is the default used output type
func NewDefaultOutput ¶
func NewDefaultOutput(io io.Writer) *DefaultOutput
NewOutput generates a new (default) output with provided io writer (if nil then `os.Stdout` is used) and a formatter
func (*DefaultOutput) Printf ¶
func (o *DefaultOutput) Printf(msg string, args ...any)
func (*DefaultOutput) Writer ¶
func (o *DefaultOutput) Writer() io.Writer
type Input ¶
type Input interface { // Ask prints question to user and then reads user input and returns as soon // as it's non empty or queries again until it is Ask(question string, check func(string) error) string // AskRegex prints question to user and then reads user input, compares it // against regex and return if matching or queries again until it does AskRegex(question string, rx *regexp.Regexp) string // Choose renders choices for user and returns what was choosen Choose(question string, choices map[string]string) string // Confirm prints question to user until she replies with "yes", "y", "no" or "n" Confirm(question string) bool }
Input is an interface for input helping. It provides shorthand methods for often used CLI interactions.
type Output ¶
type Output interface { // Printf applies format (renders styles) and writes to output Printf(msg string, args ...any) // Sprintf applies format (renders styles) and returns as string Sprintf(msg string, args ...any) string // Writer returns the `io.Writer` used by this output Writer() io.Writer }
Output is interface for