confirm

package
v0.17.0 Latest Latest
Warning

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

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

Documentation

Overview

Package confirm provides a modal yes/no dialog component. It renders a bordered titled pane with a message body and two side-by-side buttons, and resolves to a ConfirmedMsg or CancelledMsg via tea.Cmd when the user commits a choice.

The component is meant to be hosted in the standard modal pattern:

if s.confirmUp {
    return layout.ZStack(
        baseLayout,
        layout.Center(48, 7, layout.Sized(&s.confirm)),
    )
}
return baseLayout

While the modal is up, the parent screen returns true from IsCapturingKeys() so the app shell suppresses its global keys (q, t, esc-pop) and the modal owns input. The parent also forwards every tea.Msg to the confirm and matches confirm.ConfirmedMsg / confirm.CancelledMsg in its own Update to dismiss the modal and act on the result.

Keys (always active when the modal is rendered):

left / right / h / l   move selection
tab / shift+tab        move selection
y / Y                  commit Yes
n / N                  commit No
enter                  commit current selection
esc                    commit No

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CancelledMsg

type CancelledMsg struct{}

CancelledMsg is emitted when the user picks the cancel button (or hits esc).

type ConfirmedMsg

type ConfirmedMsg struct{}

ConfirmedMsg is emitted when the user picks the confirm button.

type Model

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

Model is the confirm dialog's exported state.

func New

func New(opts Options) Model

New constructs a confirm dialog. Always renders in the active border state — the modal owns input whenever it's visible, so there's no "blurred" state to model.

func (Model) Help

func (m Model) Help() []key.Binding

Help returns the keys this dialog responds to. Compose into the parent's Help() while the modal is up so the hint strip reflects the modal context.

func (Model) Init

func (m Model) Init() tea.Cmd

Init is a no-op.

func (*Model) SetActiveColor

func (m *Model) SetActiveColor(c lipgloss.TerminalColor)

SetActiveColor updates the active border color.

func (*Model) SetDimensions

func (m *Model) SetDimensions(w, h int)

SetDimensions resizes the surrounding pane.

func (*Model) SetInactiveColor

func (m *Model) SetInactiveColor(c lipgloss.TerminalColor)

SetInactiveColor updates the inactive border color.

func (*Model) SetMessage

func (m *Model) SetMessage(s string)

SetMessage updates the body text. Useful when the modal is reused across different actions without rebuilding the model.

func (*Model) SetMessageStyle

func (m *Model) SetMessageStyle(s lipgloss.Style)

SetMessageStyle updates the body-text style.

func (*Model) SetSelectedStyle

func (m *Model) SetSelectedStyle(s lipgloss.Style)

SetSelectedStyle updates the highlighted-button style. Useful when reacting to a theme swap without rebuilding the model.

func (*Model) SetTitle

func (m *Model) SetTitle(s string)

SetTitle sets the title shown on the pane's top border.

func (*Model) SetUnselectedStyle

func (m *Model) SetUnselectedStyle(s lipgloss.Style)

SetUnselectedStyle updates the dimmed-button style.

func (*Model) SetValue

func (m *Model) SetValue(v bool)

SetValue overwrites the current selection.

func (Model) Update

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

Update handles selection movement and commit. Returns a tea.Cmd carrying ConfirmedMsg or CancelledMsg when the user commits; the parent screen matches the result in its own Update to dismiss the modal and act.

All keys are active — the modal is the only thing focused while it's up.

func (Model) Value

func (m Model) Value() bool

Value reports the current selection. true = confirm, false = cancel.

func (Model) View

func (m Model) View() string

View renders the dialog as a bordered pane.

type Options

type Options struct {
	// Width and Height set the pane's outer dimensions. SetDimensions
	// overrides these later if the host re-sizes the modal.
	Width, Height int

	// Title sits on the top border (e.g. "Cancel Run", "Delete file"). Defaults
	// to "confirm".
	Title string

	// Message is the body text shown above the buttons. Multi-line strings are
	// supported; the component does not wrap.
	Message string

	// Confirm and Cancel are the rendered button labels. Default to "Yes"
	// and "No" — wrap your own text ("Yes, cancel", "Keep running").
	Confirm string
	Cancel  string

	// Initial picks which side starts highlighted. false (the zero value)
	// puts the cursor on Cancel, which is the safer default for destructive
	// actions. Set true when the affirmative is the expected path.
	Initial bool

	// SelectedStyle styles the active button. Brackets are part of the render.
	SelectedStyle lipgloss.Style
	// UnselectedStyle styles the inactive button.
	UnselectedStyle lipgloss.Style

	// MessageStyle styles the body text. Defaults to no styling.
	MessageStyle lipgloss.Style

	// Pane pass-throughs. Unset fields fall back to ThickBorder when active,
	// NormalBorder when inactive, and SlotBracketsNone.
	ActiveColor    lipgloss.TerminalColor
	InactiveColor  lipgloss.TerminalColor
	ActiveBorder   lipgloss.Border
	InactiveBorder lipgloss.Border
	SlotBrackets   pane.SlotBracketStyle
}

Options configures a new confirm dialog. Zero-value fields fall back to defaults; start from theme.Confirm() to fill in the color tokens.

Jump to

Keyboard shortcuts

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