prompt

package
v0.0.0-...-d0e6ce9 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultErrorMsgPrefix = "✘"
	// DefaultGoodPrompt     = "✔"
	//DefaultPrompt        = ""
	DefaultConfirmPrompt = "?"
)
View Source
const (
	FGBold attribute
	FGFaint
	FGItalic
	FGUnderline
)

Foreground weight/decoration attributes.

View Source
const (
	FGBlack attribute = iota + 30
	FGRed
	FGGreen
	FGYellow
	FGBlue
	FGMagenta
	FGCyan
	FGWhite
)

Foreground color attributes

View Source
const (
	BGBlack attribute = iota + 40
	BGRed
	BGGreen
	BGYellow
	BGBlue
	BGMagenta
	BGCyan
	BGWhite
)

Background color attributes

View Source
const (
	//DefaultPrompt            = "Please Input: "
	DefaultPrompt            = "?"
	DefaultValidateOkPrefix  = "✔"
	DefaultValidateErrPrefix = "✘"

	ColorPrompt = "2"
)
View Source
const DONE = "DONE"

Variables

View Source
var FuncMap = template.FuncMap{
	"black":     Styler(FGBlack),
	"red":       Styler(FGRed),
	"green":     Styler(FGGreen),
	"yellow":    Styler(FGYellow),
	"blue":      Styler(FGBlue),
	"magenta":   Styler(FGMagenta),
	"cyan":      Styler(FGCyan),
	"white":     Styler(FGWhite),
	"bgBlack":   Styler(BGBlack),
	"bgRed":     Styler(BGRed),
	"bgGreen":   Styler(BGGreen),
	"bgYellow":  Styler(BGYellow),
	"bgBlue":    Styler(BGBlue),
	"bgMagenta": Styler(BGMagenta),
	"bgCyan":    Styler(BGCyan),
	"bgWhite":   Styler(BGWhite),
	"bold":      Styler(FGBold),
	"faint":     Styler(FGFaint),
	"italic":    Styler(FGItalic),
	"underline": Styler(FGUnderline),
}

FuncMap defines template helpers for the output. It can be extended as a regular map.

View Source
var ResetCode = fmt.Sprintf("%s%dm", esc, reset)

ResetCode is the character code used to reset the terminal formatting

Functions

func Done

func Done() tea.Msg

func FontColor

func FontColor(str, color string) string

FontColor sets the color of the given string and bolds the font

func GenMask

func GenMask(l int) string

GenMask generate a mask string of the specified length

func GenStr

func GenStr(l int, s string) string

GenStr generate a string of the specified length, the string is composed of the given characters

func Styler

func Styler(attrs ...attribute) func(interface{}) string

Styler returns a func that applies the attributes given in the Styler call to the provided string.

func VFDoNothing

func VFDoNothing(_ string) error

VFDoNothing is a verification function that does nothing

func VFNotBlank

func VFNotBlank(s string) error

VFNotBlank is a verification function that checks whether the input is empty

Types

type Confirm

type Confirm struct {
	ConfirmConfig
	Message string
	Prompt  string

	FuncMap template.FuncMap

	// Default is the initial value for the confirm
	Default bool
	// contains filtered or unexported fields
}

Confirm is a regular text input that accept yes/no answers. Response type is a bool.

func NewDefaultConfirm

func NewDefaultConfirm(message string, defaultConfirm bool) Confirm

func (*Confirm) Run

func (c *Confirm) Run() (bool, error)

type ConfirmConfig

type ConfirmConfig struct {
	MessageTpl    string
	PromptTpl     string
	InvalidTpl    string
	ErrorMsgTpl   string
	SuccessMsgTpl string
}

type EchoMode

type EchoMode int

EchoMode sets the input behavior of the text input field.

const (
	// EchoNormal displays text as is. This is the default behavior.
	EchoNormal EchoMode = iota

	// EchoPassword displays the EchoCharacter mask instead of actual
	// characters.  This is commonly used for password fields.
	EchoPassword

	// EchoNone displays nothing as characters are entered. This is commonly
	// seen for password fields on the command line.
	EchoNone
)

copy from textinput.Model

type Model

type Model struct {
	// CharLimit is the maximum amount of characters this input element will
	// accept. If 0 or less, there's no limit.
	CharLimit int

	// Width is the maximum number of characters that can be displayed at once.
	// It essentially treats the text field like a horizontally scrolling
	// viewport. If 0 or less this setting is ignored.
	Width int

	// Prompt is the prefix of the prompt library, the user needs to define
	// the format(including spaces)
	Prompt string

	// ValidateFunc is a "real-time verification" function, which verifies
	// whether the terminal input data is legal in real time
	ValidateFunc func(string) error

	// ValidateOkPrefix is the prompt prefix when the validation fails
	ValidateOkPrefix string

	// ValidateErrPrefix is the prompt prefix when the verification is successful
	ValidateErrPrefix string

	// EchoMode sets the input behavior of the text input field.
	EchoMode EchoMode
	// contains filtered or unexported fields
}

Model is a data container used to store TUI status information, the ui rendering success style is as follows:

✔ Please Input: aaaa

func (Model) Canceled

func (m Model) Canceled() bool

Canceled determine whether the operation is cancelled

func (*Model) Update

func (m *Model) Update(msg tea.Msg) (*Model, tea.Cmd)

Update method responds to various events and modifies the data model according to the corresponding events

func (Model) Value

func (m Model) Value() string

Value return the input string

func (Model) View

func (m Model) View() string

View reads the data state of the data model for rendering

Jump to

Keyboard shortcuts

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