confirm

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package confirm is a yes/no prompt widget — InkUI's "Confirm".

Example

Pressing y confirms yes whatever is highlighted; the answer arrives as a ConfirmedMsg from the returned Cmd.

package main

import (
	"fmt"

	"github.com/ows4444/tui"
	"github.com/ows4444/tui/confirm"
)

func main() {
	m := confirm.New("Delete the file?")
	_, cmd := m.Update(tui.Key{Type: tui.KeyRunes, Text: "y"})
	fmt.Printf("%+v\n", cmd())
}
Output:
{Yes:true}

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConfirmedMsg

type ConfirmedMsg struct {
	Yes bool
}

ConfirmedMsg is delivered (via the Cmd Update returns) once the prompt is answered, by Enter or by a direct 'y'/'n' keypress.

type KeyMap

type KeyMap struct {
	Toggle keymap.Binding // move the highlight to the other option
	Accept keymap.Binding // confirm the highlighted option
	Yes    keymap.Binding // confirm Yes directly
	No     keymap.Binding // confirm No directly
}

KeyMap names the keys of each action of a Model.

func DefaultKeyMap

func DefaultKeyMap() KeyMap

DefaultKeyMap returns the keys a Model used before KeyMap existed.

type Model

type Model struct {
	Prompt   string
	YesLabel string
	NoLabel  string
	Theme    theme.Theme

	// KeyMap holds the keys for each action. New fills it with
	// DefaultKeyMap; a Model built as a struct literal with a zero KeyMap
	// behaves as if it held DefaultKeyMap.
	KeyMap KeyMap

	// Mouse, when true, makes Update handle tui.MouseEvent: a left click on the
	// Yes or No label answers the prompt as that key would. Off (the default)
	// ignores the mouse.
	Mouse bool
	// Bounds is the screen rectangle where the app draws the prompt (its first
	// row is the prompt's first line); clicks outside it are ignored.
	Bounds hittest.Rect
	// contains filtered or unexported fields
}

Model is a two-option Yes/No prompt: Left/Right/Tab move which option is highlighted, Enter confirms the highlighted one, and 'y'/'n' confirm directly regardless of what's highlighted.

func New

func New(prompt string) Model

New returns a Model with "Yes"/"No" labels and Yes highlighted, the common default for a prompt where doing nothing is the safe choice.

func (Model) Bindings

func (m Model) Bindings() []keymap.Binding

Bindings returns the actions the prompt currently honours, with descriptions, for help text.

func (Model) Highlighted

func (m Model) Highlighted() bool

Highlighted reports which option the cursor is currently on — not which was chosen; that only happens via ConfirmedMsg.

func (Model) LayoutNode

func (m Model) LayoutNode() layout.Node

LayoutNode adapts the prompt to a layout.Node. When the prompt and both options fit on one row it is View exactly; when narrower, the prompt word-wraps to the allotted width and the options sit on their own row beneath it. The Model is not changed.

func (Model) Linearize

func (m Model) Linearize() string

Linearize renders the prompt as plain text for accessible output (see tui.Linearizer): the prompt line, then one line per option with its position, ", selected" on the highlighted one, e.g. "Yes, option 1 of 2, selected". No brackets or reverse-video.

func (Model) SetTheme

func (m Model) SetTheme(t theme.Theme) Model

SetTheme returns m with t applied. It makes Model a tui.ThemeSetter, so a root model can forward the Program's theme (see tui.WithTheme).

func (Model) Tokens

func (m Model) Tokens() theme.Tokens

Tokens returns the colour tokens the widget renders with: its theme's roles, overridden by any theme.WithTokens(theme.ComponentConfirm, ...) and then by WithTokens.

func (Model) Update

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

Update moves the highlight on Left/Right/Tab, and confirms on Enter (the highlighted option) or a direct 'y'/'n' keypress, returning a Cmd that delivers ConfirmedMsg. With Mouse on, a left click on the Yes or No label confirms it the same way.

func (Model) View

func (m Model) View() string

View renders the prompt and its two options, with the highlighted one shown in reverse video.

func (Model) WithTokens

func (m Model) WithTokens(tok theme.Tokens) Model

WithTokens returns m with tok as its per-instance colour override. Nil fields inherit from the theme, so only the roles tok names change; the theme and every other widget are untouched. A second call replaces the first.

Jump to

Keyboard shortcuts

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