confirmation

package
v0.19.0 Latest Latest
Warning

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

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

README

Confirmation

Two-button yes/no prompt with focus-managed buttons, y/n shortcuts, dangerous-action styling, and prompt reflow.

confirmation preview

Install

glyph add confirmation

This copies confirmation.go (and its test file) into your repo at the path your glyph.json aliases declare. After install, the file is yours: edit it, refactor it, rename it. There is no confirmation library to keep in sync.

Hello, world

package main

import (
	"fmt"

	"github.com/truffle-dev/glyph/components/confirmation"
	"github.com/truffle-dev/glyph/components/theme"
)

func main() {
	c := confirmation.New(theme.Default).
		WithPrompt("Delete this conversation?").
		WithYesLabel("Delete").
		WithDangerous(true).
		WithWidth(48)
	fmt.Println(c.View())
}

API surface

Package: confirmation

Types

  • ConfirmMsg
  • CancelMsg
  • Confirm

Functions and methods

  • New
  • WithPrompt
  • WithYesLabel
  • WithNoLabel
  • WithDefault
  • WithDangerous
  • WithWidth
  • FocusedYes
  • Init
  • Update
  • View

Dependencies

  • glyph component theme (installed automatically)
  • github.com/charmbracelet/bubbletea@v1.3.10
  • github.com/charmbracelet/lipgloss@v1.1.0
  • github.com/muesli/reflow@v0.3.0

Notes

Tab/Left/Right walk between Yes and No; y/Y and n/N commit with one keystroke regardless of focus; Enter commits the focused button. Emits confirmation.ConfirmMsg{Value bool} on commit, confirmation.CancelMsg on Esc. Set WithDangerous(true) to style Yes with theme.Error for destructive actions.

See also

License

MIT, same as the rest of glyph.

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CancelMsg

type CancelMsg struct{}

CancelMsg is emitted when the user presses Esc.

type Confirm

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

Confirm is a Bubble Tea model for a yes/no prompt.

func New

func New(t theme.Theme) Confirm

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

func (c Confirm) FocusedYes() bool

FocusedYes reports whether Yes currently has focus.

func (Confirm) Init

func (c Confirm) Init() tea.Cmd

Init implements tea.Model. The component has no autonomous behavior.

func (Confirm) Update

func (c Confirm) Update(msg tea.Msg) (Confirm, tea.Cmd)

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

func (c Confirm) View() string

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

func (c Confirm) WithDangerous(d bool) Confirm

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

func (c Confirm) WithDefault(yes bool) Confirm

WithDefault sets which button has initial focus. Passing true focuses Yes; passing false focuses No. The default is No.

func (Confirm) WithNoLabel

func (c Confirm) WithNoLabel(s string) Confirm

WithNoLabel overrides the "No" button label.

func (Confirm) WithPrompt

func (c Confirm) WithPrompt(s string) Confirm

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

func (c Confirm) WithWidth(w int) Confirm

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

func (c Confirm) WithYesLabel(s string) Confirm

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.

Jump to

Keyboard shortcuts

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