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 ¶
- type CancelledMsg
- type ConfirmedMsg
- type Model
- func (m Model) Help() []key.Binding
- func (m Model) Init() tea.Cmd
- func (m *Model) SetActiveColor(c lipgloss.TerminalColor)
- func (m *Model) SetDimensions(w, h int)
- func (m *Model) SetInactiveColor(c lipgloss.TerminalColor)
- func (m *Model) SetMessage(s string)
- func (m *Model) SetMessageStyle(s lipgloss.Style)
- func (m *Model) SetSelectedStyle(s lipgloss.Style)
- func (m *Model) SetTitle(s string)
- func (m *Model) SetUnselectedStyle(s lipgloss.Style)
- func (m *Model) SetValue(v bool)
- func (m Model) Update(msg tea.Msg) (Model, tea.Cmd)
- func (m Model) Value() bool
- func (m Model) View() string
- type Options
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 ¶
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 ¶
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) SetActiveColor ¶
func (m *Model) SetActiveColor(c lipgloss.TerminalColor)
SetActiveColor updates the active border color.
func (*Model) SetDimensions ¶
SetDimensions resizes the surrounding pane.
func (*Model) SetInactiveColor ¶
func (m *Model) SetInactiveColor(c lipgloss.TerminalColor)
SetInactiveColor updates the inactive border color.
func (*Model) SetMessage ¶
SetMessage updates the body text. Useful when the modal is reused across different actions without rebuilding the model.
func (*Model) SetMessageStyle ¶
SetMessageStyle updates the body-text style.
func (*Model) SetSelectedStyle ¶
SetSelectedStyle updates the highlighted-button style. Useful when reacting to a theme swap without rebuilding the model.
func (*Model) SetUnselectedStyle ¶
SetUnselectedStyle updates the dimmed-button style.
func (Model) Update ¶
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.
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.