Documentation
¶
Index ¶
- Variables
- type ChooseDirection
- type ChooseModel
- func (m ChooseModel) Data() any
- func (m ChooseModel) DataString() string
- func (m ChooseModel) Init() tea.Cmd
- func (m ChooseModel) KeyBindings() []key.Binding
- func (m ChooseModel) Update(msg tea.Msg) (tea.Model, tea.Cmd)
- func (m ChooseModel) UseKeyEnter() bool
- func (m ChooseModel) UseKeyQ() bool
- func (m ChooseModel) View() string
- type ChooseOption
- type ChooseTheme
- type EchoMode
- type InputMode
- type InputModel
- func (m InputModel) Data() any
- func (m InputModel) DataString() string
- func (m InputModel) Init() tea.Cmd
- func (m InputModel) KeyBindings() []key.Binding
- func (m *InputModel) SetInputLimit(inputLimit InputMode) *InputModeldeprecated
- func (m InputModel) Update(msg tea.Msg) (tea.Model, tea.Cmd)
- func (m InputModel) UseKeyEnter() bool
- func (m InputModel) UseKeyQ() bool
- func (m InputModel) View() string
- func (m *InputModel) WithEchoMode(mode EchoMode) *InputModel
- func (m *InputModel) WithInputMode(mode InputMode) *InputModel
- func (m *InputModel) WithValidateFunc(vf ValidateFunc) *InputModel
- type InputOption
- type ListHandler
- type ListStyle
- type MultiChooseModel
- func (m MultiChooseModel) Data() any
- func (m MultiChooseModel) DataString() string
- func (m MultiChooseModel) Init() tea.Cmd
- func (m MultiChooseModel) KeyBindings() []key.Binding
- func (m MultiChooseModel) Update(msg tea.Msg) (tea.Model, tea.Cmd)
- func (m MultiChooseModel) UseKeyEnter() bool
- func (m MultiChooseModel) UseKeyQ() bool
- func (m MultiChooseModel) View() string
- type Prompt
- func (p *Prompt) Ask(message string) *Prompt
- func (p Prompt) Choose(choices []string, opts ...ChooseOption) (string, error)
- func (p Prompt) Init() tea.Cmd
- func (p Prompt) Input(defaultValue string, opts ...InputOption) (string, error)
- func (p Prompt) InputWithLimit(defaultValue string, inputLimit InputMode) (string, error)deprecated
- func (p Prompt) MultiChoose(choices []string) ([]string, error)
- func (p Prompt) MultiChooseWithStyle(choices []string, style *ListStyle) ([]string, error)
- func (p *Prompt) Run(pm PromptModel) (PromptModel, error)
- func (p *Prompt) SetHelpVisible(visible bool) *Promptdeprecated
- func (p *Prompt) SetModel(pm PromptModel) *Prompt
- func (p Prompt) TextArea(defaultValue string) (string, error)
- func (p Prompt) Toggle(choices []string) (string, error)
- func (p Prompt) ToggleWithStyle(choices []string, style *ListStyle) (string, error)
- func (p Prompt) Update(msg tea.Msg) (tea.Model, tea.Cmd)
- func (p Prompt) View() string
- func (p *Prompt) WithHelp(enable bool) *Prompt
- func (p *Prompt) WithProgramOptions(opts ...tea.ProgramOption) *Prompt
- func (p *Prompt) WithTestView(initView *string, finalView *string) *Prompt
- type PromptModel
- type TextAreaModel
- func (m TextAreaModel) Data() any
- func (m TextAreaModel) DataString() string
- func (m TextAreaModel) Init() tea.Cmd
- func (m TextAreaModel) KeyBindings() []key.Binding
- func (m TextAreaModel) Update(msg tea.Msg) (tea.Model, tea.Cmd)
- func (m TextAreaModel) UseKeyEnter() bool
- func (m TextAreaModel) UseKeyQ() bool
- func (m TextAreaModel) View() string
- type ToggleModeldeprecated
- func (m ToggleModel) Data() any
- func (m ToggleModel) DataString() string
- func (m ToggleModel) Init() tea.Cmd
- func (m ToggleModel) KeyBindings() []key.Binding
- func (m ToggleModel) Update(msg tea.Msg) (tea.Model, tea.Cmd)
- func (m ToggleModel) UseKeyEnter() bool
- func (m ToggleModel) UseKeyQ() bool
- func (m ToggleModel) View() string
- type ValidateFunc
Constants ¶
This section is empty.
Variables ¶
var ( ErrModelConversion = errors.New("model conversion failed") ErrUserQuit = errors.New("user quit prompt") )
var ( DefaultNormalPromptPrefix = "?" DefaultFinishPromptPrefix = "✔" DefaultNormalPromptSuffix = "›" DefaultFinishPromptSuffix = "…" DefaultNormalPromptPrefixStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("14")) DefaultFinishPromptPrefixStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("10")) DefaultErrorPromptPrefixStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("1")) DefaultNormalPromptSuffixStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("6")) DefaultFinishPromptSuffixStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("6")) DefaultNoteStyle = lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{ Light: "#909090", Dark: "#626262", }) DefaultItemStyle = lipgloss.NewStyle() DefaultSelectedItemStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("14")) DefaultChoiceStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("14")) )
var ChooseThemeArrow = ChooseTheme{ Direction: ChooseDirectionV, View: func(choices []string, cursor int) string { s := strings.Builder{} s.WriteString("\n") for i := 0; i < len(choices); i++ { if cursor == i { s.WriteString(DefaultSelectedItemStyle.Render(fmt.Sprintf("❯ %s", choices[i]))) } else { s.WriteString(DefaultItemStyle.Render(fmt.Sprintf(" %s", choices[i]))) } s.WriteString("\n") } return s.String() }, }
var ChooseThemeDefault = ChooseTheme{ Direction: ChooseDirectionV, View: func(choices []string, cursor int) string { s := strings.Builder{} s.WriteString("\n") for i := 0; i < len(choices); i++ { if cursor == i { s.WriteString(DefaultSelectedItemStyle.Render(fmt.Sprintf("• %s", choices[i]))) } else { s.WriteString(DefaultItemStyle.Render(fmt.Sprintf(" %s", choices[i]))) } s.WriteString("\n") } return s.String() }, }
var ChooseThemeLine = ChooseTheme{ Direction: ChooseDirectionH, View: func(choices []string, cursor int) string { s := strings.Builder{} result := make([]string, len(choices)) for index, choice := range choices { if index == cursor { result[index] = DefaultSelectedItemStyle.Render(choice) } else { result[index] = DefaultItemStyle.Render(choice) } } s.WriteString(strings.Join(result, " / ")) return s.String() }, }
Functions ¶
This section is empty.
Types ¶
type ChooseDirection ¶ added in v0.6.0
type ChooseDirection int
const ( ChooseDirectionAll ChooseDirection = iota ChooseDirectionH ChooseDirectionV )
type ChooseModel ¶
type ChooseModel struct {
// contains filtered or unexported fields
}
func NewChooseModel ¶
func NewChooseModel(choices []string, opts ...ChooseOption) *ChooseModel
func (ChooseModel) Data ¶
func (m ChooseModel) Data() any
func (ChooseModel) DataString ¶
func (m ChooseModel) DataString() string
func (ChooseModel) Init ¶
func (m ChooseModel) Init() tea.Cmd
func (ChooseModel) KeyBindings ¶
func (m ChooseModel) KeyBindings() []key.Binding
func (ChooseModel) UseKeyEnter ¶ added in v0.4.0
func (m ChooseModel) UseKeyEnter() bool
func (ChooseModel) UseKeyQ ¶ added in v0.3.1
func (m ChooseModel) UseKeyQ() bool
func (ChooseModel) View ¶
func (m ChooseModel) View() string
type ChooseOption ¶ added in v0.6.0
type ChooseOption func(*ChooseModel)
func WithTheme ¶ added in v0.6.0
func WithTheme(theme ChooseTheme) ChooseOption
type ChooseTheme ¶ added in v0.6.0
type ChooseTheme struct {
Direction ChooseDirection
View func([]string, int) string
}
type EchoMode ¶ added in v0.5.0
const ( // EchoNormal displays text as is. This is the default behavior. EchoNormal EchoMode = textinput.EchoNormal // EchoPassword displays the EchoCharacter mask instead of actual // characters. This is commonly used for password fields. EchoPassword EchoMode = textinput.EchoPassword // EchoNone displays nothing as characters are entered. This is commonly // seen for password fields on the command line. EchoNone EchoMode = textinput.EchoNone )
type InputModel ¶
type InputModel struct {
ItemStyle lipgloss.Style
SelectedItemStyle lipgloss.Style
ChoiceStyle lipgloss.Style
// contains filtered or unexported fields
}
func NewInputModel ¶
func NewInputModel(defaultValue string) *InputModel
func (InputModel) Data ¶
func (m InputModel) Data() any
func (InputModel) DataString ¶
func (m InputModel) DataString() string
func (InputModel) Init ¶
func (m InputModel) Init() tea.Cmd
func (InputModel) KeyBindings ¶
func (m InputModel) KeyBindings() []key.Binding
func (*InputModel) SetInputLimit
deprecated
func (m *InputModel) SetInputLimit(inputLimit InputMode) *InputModel
Deprecated: use InputModel.WithInputMode instead.
func (InputModel) UseKeyEnter ¶ added in v0.4.0
func (m InputModel) UseKeyEnter() bool
func (InputModel) UseKeyQ ¶ added in v0.3.1
func (m InputModel) UseKeyQ() bool
func (InputModel) View ¶
func (m InputModel) View() string
func (*InputModel) WithEchoMode ¶ added in v0.5.0
func (m *InputModel) WithEchoMode(mode EchoMode) *InputModel
func (*InputModel) WithInputMode ¶ added in v0.5.0
func (m *InputModel) WithInputMode(mode InputMode) *InputModel
func (*InputModel) WithValidateFunc ¶ added in v0.5.0
func (m *InputModel) WithValidateFunc(vf ValidateFunc) *InputModel
type InputOption ¶ added in v0.5.0
type InputOption func(*InputModel)
func WithEchoMode ¶ added in v0.5.0
func WithEchoMode(mode EchoMode) InputOption
func WithInputMode ¶ added in v0.5.0
func WithInputMode(mode InputMode) InputOption
func WithValidateFunc ¶ added in v0.5.0
func WithValidateFunc(vf ValidateFunc) InputOption
type ListHandler ¶
type ListHandler struct {
// contains filtered or unexported fields
}
func NewListHandler ¶
func NewListHandler(choiceCount int, style *ListStyle) *ListHandler
func (ListHandler) Cursor ¶
func (h ListHandler) Cursor() int
func (*ListHandler) MoveNext ¶
func (h *ListHandler) MoveNext()
func (*ListHandler) MovePrev ¶
func (h *ListHandler) MovePrev()
func (ListHandler) Style ¶
func (h ListHandler) Style() *ListStyle
type ListStyle ¶
type ListStyle struct {
ItemStyle lipgloss.Style
SelectedItemStyle lipgloss.Style
ChoiceStyle lipgloss.Style
}
func NewListStyle ¶
func NewListStyle() *ListStyle
type MultiChooseModel ¶
type MultiChooseModel struct {
ListHandler
// contains filtered or unexported fields
}
func NewMultiChooseModel ¶
func NewMultiChooseModel(choices []string) *MultiChooseModel
func NewMultiChooseModelWithStyle ¶
func NewMultiChooseModelWithStyle(choices []string, style *ListStyle) *MultiChooseModel
func (MultiChooseModel) Data ¶
func (m MultiChooseModel) Data() any
func (MultiChooseModel) DataString ¶
func (m MultiChooseModel) DataString() string
func (MultiChooseModel) Init ¶
func (m MultiChooseModel) Init() tea.Cmd
func (MultiChooseModel) KeyBindings ¶
func (m MultiChooseModel) KeyBindings() []key.Binding
func (MultiChooseModel) UseKeyEnter ¶ added in v0.4.0
func (m MultiChooseModel) UseKeyEnter() bool
func (MultiChooseModel) UseKeyQ ¶ added in v0.3.1
func (m MultiChooseModel) UseKeyQ() bool
func (MultiChooseModel) View ¶
func (m MultiChooseModel) View() string
type Prompt ¶
type Prompt struct {
// Style
Message string
NormalPrefix string
FinishPrefix string
NormalSuffix string
FinishSuffix string
PrefixStyle lipgloss.Style
FinishPrefixStyle lipgloss.Style
SuffixStyle lipgloss.Style
FinishSuffixStyle lipgloss.Style
// contains filtered or unexported fields
}
func (Prompt) Choose ¶
func (p Prompt) Choose(choices []string, opts ...ChooseOption) (string, error)
Choose lets the user choose one of the given choices.
func (Prompt) Input ¶
func (p Prompt) Input(defaultValue string, opts ...InputOption) (string, error)
Input asks the user to enter a string.
func (Prompt) MultiChoose ¶
MultiChoose lets the user choose multiples from the given choices. Appearance uses the default style.
func (Prompt) MultiChooseWithStyle ¶
MultiChooseWithStyle lets the user choose one of the given choices. Appearance uses the given style.
func (*Prompt) Run ¶
func (p *Prompt) Run(pm PromptModel) (PromptModel, error)
Run runs the program using the given model, blocking until the user chooses or exits.
func (*Prompt) SetHelpVisible
deprecated
func (*Prompt) SetModel ¶
func (p *Prompt) SetModel(pm PromptModel) *Prompt
SetModel sets the model used by the prompt. In most cases you won't need to use this.
func (Prompt) Toggle ¶
Toggle lets the user choose one of the given choices. Appearance uses the default style.
func (Prompt) ToggleWithStyle ¶
ToggleWithStyle lets the user choose one of the given choices. Appearance uses the given style.
func (*Prompt) WithProgramOptions ¶ added in v0.4.0
func (p *Prompt) WithProgramOptions(opts ...tea.ProgramOption) *Prompt
WithProgramOptions sets the `tea.ProgramOption` passed when calling `tea.NewProgram`. This function is mainly used for testing, usually you don't need to use this function.
type PromptModel ¶
type TextAreaModel ¶ added in v0.4.0
type TextAreaModel struct {
// contains filtered or unexported fields
}
func NewTextAreaModel ¶ added in v0.4.0
func NewTextAreaModel(defaultValue string) *TextAreaModel
func (TextAreaModel) Data ¶ added in v0.4.0
func (m TextAreaModel) Data() any
func (TextAreaModel) DataString ¶ added in v0.4.0
func (m TextAreaModel) DataString() string
func (TextAreaModel) Init ¶ added in v0.4.0
func (m TextAreaModel) Init() tea.Cmd
func (TextAreaModel) KeyBindings ¶ added in v0.4.0
func (m TextAreaModel) KeyBindings() []key.Binding
func (TextAreaModel) UseKeyEnter ¶ added in v0.4.0
func (m TextAreaModel) UseKeyEnter() bool
func (TextAreaModel) UseKeyQ ¶ added in v0.4.0
func (m TextAreaModel) UseKeyQ() bool
func (TextAreaModel) View ¶ added in v0.4.0
func (m TextAreaModel) View() string
type ToggleModel
deprecated
type ToggleModel struct {
ListHandler
// contains filtered or unexported fields
}
Deprecated: use Choose([]string{}, WithTheme(ChooseThemeLine)) instead.
func NewToggleModel ¶
func NewToggleModel(choices []string) *ToggleModel
func NewToggleModelWithStyle ¶
func NewToggleModelWithStyle(choices []string, style *ListStyle) *ToggleModel
func (ToggleModel) Data ¶
func (m ToggleModel) Data() any
func (ToggleModel) DataString ¶
func (m ToggleModel) DataString() string
func (ToggleModel) Init ¶
func (m ToggleModel) Init() tea.Cmd
func (ToggleModel) KeyBindings ¶
func (m ToggleModel) KeyBindings() []key.Binding
func (ToggleModel) UseKeyEnter ¶ added in v0.4.0
func (m ToggleModel) UseKeyEnter() bool
func (ToggleModel) UseKeyQ ¶ added in v0.3.1
func (m ToggleModel) UseKeyQ() bool
func (ToggleModel) View ¶
func (m ToggleModel) View() string
type ValidateFunc ¶ added in v0.5.0
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
choose
command
|
|
|
choose-theme-arrow
command
|
|
|
choose-theme-line
command
|
|
|
choose-with-help
command
|
|
|
input
command
|
|
|
input-echo-none
command
|
|
|
input-echo-password
command
|
|
|
input-integer-only
command
|
|
|
input-number-only
command
|
|
|
input-with-help
command
|
|
|
input-with-validation
command
|
|
|
multichoose
command
|
|
|
multichoose-with-help
command
|
|
|
textarea
command
|
|
|
textarea-with-help
command
|
|
|
toggle
command
|
|
|
toggle-with-help
command
|










