prompt

package module
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2023 License: MIT Imports: 11 Imported by: 52

README

Prompt

User-friendly interactive prompts for Go.
Based on Bubble Tea. Inspired by Prompts and Gum.

Action Status Codecov Go Reference Go Reference Git tag Go Version

example

Table of Contents

Features

  1. choose lets the user choose one of several strings using the terminal ui.
  2. multichoose lets the user choose multiple strings from multiple strings using the terminal ui.
  3. input lets the user enter a string using the terminal ui. You can specify that only numbers or integers are allowed.
  4. Show help message for keymaps.
  5. Based on Bubble Tea. prompt.Prompt and all child models implement tea.Model.

Screenshots

Choose

Theme Default

example

choose

Theme Arrow

example

choose-theme-arrow

Theme Line

example

choose-theme-line

MultiChoose

Theme Default

example

multichoose

Theme Dot

example

multichoose-theme-dot

Input

example

input

Password input

example

input-echo-password

Password input like linux (do not display any characters)

example

input-echo-none

Only integers can be entered

example

Only numbers can be entered

example

Input with validation

example

input-with-validation

Write

example

write

Show help message

All components support displaying help message for shortcut keys at the bottom.

choose-with-help

Examples:

  1. Choose with help
  2. MultiChoose with help
  3. Input with help
  4. TextArea with help
  5. Toggle with help

License

MIT License.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrModelConversion = errors.New("model conversion failed")
	ErrUserQuit        = errors.New("user quit prompt")
)

Functions

This section is empty.

Types

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 New

func New() *Prompt

New returns a *Prompt using the default style.

func (*Prompt) Ask

func (p *Prompt) Ask(message string) *Prompt

Ask set prompt message

func (Prompt) Choose

func (p Prompt) Choose(choices []string, opts ...choose.Option) (string, error)

Choose lets the user choose one of the given choices.

func (Prompt) Init

func (p Prompt) Init() tea.Cmd

func (Prompt) Input

func (p Prompt) Input(defaultValue string, opts ...input.Option) (string, error)

Input asks the user to enter a string.

func (Prompt) MultiChoose

func (p Prompt) MultiChoose(choices []string, opts ...multichoose.Option) ([]string, error)

MultiChoose lets the user choose multiples from the given choices.

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) 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) Update

func (p Prompt) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (Prompt) View

func (p Prompt) View() string

func (*Prompt) WithHelp added in v0.4.0

func (p *Prompt) WithHelp(enable bool) *Prompt

WithHelp sets whether the help of the keymap is visible

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.

func (*Prompt) WithTestView added in v0.5.1

func (p *Prompt) WithTestView(initView *string, finalView *string) *Prompt

func (Prompt) Write added in v0.7.0

func (p Prompt) Write(defaultValue string) (string, error)

type PromptModel

type PromptModel interface {
	tea.Model
	Data() any          // Returns the final result.
	DataString() string // Returns a string for display in the result position.
	KeyBindings() []key.Binding
	UseKeyQ() bool
	UseKeyEnter() bool
}

Directories

Path Synopsis
choose command
input command
input-echo-none command
input-with-help command
multichoose command
write command
write-with-help command

Jump to

Keyboard shortcuts

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