dialog

package
v0.0.20 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Button added in v0.0.12

type Button struct {
	Label       string
	Accel       string
	Value       string
	Affirmative bool
}

Button is one answer a dialog offers.

Accel is the single key that chooses it outright, drawn inside the label so it is discoverable before it is needed (decision I-7). It is not a held key — that is why y/n are safe here and j/k are not. The reason j/k were kept off the button row is that they are what a reader's fingers are already on when a confirm appears mid-scroll; an accelerator letter nobody is holding cannot be pressed by reflex.

Affirmative is what Confirmed reports for this button. Every button that does the thing is affirmative; the one that backs out is not.

type DialogResultMsg

type DialogResultMsg struct {
	ID        string
	Confirmed bool
	Value     string
}

DialogResultMsg is emitted when a dialog is closed.

Value names the button that was chosen, so a dialog with more than two answers can be told apart by the host: the delete confirm asks "for me" or "for everyone", and the caller has to know which. Confirmed remains the yes/no reading of the same answer — true for any button that acts, false for the one that backs out and for Escape — so the callers that only ever asked one question did not have to learn a second vocabulary.

type Model

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

Model is a modal dialog component.

func NewAlert

func NewAlert(r theme.Roles, id, title, message string) Model

NewAlert creates an alert dialog: one button, nothing to choose between.

func NewChoice added in v0.0.12

func NewChoice(r theme.Roles, id, title, message string, buttons []Button) Model

NewChoice creates a dialog with an arbitrary set of answers.

The first button is the highlighted one, and it must be the one that backs out: Enter accepts whatever is highlighted, so a reflex Enter has to be harmless. NewConfirm and NewAlert are the two shapes that existed before this and are now wrappers, so there is one implementation of the button row, the accelerators and the hint line rather than one per shape.

func NewConfirm

func NewConfirm(r theme.Roles, id, title, message string) Model

NewConfirm creates a two-button confirmation dialog, answerable with y and n as well as with the arrows (decision I-7).

func (Model) Accelerators added in v0.0.14

func (m Model) Accelerators() string

Accelerators is the answer keys in button order: "n/y" for a confirm, "n/m/e" for the delete choice, "" for a dialog whose buttons carry none.

Exported because the frame's hint bar has to name the same letters this dialog's own line does, and the button set is the only thing that knows what they are. The bar used to say "y/n" for every dialog, which was wrong on the delete choice — advertising an inert y on the one surface where a wrong key press is destructive.

func (Model) IsVisible

func (m Model) IsVisible() bool

IsVisible returns whether the dialog is visible.

func (Model) Update

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

Update handles messages.

func (Model) View

func (m Model) View() string

View renders the dialog.

Jump to

Keyboard shortcuts

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