Documentation
¶
Overview ¶
Package confirmation renders a two-button yes/no prompt with focus-managed buttons, single-keystroke y/n shortcuts, and dangerous-action styling.
The component is a thin Bubble Tea model. The parent is expected to embed it inside a modal or inline panel and listen for ConfirmMsg / CancelMsg from the returned tea.Cmd. The prompt text reflows to the configured width using muesli/reflow/wordwrap so long questions render cleanly.
Index ¶
- type CancelMsg
- type Confirm
- func (c Confirm) FocusedYes() bool
- func (c Confirm) Init() tea.Cmd
- func (c Confirm) Update(msg tea.Msg) (Confirm, tea.Cmd)
- func (c Confirm) View() string
- func (c Confirm) WithDangerous(d bool) Confirm
- func (c Confirm) WithDefault(yes bool) Confirm
- func (c Confirm) WithNoLabel(s string) Confirm
- func (c Confirm) WithPrompt(s string) Confirm
- func (c Confirm) WithWidth(w int) Confirm
- func (c Confirm) WithYesLabel(s string) Confirm
- type ConfirmMsg
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Confirm ¶
type Confirm struct {
// contains filtered or unexported fields
}
Confirm is a Bubble Tea model for a yes/no prompt.
func New ¶
New constructs a Confirm using the given theme. Defaults: labels "Yes" and "No", focus on No (the safer default for destructive prompts), reflow width 60.
func (Confirm) FocusedYes ¶
FocusedYes reports whether Yes currently has focus.
func (Confirm) Update ¶
Update handles key input. Tab / Right / l move focus right; Shift+Tab / Left / h move focus left. y/Y and n/N focus the matching button and commit in a single keystroke. Enter commits the focused button. Esc emits CancelMsg.
func (Confirm) View ¶
View renders the prompt, the two buttons, and a right-aligned key hint. The prompt is word-wrapped to the configured width; buttons are foreground/background-styled per focus state and the dangerous flag.
func (Confirm) WithDangerous ¶
WithDangerous toggles destructive-action styling. When true, the Yes button uses theme.Error for its foreground and focus background so the prompt visually warns the user before they commit.
func (Confirm) WithDefault ¶
WithDefault sets which button has initial focus. Passing true focuses Yes; passing false focuses No. The default is No.
func (Confirm) WithNoLabel ¶
WithNoLabel overrides the "No" button label.
func (Confirm) WithPrompt ¶
WithPrompt sets the question text shown above the buttons. Required for a sensible view; an empty prompt renders only the button row and hint.
func (Confirm) WithWidth ¶
WithWidth caps the prompt reflow width in cells. Values below 20 clamp to 20 so the prompt always has room to breathe.
func (Confirm) WithYesLabel ¶
WithYesLabel overrides the "Yes" button label.
type ConfirmMsg ¶
type ConfirmMsg struct {
Value bool
}
ConfirmMsg is emitted when the user commits with Enter or a y/n keystroke. Value is true when Yes was selected, false when No.
