checkbox

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package checkbox implements an interactive checkbox widget.

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultTextColor        = cell.ColorWhite
	DefaultFocusedTextColor = cell.ColorCyan
	DefaultCheckedTextColor = cell.ColorGreen
)

Default colors used by the checkbox widget.

View Source
var IndicatorSets = struct {
	Classic IndicatorSet
	Heavy   IndicatorSet
	Rounded IndicatorSet
}{
	Classic: IndicatorSet{Unchecked: "[ ]", Checked: "[x]"},
	Heavy:   IndicatorSet{Unchecked: "☐", Checked: "☑"},
	Rounded: IndicatorSet{Unchecked: "◯", Checked: "◉"},
}

IndicatorSets groups reusable checkbox indicators.

Functions

This section is empty.

Types

type ChangeFn

type ChangeFn func(checked bool) error

ChangeFn is called when the user toggles the checkbox state.

The callback must be thread-safe because it is triggered from the keyboard and mouse event handling paths, which run in separate goroutines.

type Checkbox

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

Checkbox lets the user toggle a single boolean value.

Implements widgetapi.Widget. This object is thread-safe.

func New

func New(label string, opts ...Option) (*Checkbox, error)

New returns a new Checkbox with the provided label.

func (*Checkbox) Checked

func (c *Checkbox) Checked() bool

Checked reports whether the checkbox is currently checked.

func (*Checkbox) Draw

func (c *Checkbox) Draw(cvs *canvas.Canvas, meta *widgetapi.Meta) error

Draw draws the Checkbox onto the canvas. Implements widgetapi.Widget.Draw.

func (*Checkbox) Keyboard

func (c *Checkbox) Keyboard(k *terminalapi.Keyboard, meta *widgetapi.EventMeta) error

Keyboard processes keyboard events for the checkbox. Implements widgetapi.Widget.Keyboard.

func (*Checkbox) Mouse

func (c *Checkbox) Mouse(m *terminalapi.Mouse, meta *widgetapi.EventMeta) error

Mouse processes mouse events for the checkbox. Implements widgetapi.Widget.Mouse.

func (*Checkbox) Options

func (c *Checkbox) Options() widgetapi.Options

Options implements widgetapi.Widget.Options.

func (*Checkbox) SetChecked

func (c *Checkbox) SetChecked(checked bool)

SetChecked replaces the current checked state.

func (*Checkbox) Text

func (c *Checkbox) Text() string

Text returns the checkbox's current rendered one-line text.

func (*Checkbox) TextFor

func (c *Checkbox) TextFor(checked bool) string

TextFor returns the checkbox's rendered text for the provided checked state.

func (*Checkbox) Toggle

func (c *Checkbox) Toggle() bool

Toggle flips the current checked state and returns the new value.

type IndicatorSet

type IndicatorSet struct {
	Unchecked string
	Checked   string
}

IndicatorSet defines the UTF-8 strings used to represent unchecked and checked states.

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option is used to provide options.

func CellOpts

func CellOpts(cellOpts ...cell.Option) Option

CellOpts sets the default cell styling used while the checkbox is unchecked.

func Checked

func Checked(checked bool) Option

Checked configures the initial checked state.

func CheckedCellOpts

func CheckedCellOpts(cellOpts ...cell.Option) Option

CheckedCellOpts sets the styling used while the checkbox is checked.

func FocusedCellOpts

func FocusedCellOpts(cellOpts ...cell.Option) Option

FocusedCellOpts sets the styling used while the checkbox is focused and unchecked.

func Indicators

func Indicators(unchecked, checked string) Option

Indicators sets the UTF-8 strings used for unchecked and checked states.

func LabelGap

func LabelGap(cells int) Option

LabelGap sets the number of blank cells between the indicator and label.

func OnChange

func OnChange(fn ChangeFn) Option

OnChange sets the checkbox's toggle hook.

This is the widget's canonical callback surface. Callers that need delayed or asynchronous behavior should build that from this hook so the widget keeps a single stable event path.

func UseIndicatorSet

func UseIndicatorSet(set IndicatorSet) Option

UseIndicatorSet sets both checkbox indicator strings from a reusable group.

Directories

Path Synopsis
Binary checkboxdemo shows the functionality of a checkbox widget.
Binary checkboxdemo shows the functionality of a checkbox widget.

Jump to

Keyboard shortcuts

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