prompt

package module
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2024 License: MIT Imports: 8 Imported by: 35

README

✔ Prompt

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

Action Status Codecov Go Report Card Go Reference Git tag Go Version

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

example

choose

Modify the theme of choose:

example

choose-themes

AdvancedChoose

example

advancedchoose

MultiChoose

example

multichoose

Modify the theme of choose:

example

multichoose-themes

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

Prompt Theme

All model themes can be customized. The prompt's theme can also be customized.

example

prompt-themes

Customization

Some options can be passed when using these models, such as whether to display help information, etc.

All available options and examples can be seen in the following files:

License

MIT License.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrModelConversion = errors.New("model conversion failed")
	ErrUserQuit        = constants.ErrUserQuit
)

Functions

func ThemeDefault added in v0.8.0

func ThemeDefault(msg string, state State, model string) string

func ThemeDefaultClear added in v0.8.5

func ThemeDefaultClear(msg string, state State, model string) string

ThemeDefaultClear is basically the same as ThemeDefault, but it will clear the screen after the selection is completed or after exiting.

Types

type Option added in v0.8.0

type Option func(*Prompt)

func WithTeaProgramOpts added in v0.9.0

func WithTeaProgramOpts(opts ...tea.ProgramOption) Option

func WithTheme added in v0.6.0

func WithTheme(theme Theme) Option

type Prompt

type Prompt struct {
	Message string
	// contains filtered or unexported fields
}

func New

func New(opts ...Option) *Prompt

New returns a *Prompt using the default style.

func (Prompt) AdvancedChoose added in v0.9.0

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

Choose lets the user choose one of the given choices.

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, opts ...tea.ProgramOption) (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) Write added in v0.7.0

func (p Prompt) Write(defaultValue string, opts ...write.Option) (string, error)

type PromptModel

type PromptModel interface {
	tea.Model
	DataString() string // Returns a string for display in the result position.
	Quitting() bool
	Error() error
	TeaProgramOpts() []tea.ProgramOption
}

type State added in v0.8.0

type State int
const (
	StateNormal State = iota
	StateFinish
	StateError
)

type Theme added in v0.8.0

type Theme func(string, State, string) string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳