prompt

package
v0.18.5 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package prompt provides a multi-button confirm overlay for the tui/app shell — for questions where a plain yes/no is not enough (e.g. "stop containers / quit and keep running / cancel").

The overlay closes itself and emits a ResultMsg; the hosting Content handles the outcome:

case prompt.ResultMsg:
    switch msg.Choice { case "stop": ...; case "quit": ... }

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Choice

type Choice struct {
	// ID is returned in ResultMsg.Choice (e.g. "stop", "quit", "cancel").
	ID string
	// Label is the button text.
	Label string
}

Choice is one button of a prompt.

type Options

type Options struct {
	// ID names the overlay and is echoed in ResultMsg (default "confirm").
	ID      string
	Title   string
	Message string
	// Choices default to Yes ("yes") / No ("no").
	Choices []Choice
	// Default is the initially selected choice index.
	Default int
	// Danger styles the title with the error color.
	Danger bool
	// MaxWidth bounds the modal (default 70).
	MaxWidth int
}

Options configure New.

type Overlay

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

Overlay is a centered multi-button confirm modal.

func New

func New(opts Options) *Overlay

New creates a prompt overlay. Push it with Host.PushOverlay.

func (*Overlay) ID

func (o *Overlay) ID() string

ID implements app.Overlay.

func (*Overlay) Init

func (o *Overlay) Init() tea.Cmd

Init implements app.Overlay.

func (*Overlay) Update

func (o *Overlay) Update(msg tea.Msg) (app.Overlay, tea.Cmd)

Update implements app.Overlay.

func (*Overlay) View

func (o *Overlay) View(width, height int) string

View implements app.Overlay.

type ResultMsg

type ResultMsg struct {
	// ID names the prompt (Options.ID) so apps with several prompts can tell
	// results apart.
	ID     string
	Choice string
}

ResultMsg is emitted when the prompt closes. Choice is the chosen Choice.ID; empty means the prompt was dismissed with esc.

Jump to

Keyboard shortcuts

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