bubbleconfirm

package
v29.0.0 Latest Latest
Warning

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

Go to latest
Published: May 31, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Undecided = iota
	Yes
	No
)

confirmation result values.

Variables

View Source
var ErrConfirmationFailed = errors.New("failed to confirm, your answers were different")

ErrConfirmationFailed is returned when second answer is not the same with first one.

View Source
var ErrInterrupted = errors.New("interrupted")

ErrInterrupted is returned when the input process is interrupted.

Functions

func Ask

func Ask(question ...Question) (err error)

Ask asks questions and collect answers.

func ValuesFromFlagsOrAsk

func ValuesFromFlagsOrAsk(fset *pflag.FlagSet, title string, flags ...Flag) (values map[string]string, err error)

ValuesFromFlagsOrAsk returns values of flags within map[string]string where map's key is the name of the flag and value is flag's value. when provided, values are collected through command otherwise they're asked by prompting user. title used as a message while prompting.

Types

type Flag

type Flag struct {
	Name       string
	IsRequired bool
}

Flag represents a cmd flag.

func NewFlag

func NewFlag(name string, isRequired bool) Flag

NewFlag creates a new flag.

type Model

type Model struct {
	Question string
	// contains filtered or unexported fields
}

Model represents the bubbletea model for a confirmation prompt.

func NewModel

func NewModel(question string) Model

NewModel creates a new confirmation model with the given question.

func (Model) Choice

func (m Model) Choice() int

Choice returns the selected choice (Yes, No, or Undecided).

func (Model) Init

func (m Model) Init() tea.Cmd

Init initializes the model.

func (Model) Update

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

Update handles messages and updates the model.

func (Model) View

func (m Model) View() string

View renders the confirmation prompt.

type Option

type Option func(*Question)

Option configures Question.

func DefaultAnswer

func DefaultAnswer(answer interface{}) Option

DefaultAnswer sets a default answer to Question.

func GetConfirmation

func GetConfirmation() Option

GetConfirmation prompts confirmation for the given answer.

func HideAnswer

func HideAnswer() Option

HideAnswer hides the answer to prevent secret information being leaked.

func Required

func Required() Option

Required marks the answer as required.

type Question

type Question struct {
	// contains filtered or unexported fields
}

Question holds information on what to ask user and where the answer stored at.

func NewQuestion

func NewQuestion(question string, answer interface{}, options ...Option) Question

NewQuestion creates a new question.

Jump to

Keyboard shortcuts

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