ui

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: Apache-2.0 Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrQuit ends a flow without an error message.
	ErrQuit = errors.New("quit")
	// ErrAborted ends a flow because the user said no or cancelled a form.
	ErrAborted = errors.New("aborted")
)

Functions

func Confirm

func Confirm(u UI, title, description string, def bool) (bool, error)

Confirm asks a yes/no question; description carries any warning, since a full-screen form hides the transcript.

func RunFullscreen

func RunFullscreen(ctx context.Context, title string, out io.Writer, logPath string, flow func(context.Context, UI) error) error

RunFullscreen runs flow full-screen. After the app closes, everything except the raw installer logs is printed to out, and the full transcript is kept at logPath.

func Select

func Select(u UI, title, description string, options []Option, value *string) error

Select asks the user to pick one of options; value holds the default and receives the answer.

Types

type Choice

type Choice struct {
	Key         string
	Title       string
	Description string
	Options     []Option
	Value       *string
}

Choice asks for one of Options.

type Choices

type Choices struct {
	Key         string
	Title       string
	Description string
	Options     []Option
	// Height limits the visible rows; 0 means the default.
	Height   int
	Validate func([]string) error
	Value    *[]string
}

Choices asks for any number of Options.

type Confirmation

type Confirmation struct {
	Key         string
	Title       string
	Description string
	Value       *bool
}

Confirmation asks yes or no.

type Field

type Field interface {
	// contains filtered or unexported methods
}

Field is one question: Input, Choice, Choices or Confirmation.

type Form

type Form struct {
	Pages []Page
}

Form is a set of questions asked together. Fields write the user's answers through their Value pointers, and the initial value of a pointer is the default answer. Plain and Fullscreen render it with huh; uitest answers it from a script.

type Fullscreen

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

Fullscreen runs a flow in a goroutine and renders it as a full-screen app. Flow calls are turned into messages for the bubbletea program.

func (*Fullscreen) Ask

func (f *Fullscreen) Ask(form Form) error

func (*Fullscreen) Begin

func (f *Fullscreen) Begin(title string) func(error)

func (*Fullscreen) Heading

func (f *Fullscreen) Heading(msg string)

func (*Fullscreen) Info

func (f *Fullscreen) Info(msg string)

func (*Fullscreen) Logs

func (f *Fullscreen) Logs() io.Writer

func (*Fullscreen) OK

func (f *Fullscreen) OK(msg string)

func (*Fullscreen) Step

func (f *Fullscreen) Step(ctx context.Context, title string, fn func(context.Context) error) error

func (*Fullscreen) Warn

func (f *Fullscreen) Warn(msg string)

type Input

type Input struct {
	// Key identifies the field to scripted answers; it should be unique within a flow.
	Key         string
	Title       string
	Description string
	// DescriptionFunc replaces Description with text that depends on other answers; Watch is the variable it
	// depends on (a pointer), so the text updates when that answer changes.
	DescriptionFunc func() string
	Watch           any
	// Secret hides what is typed.
	Secret   bool
	Validate func(string) error
	Value    *string
}

Input asks for a line of text.

type Option

type Option struct {
	Label string
	Value string
	// Selected starts the option selected in a Choices field.
	Selected bool
}

Option is one of the answers of a Choice or Choices field.

func Options

func Options(values ...string) []Option

Options makes an Option of each value, labelled by the value itself.

type Page

type Page struct {
	Title       string
	Description string
	// Hidden skips the page when it returns true; it is evaluated when the page is reached, so it can depend
	// on answers given on earlier pages.
	Hidden func() bool
	Fields []Field
}

Page is a group of fields shown together.

type Plain

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

func NewPlain

func NewPlain(out io.Writer) *Plain

func (*Plain) Ask

func (p *Plain) Ask(form Form) error

func (*Plain) Begin

func (p *Plain) Begin(title string) func(error)

func (*Plain) Heading

func (p *Plain) Heading(msg string)

func (*Plain) Info

func (p *Plain) Info(msg string)

func (*Plain) Logs

func (p *Plain) Logs() io.Writer

func (*Plain) OK

func (p *Plain) OK(msg string)

func (*Plain) Step

func (p *Plain) Step(ctx context.Context, title string, fn func(context.Context) error) error

func (*Plain) Warn

func (p *Plain) Warn(msg string)

type UI

type UI interface {
	// Ask shows the questions and returns ErrAborted when the user cancels.
	Ask(form Form) error
	Step(ctx context.Context, title string, fn func(context.Context) error) error
	// Begin marks a long phase without a spinner (e.g. while logs stream); call end when it finishes.
	Begin(title string) (end func(error))
	Logs() io.Writer
	Heading(msg string)
	Info(msg string)
	OK(msg string)
	Warn(msg string)
}

UI is what the command flows talk to; Plain prints line by line, Fullscreen renders a full-screen app.

Directories

Path Synopsis
Package uitest provides a scripted ui.UI for testing flows without a terminal.
Package uitest provides a scripted ui.UI for testing flows without a terminal.

Jump to

Keyboard shortcuts

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