Documentation
¶
Overview ¶
Package toggle provides a yes/no (boolean) selector wrapped in a pane — two labelled buttons rendered side-by-side with the active side highlighted, inside a bordered titled box.
Like every other tuilib component (input, filter, list, …), toggle owns its own pane: View() returns the bordered render. Don't wrap a toggle in another pane — set Options.Title to put the label on the border instead.
While focused, left/right/h/l/space toggle, and y/n set explicitly:
tg := toggle.New(theme.Dark().Toggle())
tg.SetTitle("Send notifications?")
// in your screen's Update: tg, _ = tg.Update(msg)
// later: send := tg.Value()
Index ¶
- type Model
- func (m *Model) Blur()
- func (m *Model) Focus() tea.Cmd
- func (m Model) Focused() bool
- func (m Model) Help() []key.Binding
- func (m Model) Init() tea.Cmd
- func (m *Model) SetActiveColor(c lipgloss.TerminalColor)
- func (m *Model) SetInactiveColor(c lipgloss.TerminalColor)
- func (m *Model) SetSelectedStyle(s lipgloss.Style)
- func (m *Model) SetTitle(s string)
- func (m *Model) SetUnselectedStyle(s lipgloss.Style)
- func (m *Model) SetValue(v bool)
- func (m *Model) SetWidth(w int)
- func (m Model) Update(msg tea.Msg) (Model, tea.Cmd)
- func (m Model) Value() bool
- func (m Model) View() string
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
Model is the toggle's exported state. Focus state lives on both the internal flag and the pane (so the border color reflects focus) — toggle them together via Focus/Blur.
func (Model) Help ¶
Help returns the keys this toggle responds to. Compose into a screen's Help() to drive a per-component help line.
func (*Model) SetActiveColor ¶
func (m *Model) SetActiveColor(c lipgloss.TerminalColor)
SetActiveColor updates the border color used when focused.
func (*Model) SetInactiveColor ¶
func (m *Model) SetInactiveColor(c lipgloss.TerminalColor)
SetInactiveColor updates the border color used when unfocused.
func (*Model) SetSelectedStyle ¶
SetSelectedStyle updates the rendered style of the active side. Useful when reacting to a theme swap without rebuilding the model.
func (*Model) SetUnselectedStyle ¶
SetUnselectedStyle updates the rendered style of the inactive side.
type Options ¶
type Options struct {
// Width sets the pane's outer width. Height is fixed at 3.
Width int
// Title sits on the top border of the pane. Defaults to "toggle" — set
// it to the field's question (e.g. "Send notifications?").
Title string
// Initial is the starting value. Defaults to false.
Initial bool
// YesLabel and NoLabel are the rendered button labels. Default to "yes"
// and "no" — wrap your own text (e.g. "on"/"off", "save"/"discard").
YesLabel string
NoLabel string
// SelectedStyle styles the active side, brackets included.
SelectedStyle lipgloss.Style
// UnselectedStyle styles the inactive side.
UnselectedStyle lipgloss.Style
// Pane pass-throughs. Unset fields fall back to NormalBorder both states
// and SlotBracketsNone.
ActiveColor lipgloss.TerminalColor
InactiveColor lipgloss.TerminalColor
ActiveBorder lipgloss.Border
InactiveBorder lipgloss.Border
SlotBrackets pane.SlotBracketStyle
}
Options configures a new toggle. Zero-value fields fall back to defaults.