texter

package
v0.0.0-...-8b058bf Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultResultTemplate = `
{{- print .Prompt " " (Foreground "32"  (Mask .FinalValue)) "\n" -}}
`

The default result template returns the prompt followed by a space and the input highlighted in blue.

View Source
const TemplateCustomInvalidMessage = `` /* 162-byte string literal not displayed */

This template is the same as the default except that the invalid input message is determined by the options passed to the instance.

View Source
const TemplateDefault = `` /* 176-byte string literal not displayed */

The default template for text input; shows the prompt message followed by a blank line before the input field. If the input length is zero, it reports in bold orange text that the input is invalid because it cannot be empty. If any characters have been written, it instead displays that teh input is valid in bold blue text.

Variables

This section is empty.

Functions

func New

func New(message string, options ...Option) *textinput.TextInput

Create a new textinput prompt by specifying a message to display to the user to explain what text they should input. Includes a default placeholder and validation message reminding them that the input cannot be empty. Any options passed to this function are applied in the order they are specified and after the defaults are set.

func NewValidatable

func NewValidatable(message string, validateFunc func(s string) bool, options ...Option) *textinput.TextInput

This helper function provides a shorthand for creating a textinput prompt with a custom validation function. It is functionally identical to the New() function except that it requires a validation function (leading to slightly improved UX when developing and using a language server) and prepends the validation function to the list of any further options.

func NewValidatableWithCustomMessage

func NewValidatableWithCustomMessage(
	message string,
	validateFunc func(s string) bool,
	validateMessage string,
	options ...Option,
) *textinput.TextInput

This helper function provides a shorthand for creating a textinput prompt with a custom validation function. It is functionally identical to the New() function except that it requires a validation function and string for the message to display when the input fails validation (leading to slightly improved UX when developing and using a language server) and prepends the validation function to the list of any further options.

func NewValidatableWithCustomMessageFunc

func NewValidatableWithCustomMessageFunc(
	message string,
	validateFunc func(s string) bool,
	validateMessageFunc func() string,
	options ...Option,
) *textinput.TextInput

This helper function provides a shorthand for creating a textinput prompt with a custom validation function. It is functionally identical to the New() function except that it requires a validation function and function for determiningthe message to display when the input fails validation (leading to slightly improved UX when developing and using a language server) and prepends the validation function to the list of any further options.

Types

type Option

type Option func(prompt *textinput.TextInput)

Options are functions which modify a TextInput prompt. They provide a semantic way to both discover configuration options for a TextInput prompt and to pass them dynamically as needed.

func WithCharLimit

func WithCharLimit(limit int) Option

This option sets a maximum length to the input for the prompt. By default, the prompt does not have a limit.

func WithColorProfile

func WithColorProfile(profile termenv.Profile) Option

This option allows you to override how colors are rendered. By default, the underlying prompt queries the terminal.

func WithExtendedTemplateFuncs

func WithExtendedTemplateFuncs(funcMap template.FuncMap) Option

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 TextInput: https://pkg.go.dev/github.com/erikgeiser/promptkit/textinput#TextInput.ExtendedTemplateFuncs and for template.FuncMap: https://pkg.go.dev/text/template#FuncMap

func WithHidden

func WithHidden(hidden bool) Option

This option overrides whether the prompt should treat the input as secret or not. If set to true, the prompt will mask the input to prevent anyone from reading it off the screen.

func WithHideMask

func WithHideMask(mask rune) Option

This option overrides the default hide mask for the prompt's input if it is marked as hidden. The mask will be rendered to the screen once for every rune the user inputs.

func WithInitialValue

func WithInitialValue(value string) Option

This option sets the initial value to be passed to the input, enabling them to hit enter to accept or to edit the value first. For more information, see the docs for TextInput: https://pkg.go.dev/github.com/erikgeiser/promptkit/textinput#TextInput.InitialValue

func WithInputBackgroundStyle

func WithInputBackgroundStyle(style lipgloss.Style) Option

This option allows you to override the default style for the background of the input text box itself. Pass a lipgloss style and it will be applied inline to to the input text box.

func WithInputCursorStyle

func WithInputCursorStyle(style lipgloss.Style) Option

This option allows you to override the default style for the cursor when inputting text to the prompt. Pass a lipgloss style and it will be applied inline to to the cursor.

func WithInputPlaceholderStyle

func WithInputPlaceholderStyle(style lipgloss.Style) Option

This option allows you to override the default style for the plcaseholder text itself. Pass a lipgloss style and it will be applied inline to to the placeholder text.

func WithInputTextStyle

func WithInputTextStyle(style lipgloss.Style) Option

This option allows you to override the default style for the input text itself. Pass a lipgloss style and it will be applied inline to to the input text.

func WithInputWidth

func WithInputWidth(width int) Option

This option defines the maximum number of characters that the input can display at a time. If a user types in more characters than the width, the viewport for the input prompt will scroll with their cursor.

func WithKeyMap

func WithKeyMap(keymap textinput.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{"shift+esc"} // replace ctrl+c with shift+escape to abort
texter.NewModel("Do you want to continue?", texter.WithKeyMap(keymap))

func WithPlaceholder

func WithPlaceholder(placeholder string) Option

This option overrides the default placeholder text the prompt displays when the user has not typed any text yet. For more information, see the docs for TextInput: https://pkg.go.dev/github.com/erikgeiser/promptkit/textinput#TextInput.Placeholder

func WithResultTemplate

func WithResultTemplate(template string) Option

This option overrides the default template the prompt uses to display results to the terminal. For more information, see the docs for TextInput: https://pkg.go.dev/github.com/erikgeiser/promptkit/textinput#TextInput.ResultTemplate

func WithTemplate

func WithTemplate(template string) Option

This option overrides the default template the prompt uses to display to the terminal. For more information, see the docs for TextInput: https://pkg.go.dev/github.com/erikgeiser/promptkit/textinput#TextInput.Template

func WithValidateFunc

func WithValidateFunc(validateFunc func(string) bool) Option

This option overrides the default validation check for the prompt (the default only checks that the input is not empty), preventing submission if the input does not pass validation. If you pass nil for this option, no validation is performed. To use this option, pass a function which takes an input string and returns true if it is valid and false if it is not.

func WithValidationMessage

func WithValidationMessage(message string) Option

This option is a helper option for replacing the message from the default validation check with one specific to the validation actually being performed. Only use this if you are also changing the default validation for the prompt. Do not use this and WithValidationMessageFunc() together as they are different implementations of the same thing.

func WithValidationMessageFunc

func WithValidationMessageFunc(messageFunc func() string) Option

This option is a helper option for replacing the message from the default validation check with a dynamic message that can be aware of why the validation failed. Only use this if you are also changing the default validation for the prompt. Do not use this and WithValidationMessage() together as they are different implementations of the same thing.

func WithWrapMode

func WithWrapMode(mode promptkit.WrapMode) Option

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.

Jump to

Keyboard shortcuts

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