confirm

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultHorizontalKeyMap = KeyMap{
	Toggle: key.NewBinding(
		key.WithKeys(tea.KeyLeft.String(), tea.KeyRight.String()),
		key.WithHelp("←/→", "toggle"),
	),
	Help: key.NewBinding(
		key.WithKeys("?"),
		key.WithHelp("?", "help"),
	),
	Enter: key.NewBinding(key.WithKeys(tea.KeyEnter.String())),
}
View Source
var DefaultVerticalKeyMap = KeyMap{
	Toggle: key.NewBinding(
		key.WithKeys(tea.KeyUp.String(), tea.KeyDown.String()),
		key.WithHelp("↑/↓", "toggle"),
	),
	Help: key.NewBinding(
		key.WithKeys("?"),
		key.WithHelp("?", "help"),
	),
	Enter: key.NewBinding(key.WithKeys(tea.KeyEnter.String())),
}

Functions

This section is empty.

Types

type Decision

type Decision int

Decision is an enumeration of decisions available in the confirmation bubble

const (
	// Undecided indicates the state in which a user has not made a selection, and there is no default available
	Undecided Decision = iota

	// Accepted indicates the user has provided a positive response (accepted confirmation)
	Accepted

	// Denied indicates the user has provided a negative response (denied confirmation)
	Denied
)

func (Decision) String

func (d Decision) String() string

String satisfies the fmt.Stringer interface

func (Decision) TrueFalseString

func (d Decision) TrueFalseString() string

TrueFalseString represents Decision in undecided/true/false format

func (Decision) YesNoString

func (d Decision) YesNoString() string

YesNoString represents Decision in undecided/yes/no format

type KeyMap

type KeyMap struct {
	Toggle key.Binding
	Help   key.Binding
	Enter  key.Binding
}

KeyMap defines the key bindings for selectable renderings

func (KeyMap) FullHelp

func (k KeyMap) FullHelp() [][]key.Binding

FullHelp returns keybindings for the expanded help view. It's part of the key.Map interface.

func (KeyMap) ShortHelp

func (k KeyMap) ShortHelp() []key.Binding

ShortHelp returns keybindings to be shown in the mini help view. It's part of the key.Map interface.

type Model

type Model struct {
	// PromptPrefix is a character or other indicator existing before the user prompt, separately styled
	PromptPrefix string

	// Prompt is the text to display to the user, prompting them for input
	Prompt string

	// Placeholder is text used only when rendering as InputBox, providing help-like text to the user
	Placeholder string

	// AcceptedDecisionText is the text to display to a user which they will select for Accepted confirmations
	AcceptedDecisionText string

	// DeniedDecisionText is the text to display to a user which they will select for Denied confirmations
	DeniedDecisionText string

	// ChooserIndicator is a rune displayed to the user for HorizontalSelection or VerticalSelection rendering
	ChooserIndicator rune

	// DefaultValue allows the caller to define the initially selected value
	DefaultValue Decision

	// Rendering provides options for modified rendering
	Rendering Rendering

	// Styles is the group of available styles
	Styles Styles

	// ShowHelp determines whether to show help where possible (e.g. HorizontalSelection or VerticalSelection rendering)
	ShowHelp bool
	// contains filtered or unexported fields
}

Model represents the bubble tea model for the confirm bubble

func New

func New() Model

New creates a new model with default settings.

func (*Model) Init

func (m *Model) Init() tea.Cmd

Init satisfies the tea.Model interface

func (*Model) IsAccepted

func (m *Model) IsAccepted() bool

IsAccepted is a helper to indicate the positive confirmation state was selected

func (*Model) IsDenied

func (m *Model) IsDenied() bool

IsDenied is a helper to indicate the negative confirmation state was selected

func (*Model) IsUndecided

func (m *Model) IsUndecided() bool

IsUndecided is a helper to indicate in cases where no default was provided, the user made no choice

func (*Model) Selected

func (m *Model) Selected() Decision

Selected retrieves the default or user-selected Decision value

func (*Model) SetDecision

func (m *Model) SetDecision(decision Decision)

SetDecision allows for externally setting the decision to a supported value

func (*Model) Update

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

Update satisfies the tea.Model interface

func (*Model) Value

func (m *Model) Value() string

Value returns the Decision in human-readable form, supporting the text defined by the caller

func (*Model) View

func (m *Model) View() string

View satisfies the tea.Model interface

type Rendering

type Rendering int

Rendering is an enumeration of available renderings, allowing modification of the bubble's view output

const (
	// InputBox defines rendering as standard format: Prompt? Y/n
	// The user would then enter the desired character and hit enter.
	InputBox Rendering = iota

	// HorizontalSelection defines rendering as a left->right looping toggle: Prompt? ➤Y  N
	HorizontalSelection

	// VerticalSelection defines rendering as a up->down looping toggle:
	// Prompt?
	// ➤Y
	//  N
	VerticalSelection
)

type Styles

type Styles struct {
	PromptPrefix     lipgloss.Style
	Prompt           lipgloss.Style
	Text             lipgloss.Style
	Placeholder      lipgloss.Style
	ChooserIndicator lipgloss.Style
}

Styles holds relevant styles used for rendering For an introduction to styling with Lip Gloss see: https://github.com/charmbracelet/lipgloss

Jump to

Keyboard shortcuts

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