Documentation ¶
Index ¶
- Constants
- func New(message string, options ...Option) *confirmation.Confirmation
- func NewModel(message string, options ...Option) *confirmation.Model
- type Option
- func WithColorProfile(profile termenv.Profile) Option
- func WithCustomAnswers(yesText string, noText string) Option
- func WithDefaultValue(defaultValue confirmation.Value) Option
- func WithExtendedTemplateFuncs(funcMap template.FuncMap) Option
- func WithInvertedColorTemplate() Option
- func WithKeyMap(keymap confirmation.KeyMap) Option
- func WithResultTemplate(template string) Option
- func WithTemplate(template string) Option
- func WithWrapMode(mode promptkit.WrapMode) Option
Constants ¶
const DefaultResultTemplate = `` /* 136-byte string literal not displayed */
The default template for displaying the results of the prompt. It shows the prompt followed by the choice after a space, highlighted in blue for yes and orange for no.
const DefaultTemplate = `` /* 243-byte string literal not displayed */
The default template for displaying the prompt and available choices. It shows the prompt message with a blank space before displaying yes and no. When yes is selected, it is highlighted in blue. When no is selected, it is highlighted in orange.
const InvertedColorResultTemplate = `` /* 136-byte string literal not displayed */
This template is the same as the default result template except that the colors for yes and no are inverted; orange for yes and blue for no. Useful when you want to highlight that _confirming_ is the dangerous option.
const InvertedColorTemplate = `` /* 243-byte string literal not displayed */
This template is the same as the default template except that the colors for yes and no are inverted; orange for yes and blue for no. Useful when you want to highlight that _confirming_ is the dangerous option.
const ResultTemplateCustomOptions = `` /* 132-byte string literal not displayed */
A helper result template for when you want to use words other than "yes" and "no" to answer the prompt question. It is otherwise identical in behavior to the default result template.
const TemplateCustomOptions = `` /* 262-byte string literal not displayed */
A helper template for when you want to use words other than "yes" and "no" to answer the prompt question. It is otherwise identical in behavior to the default template.
Variables ¶
This section is empty.
Functions ¶
func New ¶
func New(message string, options ...Option) *confirmation.Confirmation
Create a new confirmation prompt by specifying a message to ask the user to answer with yes or no and zero or more options to configure the prompt's behavior.
Types ¶
type Option ¶
type Option func(prompt *confirmation.Confirmation)
Options are functions which modify a Confirmation prompt. They provide a semantic way to both discover configuration options for a Confirmation prompt and to pass them dynamically as needed.
func WithColorProfile ¶
This option allows you to override how colors are rendered. By default, the underlying prompt queries the terminal.
func WithCustomAnswers ¶
This option allows you to override the default display words for confirming/disconfirming ("yes" and "no" respectively) to something else. This is a shorthand option which also replaces the default template and result template for you to ones which respect the newly chosen option texts. If you want to use different display words for the prompt _and_ a custom template, you will need to update your template accordingly and should not use this option.
func WithDefaultValue ¶
func WithDefaultValue(defaultValue confirmation.Value) Option
This option allows you to override the default value of the prompt (unconfirmed) when instantiating the prompt.
func WithExtendedTemplateFuncs ¶
This option allows you to pass additional functions for the templates used in the prompt. Specify one or more with their name as the key in a map. This option will add the function if it is not already registered or overwrite an extended function if it already exists for the prompt. For more information, see the docs for Confirmation: https://pkg.go.dev/github.com/erikgeiser/promptkit/confirmation#Confirmation.ExtendedTemplateFuncs and for template.FuncMap: https://pkg.go.dev/text/template#FuncMap
func WithInvertedColorTemplate ¶
func WithInvertedColorTemplate() Option
This option inverts the colors of the template; orange for yes and blue for no. Use when confirming is the more dangerous or destructive option.
func WithKeyMap ¶
func WithKeyMap(keymap confirmation.KeyMap) Option
This option allows you to override the default key map for the prompt. Specify the key presses (or combinations) you want to trigger an action from as strings for their specified action. Note that this option entirely replaces the existing key map; it is best practice to create the default key map, modify it, and then pass the modified map to this option instead of creating the key map inline.
For example:
keymap := confirmation.NewDefaultKeyMap() // start with default map keymap.Abort := []string{"esc"} // replace ctrl+c with escape to abort confirmer.NewModel("What's your name?", confirmer.WithKeyMap(keymap))
func WithResultTemplate ¶
This option overrides the default template the prompt uses to display results to the terminal. For more information, see the docs for Confirmation: https://pkg.go.dev/github.com/erikgeiser/promptkit/confirmation#Confirmation.ResultTemplate
func WithTemplate ¶
This option overrides the default template the prompt uses to display to the terminal. For more information, see the docs for Confirmation: https://pkg.go.dev/github.com/erikgeiser/promptkit/confirmation#Confirmation.Template
func WithWrapMode ¶
This option allows you to override the default wrap mode for the prompt (promptkit.WordWrap). The default mode wraps the input at width, wrapping on last white space before the word which runs over the width so that words are not cut in the middle. The other built-in modes are HardWrap, which wraps at the specified width regardless of the text, and nil which disables wrapping. You can also supply your own wrap mode by specifying a function which takes an input string and width in and returns the wrapped string.