Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Info ¶
type Info struct { // The Type represents a valid prompt and must be mappable to the Prompt enum via the EnumType() method. Type string // The Message is an arbitrary string that will be used for the prompt message. Message string // Dynamic prompts can include zero or more options which alter the behavior of the prompt. Options []PromptOption }
An Info object is used to dynamically build a prompt from data, enabling the creation of prompts defined outside of the compiled code itself.
type Model ¶
type Model struct { // Which prompt is active ActiveType Prompt // The model for the selection prompt Selection *selection.Model // The model for the text input prompt TextInput *textinput.Model // The model for the confirmation prompt Confirmation *confirmation.Model }
The Model for a dynamic prompt is able to display confirmation, selection, and text input prompts from data without the developer knowing ahead of time which type of prompt will be needed. This allows a program to take advantage of prompts defined in data outside of the go code itself.
func New ¶
The New function takes the data for dynamic prompt info and returns a dynamic prompt model configured per the values and options defined in the Info object.
func (*Model) Init ¶
When the Model is initialized, it passes straight through to appropriate submodel for the prompt.
type Option ¶
type Option int
The Option enum maps an option string to a defined behavior for the dynamic prompt.
const ( // The specified string did not map to a valid option OptionUnknown Option = iota // The option sets the default value for a confirmation prompt to yes, no, or undecided. ConfirmationDefault // The option adds the value list to the selection prompt as valid choices. Use this when the choices are a list of // non-complex objects, like strings or integers. SelectionChoiceSimple // The option adds the value list to the selection prompt as valid choices. Use this when the choices are a list of // complex objects as maps; to use this option, each choice in the data must include a name key with a string value // for identifying the choice. SelectionChoiceComplex )
type Prompt ¶
type Prompt int
The Prompt enum declares the types of prompts that the dynamic model can handle.
const ( // Unknown prompts go unhandled, erroring. PromptUnknown Prompt = iota // A confirmation prompt asks a user a yes/no question Confirmation // A selection prompt has the user select one choice from a list of choices Selection // A text input prompt has the user enter a string of text TextInput )
type PromptOption ¶
type PromptOption struct { // The Type must be a string that maps to a valid Option via the EnumType() method. Type string // The Value can be anything but is most commonly a string, a map[string]any, or a slice of either. Value any }
Prompt Options must declare a type and a value. They are used for changing the behavior of a dynamic prompt.
func (PromptOption) ConfirmationOptions ¶
func (option PromptOption) ConfirmationOptions() (options []confirmer.Option)
The ConfirmationOptions method introspects on a PromptOption to return a slice of options to use when creating a confirmation prompt.
If the prompt option is for a confirmation default, it sets the prompt's default value to Yes (if the value in the data is true or "yes"), No (if the value in the data is false or "no"), or Undecided (if the value is anything else).
func (PromptOption) EnumType ¶
func (option PromptOption) EnumType() (modifier Option)
The EnumType method maps the string specified in the data for a dynamic prompt's options to an Option enum. If the specified string cannot be mapped, it returns OptionUnknown and is ignored.
func (PromptOption) SelectionOptions ¶
func (option PromptOption) SelectionOptions() (options []selector.Option)
The SelectionOptions method introspects on a PromptOption to return a slice of options to use when creating a selection prompt.
If the prompt option is for a simple selection choice, it appends the value of the prompt option to the list of valid choices.
If the prompt option is for a complex selection choice, it returns options which:
1. Append the slice of choices under the "choices" key in the option's value as valid choices 2. Add a name function to the prompt's extended template funcs, returning the value of the name key (as specified in the "name" key of the option's value) from each choice when rendering the choice in the prompt 3. Add a filter function to enable users to type to filter the available choices, using the name key again 4. Specifies the alternate result template to ensure the result is displayed using the name and not a splat of the choice's values as a string.
func (PromptOption) TextInputOptions ¶
func (option PromptOption) TextInputOptions() (options []texter.Option)
The TextInputOptions method introspects on a PromptOption to return a slice of options to use when creating a textinput prompt.
No options are yet implemented.