Documentation
¶
Overview ¶
Package teaware provides form widgets and layout containers for building terminal user interfaces with the Bubble Tea framework.
Widgets ¶
teaware includes the following interactive widgets:
- TextInput — single-line text field
- Textarea — multi-line text area
- Dropdown — single-select dropdown list
- Checkbox — boolean toggle rendered as "[ ] Label" / "[x] Label"
- RadioGroup — single-select group of radio buttons
- Button — clickable button with primary and secondary styles
- Label — non-interactive text label
- Separator — horizontal visual divider
- Spacer — invisible flexible space for layouts
Layout Containers ¶
Widgets are arranged using layout containers:
- Flex — row or column layout with proportional sizing
- Grid — fixed column-definition grid layout
- [Overlay] — popup layer rendered on top of other content
- Padding — adds fixed padding around a single widget
Forms ¶
Form is the top-level container that wires together focus management, keyboard navigation (Tab / Shift-Tab), and overlay rendering. Embed any combination of widgets and layout containers:
form := teaware.NewForm(
teaware.NewGrid(
teaware.Col(20, teaware.NewLabel("Name:")),
teaware.Col(40, teaware.NewTextInput()),
),
teaware.NewButton("Submit").OnClick(func() tea.Cmd {
// handle submit
return nil
}),
)
Theming ¶
All widgets read styles from the active Theme. Call SetTheme to apply a custom theme globally; use DefaultTheme as a starting point.
Index ¶
- Variables
- func RegisterOverlay(absX, absY int, content string)
- func SetOverlayRegistry(r OverlayRegistry)
- func SetTheme(t Theme)
- type Button
- func (b *Button) Blur()
- func (b *Button) Constraints() Constraints
- func (b *Button) Disabled(v bool) *Button
- func (b *Button) Focus() tea.Cmd
- func (b *Button) Focused() bool
- func (b *Button) OnClick(fn func() tea.Cmd) *Button
- func (b *Button) SetSize(_, _ int)
- func (b *Button) Style(s ButtonStyle) *Button
- func (b *Button) Update(msg tea.Msg) tea.Cmd
- func (b *Button) View() string
- type ButtonStyle
- type ButtonTheme
- type Checkbox
- func (c *Checkbox) Blur()
- func (c *Checkbox) Checked(v bool) *Checkbox
- func (c *Checkbox) Constraints() Constraints
- func (c *Checkbox) Disabled(v bool) *Checkbox
- func (c *Checkbox) Focus() tea.Cmd
- func (c *Checkbox) Focused() bool
- func (c *Checkbox) IsChecked() bool
- func (c *Checkbox) OnChange(fn func(bool) tea.Cmd) *Checkbox
- func (c *Checkbox) SetSize(_, _ int)
- func (c *Checkbox) Update(msg tea.Msg) tea.Cmd
- func (c *Checkbox) View() string
- type CheckboxTheme
- type ColumnDef
- type Constraints
- type ConstraintsProvider
- type Container
- type Direction
- type Dropdown
- func (d *Dropdown) Blur()
- func (d *Dropdown) Constraints() Constraints
- func (d *Dropdown) Focus() tea.Cmd
- func (d *Dropdown) Focused() bool
- func (d *Dropdown) GetValue() string
- func (d *Dropdown) OnChange(fn func(string) tea.Cmd) *Dropdown
- func (d *Dropdown) SetPosition(x, y int)
- func (d *Dropdown) SetSize(width, _ int)
- func (d *Dropdown) Update(msg tea.Msg) tea.Cmd
- func (d *Dropdown) Value(v string) *Dropdown
- func (d *Dropdown) View() string
- type DropdownTheme
- type Flex
- func (f *Flex) Add(child Painter, opts ...FlexItemOption) *Flex
- func (f *Flex) Blur()
- func (f *Flex) Constraints() Constraints
- func (f *Flex) Focus() tea.Cmd
- func (f *Flex) FocusNext() tea.Cmd
- func (f *Flex) FocusPrevious() tea.Cmd
- func (f *Flex) Focused() bool
- func (f *Flex) Gap(n int) *Flex
- func (f *Flex) Padding(values ...int) *Flex
- func (f *Flex) ReceiveFocusFromNext() tea.Cmd
- func (f *Flex) ReceiveFocusFromPrevious() tea.Cmd
- func (f *Flex) SetPosition(x, y int)
- func (f *Flex) SetSize(width, height int)
- func (f *Flex) Update(msg tea.Msg) tea.Cmd
- func (f *Flex) View() string
- type FlexItemOption
- type FocusNextMsg
- type FocusOwner
- type FocusPreviousMsg
- type Form
- func (f *Form) Blur()
- func (f *Form) Constraints() Constraints
- func (f *Form) Focus() tea.Cmd
- func (f *Form) Focused() bool
- func (f *Form) HasOpenPopups() bool
- func (f *Form) RegisterOverlay(absX, absY int, content string)
- func (f *Form) SetSize(w, h int)
- func (f *Form) Update(msg tea.Msg) tea.Cmd
- func (f *Form) View() string
- func (f *Form) WithAutoTab(enabled bool) *Form
- type Grid
- func (g *Grid) AddRow(cells ...Painter) *Grid
- func (g *Grid) Blur()
- func (g *Grid) ColumnGap(n int) *Grid
- func (g *Grid) Columns(cols ...ColumnDef) *Grid
- func (g *Grid) Constraints() Constraints
- func (g *Grid) Focus() tea.Cmd
- func (g *Grid) FocusNext() tea.Cmd
- func (g *Grid) FocusPrevious() tea.Cmd
- func (g *Grid) Focused() bool
- func (g *Grid) Padding(values ...int) *Grid
- func (g *Grid) ReceiveFocusFromNext() tea.Cmd
- func (g *Grid) ReceiveFocusFromPrevious() tea.Cmd
- func (g *Grid) RowGap(n int) *Grid
- func (g *Grid) SetPosition(x, y int)
- func (g *Grid) SetSize(width, height int)
- func (g *Grid) Update(msg tea.Msg) tea.Cmd
- func (g *Grid) View() string
- type InputTheme
- type Label
- type LabelTheme
- type OverlayRegistry
- type Padding
- type Painter
- type Positioner
- type RadioGroup
- func (r *RadioGroup) Blur()
- func (r *RadioGroup) Constraints() Constraints
- func (r *RadioGroup) Disabled(v bool) *RadioGroup
- func (r *RadioGroup) Focus() tea.Cmd
- func (r *RadioGroup) Focused() bool
- func (r *RadioGroup) GetValue() string
- func (r *RadioGroup) OnChange(fn func(string) tea.Cmd) *RadioGroup
- func (r *RadioGroup) SetSize(_, _ int)
- func (r *RadioGroup) Update(msg tea.Msg) tea.Cmd
- func (r *RadioGroup) Value(v string) *RadioGroup
- func (r *RadioGroup) View() string
- type RadioTheme
- type Separator
- type SeparatorTheme
- type SizeMode
- type Sizer
- type Spacer
- type TextInput
- func (t *TextInput) Blur()
- func (t *TextInput) CharLimit(n int) *TextInput
- func (t *TextInput) Constraints() Constraints
- func (t *TextInput) Focus() tea.Cmd
- func (t *TextInput) Focused() bool
- func (t *TextInput) GetValue() string
- func (t *TextInput) OnChange(fn func(string) tea.Cmd) *TextInput
- func (t *TextInput) OnSubmit(fn func(string) tea.Cmd) *TextInput
- func (t *TextInput) Placeholder(s string) *TextInput
- func (t *TextInput) SetSize(width, _ int)
- func (t *TextInput) Update(msg tea.Msg) tea.Cmd
- func (t *TextInput) Validate(fn func(string) error) *TextInput
- func (t *TextInput) Value(s string) *TextInput
- func (t *TextInput) View() string
- type Textarea
- func (t *Textarea) Blur()
- func (t *Textarea) Constraints() Constraints
- func (t *Textarea) Focus() tea.Cmd
- func (t *Textarea) Focused() bool
- func (t *Textarea) GetValue() string
- func (t *Textarea) Lines(n int) *Textarea
- func (t *Textarea) OnChange(fn func(string) tea.Cmd) *Textarea
- func (t *Textarea) Placeholder(s string) *Textarea
- func (t *Textarea) SetSize(width, height int)
- func (t *Textarea) Update(msg tea.Msg) tea.Cmd
- func (t *Textarea) View() string
- type Theme
- type Updater
- type Widget
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var Auto = ColumnDef{/* contains filtered or unexported fields */}
Auto is a ColumnDef that sizes the column to fit its content.
var FocusNextCmd tea.Cmd = func() tea.Msg { return FocusNextMsg{} }
FocusNextCmd sends FocusNextMsg to signal focus exhaustion in the forward direction.
var FocusPreviousCmd tea.Cmd = func() tea.Msg { return FocusPreviousMsg{} }
FocusPreviousCmd sends FocusPreviousMsg to signal focus exhaustion in the backward direction.
var Stretch = ColumnDef{/* contains filtered or unexported fields */}
Stretch is a ColumnDef that takes remaining available space.
Functions ¶
func RegisterOverlay ¶
RegisterOverlay registers floating overlay content at the given absolute coordinates. It is a no-op when no registry has been set.
func SetOverlayRegistry ¶
func SetOverlayRegistry(r OverlayRegistry)
SetOverlayRegistry sets the global overlay registry. Pass nil to clear it. Must be called from the Bubble Tea goroutine (e.g. inside View).
func SetTheme ¶
func SetTheme(t Theme)
SetTheme replaces the active theme. All widgets pick up the new theme on next View(). Must be called from the Bubble Tea goroutine (e.g. inside Update).
Example ¶
ExampleSetTheme shows replacing the global theme with a custom one. All widgets pick up the new theme on the next teaware.Form.View call.
original := teaware.CurrentTheme()
defer teaware.SetTheme(original)
custom := teaware.DefaultTheme()
custom.Checkbox.Checked = "[✓]"
custom.Checkbox.Unchecked = "[ ]"
custom.Button.Focused = lipgloss.NewStyle().
Padding(0, 3).
Foreground(lipgloss.Color("15")).
Background(lipgloss.Color("99"))
teaware.SetTheme(custom)
theme := teaware.CurrentTheme()
fmt.Println("checked symbol:", theme.Checkbox.Checked)
Output: checked symbol: [✓]
Types ¶
type Button ¶
type Button struct {
// contains filtered or unexported fields
}
Button is an interactive widget that renders a styled label. Enter and Space triggers the OnClick handler.
func NewButton ¶
NewButton creates a new Button with the given label.
Example ¶
ExampleNewButton shows a teaware.Button with primary and secondary variants.
package main
import (
"fmt"
tea "charm.land/bubbletea/v2"
"github.com/anadale/teaservice/teaware"
)
func main() {
var submitted bool
submit := teaware.NewButton("Submit").
OnClick(func() tea.Cmd {
submitted = true
return nil
})
cancel := teaware.NewButton("Cancel").
Style(teaware.ButtonStyleSecondary).
OnClick(func() tea.Cmd { return tea.Quit })
_ = submit
_ = cancel
fmt.Println("buttons created, submitted:", submitted)
}
Output: buttons created, submitted: false
func (*Button) Constraints ¶
func (b *Button) Constraints() Constraints
Constraints implements ConstraintsProvider.
func (*Button) Style ¶
func (b *Button) Style(s ButtonStyle) *Button
Style sets the visual variant of the button.
type ButtonStyle ¶
type ButtonStyle int
ButtonStyle defines the visual variant of a Button.
const ( ButtonStylePrimary ButtonStyle = iota // ButtonStylePrimary is the default, accent button style. ButtonStyleSecondary // ButtonStyleSecondary is the less prominent, outlined button style. )
Available ButtonStyle values.
type ButtonTheme ¶
ButtonTheme defines styles for Button widgets.
type Checkbox ¶
type Checkbox struct {
// contains filtered or unexported fields
}
Checkbox is an interactive widget that renders as "[ ] Label" or "[x] Label". Space and Enter toggle the checked state.
func NewCheckbox ¶
NewCheckbox creates a new Checkbox with the given label.
Example ¶
ExampleNewCheckbox shows a teaware.Checkbox with an OnChange callback.
package main
import (
"fmt"
tea "charm.land/bubbletea/v2"
"github.com/anadale/teaservice/teaware"
)
func main() {
cb := teaware.NewCheckbox("Subscribe to newsletter").
Checked(true).
OnChange(func(v bool) tea.Cmd {
fmt.Println("changed to:", v)
return nil
})
fmt.Println("checked:", cb.IsChecked())
}
Output: checked: true
func (*Checkbox) Constraints ¶
func (c *Checkbox) Constraints() Constraints
Constraints implements ConstraintsProvider.
type CheckboxTheme ¶
type CheckboxTheme struct {
Unchecked string
Checked string
Normal lipgloss.Style
Focused lipgloss.Style
Disabled lipgloss.Style
}
CheckboxTheme defines styles and symbols for Checkbox widgets.
type ColumnDef ¶
type ColumnDef struct {
// contains filtered or unexported fields
}
ColumnDef defines a single column's sizing rule.
func FixedColumn ¶
FixedColumn creates a ColumnDef with a fixed character width.
type Constraints ¶
Constraints describes a widget's size preferences. Zero value means "no constraint / expand".
type ConstraintsProvider ¶
type ConstraintsProvider interface {
Constraints() Constraints
}
ConstraintsProvider lets a widget advertise its size preferences to the parent container.
type Container ¶
type Container interface {
Widget
FocusNext() tea.Cmd
FocusPrevious() tea.Cmd
ReceiveFocusFromPrevious() tea.Cmd // entering via Tab from before this container → focus first child
ReceiveFocusFromNext() tea.Cmd // entering via Shift+Tab from after this container → focus last child
}
Container extends Widget with focus navigation methods. Exported so third-party containers can participate in the focus protocol.
type Dropdown ¶
type Dropdown struct {
// contains filtered or unexported fields
}
Dropdown is an interactive widget that shows a selected value and expands to a popup list when activated.
Closed state: renders "[ Selected ▼ ]"; Enter/Space opens the popup. Open state: registers a floating overlay via the global OverlayRegistry and returns only the closed header view; Up/Down navigate; Enter selects the highlighted option; Esc closes without changing selection.
func NewDropdown ¶
NewDropdown creates a Dropdown with the given options. The first option is selected by default when options are non-empty.
Example ¶
ExampleNewDropdown shows a teaware.Dropdown with options and an OnChange callback.
package main
import (
"fmt"
tea "charm.land/bubbletea/v2"
"github.com/anadale/teaservice/teaware"
)
func main() {
var selected string
drop := teaware.NewDropdown([]string{"Red", "Green", "Blue"}).
Value("Green").
OnChange(func(v string) tea.Cmd {
selected = v
return nil
})
fmt.Println("value:", drop.GetValue())
_ = selected
}
Output: value: Green
func (*Dropdown) Constraints ¶
func (d *Dropdown) Constraints() Constraints
Constraints implements ConstraintsProvider.
func (*Dropdown) SetPosition ¶
SetPosition implements Positioner.
type DropdownTheme ¶
type DropdownTheme struct {
Normal lipgloss.Style
Focused lipgloss.Style
Disabled lipgloss.Style
Item lipgloss.Style
Selected lipgloss.Style
}
DropdownTheme defines styles for Dropdown widgets.
type Flex ¶
type Flex struct {
// contains filtered or unexported fields
}
Flex arranges children along a Direction with a two-pass layout.
func NewFlex ¶
NewFlex creates a new Flex container with the given direction.
Example ¶
ExampleNewFlex shows a horizontal teaware.Flex container with a gap between children.
package main
import (
"fmt"
"github.com/anadale/teaservice/teaware"
)
func main() {
okBtn := teaware.NewButton("OK")
cancelBtn := teaware.NewButton("Cancel").Style(teaware.ButtonStyleSecondary)
row := teaware.NewFlex(teaware.Horizontal).
Gap(2).
Add(okBtn).
Add(cancelBtn)
row.SetSize(40, 1)
_ = row.Focus()
fmt.Println("ok focused:", okBtn.Focused())
}
Output: ok focused: true
Example (Vertical) ¶
ExampleNewFlex_vertical shows a vertical teaware.Flex that stacks widgets.
package main
import (
"fmt"
"github.com/anadale/teaservice/teaware"
)
func main() {
col := teaware.NewFlex(teaware.Vertical).
Gap(1).
Add(teaware.NewTextInput().Placeholder("Username")).
Add(teaware.NewTextInput().Placeholder("Password"))
col.SetSize(30, 4)
fmt.Println("vertical flex configured")
}
Output: vertical flex configured
func (*Flex) Add ¶
func (f *Flex) Add(child Painter, opts ...FlexItemOption) *Flex
Add appends a child with optional item options.
func (*Flex) Constraints ¶
func (f *Flex) Constraints() Constraints
Constraints implements ConstraintsProvider.
func (*Flex) FocusNext ¶
FocusNext advances focus to the next focusable child, returning FocusNextCmd when exhausted. If the currently focused child is a Container with an active child focus, focus is advanced within that container before moving to the next sibling.
func (*Flex) FocusPrevious ¶
FocusPrevious moves focus to the previous focusable child, returning FocusPreviousCmd when exhausted. If the currently focused child is a Container with an active child focus, focus is moved backward within that container before moving to the previous sibling.
func (*Flex) Padding ¶
Padding sets the inset around the container content using CSS shorthand notation:
Padding(all) Padding(vertical, horizontal) Padding(top, right, bottom, left)
func (*Flex) ReceiveFocusFromNext ¶
ReceiveFocusFromNext focuses the last focusable child.
func (*Flex) ReceiveFocusFromPrevious ¶
ReceiveFocusFromPrevious focuses the first focusable child.
func (*Flex) SetPosition ¶
SetPosition implements Positioner and propagates absolute coordinates to children.
type FlexItemOption ¶
type FlexItemOption func(*flexItem)
FlexItemOption is applied to an individual child in Add().
func Fixed ¶
func Fixed(n int) FlexItemOption
Fixed sets a child to a fixed size along the main axis.
func Grow ¶
func Grow() FlexItemOption
Grow makes a child stretch to fill remaining space along the main axis.
type FocusNextMsg ¶
type FocusNextMsg struct{}
FocusNextMsg is returned (via FocusNextCmd) when a container has exhausted forward focus traversal. The parent container intercepts this to move focus to the next sibling. Exported so third-party containers can participate.
type FocusOwner ¶
FocusOwner can receive and lose keyboard focus.
type FocusPreviousMsg ¶
type FocusPreviousMsg struct{}
FocusPreviousMsg is returned (via FocusPreviousCmd) when a container has exhausted backward focus traversal.
type Form ¶
type Form struct {
// contains filtered or unexported fields
}
Form wraps a root Container and implements FocusOwner, Painter, and Sizer. By default it intercepts Tab/Shift+Tab and calls FocusNext/FocusPrevious automatically. Form also acts as an OverlayRegistry: during View() it collects overlays from children and composites them on top of the base view via lipgloss.Compositor.
func NewForm ¶
NewForm creates a Form with autoTab enabled.
Example ¶
ExampleNewForm demonstrates building a complete form with a Grid layout. teaware.Form wires focus navigation (Tab / Shift-Tab) and overlay rendering for widgets like teaware.Dropdown.
package main
import (
"fmt"
"github.com/anadale/teaservice/teaware"
)
func main() {
nameInput := teaware.NewTextInput().Placeholder("Your name")
emailInput := teaware.NewTextInput().Placeholder("Email")
submitBtn := teaware.NewButton("Submit")
form := teaware.NewForm(
teaware.NewGrid().
Columns(teaware.Auto, teaware.Stretch).
ColumnGap(2).
AddRow(teaware.NewLabel("Name:"), nameInput).
AddRow(teaware.NewLabel("Email:"), emailInput).
AddRow(teaware.Span(2, submitBtn)),
)
form.SetSize(60, 10)
_ = form.Focus()
fmt.Println("focused:", nameInput.Focused())
}
Output: focused: true
func (*Form) Constraints ¶
func (f *Form) Constraints() Constraints
Constraints implements ConstraintsProvider by returning the root container's constraints.
func (*Form) HasOpenPopups ¶
HasOpenPopups reports whether any floating overlay was registered during the last View() call. Use this to distinguish between Esc closing a popup vs quitting the application.
func (*Form) RegisterOverlay ¶
RegisterOverlay implements OverlayRegistry. Called by child widgets during View().
func (*Form) SetSize ¶
SetSize implements Sizer. It propagates the dimensions to the root container and resets its position to (0, 0) if the root also implements Positioner.
func (*Form) Update ¶
Update implements Updater. It intercepts FocusNextMsg and FocusPreviousMsg to wrap the focus cycle, and — when autoTab is enabled — handles Tab/Shift+Tab before delegating all other messages to the root container.
func (*Form) View ¶
View implements Painter. It renders the root container and composites any registered overlay layers on top of the base view using lipgloss.Compositor.
func (*Form) WithAutoTab ¶
WithAutoTab enables or disables automatic Tab/Shift+Tab handling.
type Grid ¶
type Grid struct {
// contains filtered or unexported fields
}
Grid arranges children in rows and columns with configurable column sizing.
func NewGrid ¶
func NewGrid() *Grid
NewGrid creates a new empty Grid.
Example ¶
ExampleNewGrid shows a two-column teaware.Grid with Auto and Stretch columns. teaware.Auto sizes to the widest cell in the column; teaware.Stretch fills the remaining space. teaware.Span lets a widget span multiple columns.
package main
import (
"fmt"
"github.com/anadale/teaservice/teaware"
)
func main() {
grid := teaware.NewGrid().
Columns(teaware.Auto, teaware.Stretch).
ColumnGap(1).
AddRow(teaware.NewLabel("Name:"), teaware.NewTextInput()).
AddRow(teaware.NewLabel("Email:"), teaware.NewTextInput()).
AddRow(teaware.Span(2, teaware.NewSeparator(teaware.Horizontal)))
grid.SetSize(60, 6)
fmt.Println("grid configured")
}
Output: grid configured
Example (FixedColumns) ¶
ExampleNewGrid_fixedColumns shows a grid with a fixed-width first column.
package main
import (
"fmt"
"github.com/anadale/teaservice/teaware"
)
func main() {
grid := teaware.NewGrid().
Columns(teaware.FixedColumn(12), teaware.Stretch).
AddRow(teaware.NewLabel("Name:"), teaware.NewTextInput()).
AddRow(teaware.NewLabel("Department:"), teaware.NewTextInput())
grid.SetSize(60, 4)
fmt.Println("fixed columns configured")
}
Output: fixed columns configured
func (*Grid) AddRow ¶
AddRow appends a row of cells. Use Span() to have a cell span multiple columns.
func (*Grid) Columns ¶
Columns configures column definitions. Pass Auto, Stretch, or FixedColumn(n).
func (*Grid) Constraints ¶
func (g *Grid) Constraints() Constraints
Constraints implements ConstraintsProvider.
func (*Grid) FocusNext ¶
FocusNext advances focus to the next focusable cell in row-major order. If the currently focused cell is a Container with an active child focus, focus is advanced within that container before moving to the next sibling. Returns FocusNextCmd when all focusable cells are exhausted.
func (*Grid) FocusPrevious ¶
FocusPrevious moves focus to the previous focusable cell in row-major order. If the currently focused cell is a Container with an active child focus, focus is moved backward within that container before moving to the previous sibling. Returns FocusPreviousCmd when all focusable cells are exhausted.
func (*Grid) Padding ¶
Padding sets the inset around the grid content using CSS shorthand notation:
Padding(all) Padding(vertical, horizontal) Padding(top, right, bottom, left)
func (*Grid) ReceiveFocusFromNext ¶
ReceiveFocusFromNext focuses the last focusable cell.
func (*Grid) ReceiveFocusFromPrevious ¶
ReceiveFocusFromPrevious focuses the first focusable cell.
func (*Grid) SetPosition ¶
SetPosition implements Positioner and propagates absolute coordinates to children.
type InputTheme ¶
InputTheme defines styles for TextInput widgets.
type Label ¶
type Label struct {
// contains filtered or unexported fields
}
Label is a non-interactive text widget that renders a string with optional styling.
func NewLabel ¶
NewLabel creates a new Label with the given text.
Example ¶
ExampleNewLabel shows a non-interactive text label for form layouts.
package main
import (
"fmt"
"github.com/anadale/teaservice/teaware"
)
func main() {
label := teaware.NewLabel("Username:")
fmt.Println("label view:", label.View())
}
Output: label view: Username:
func (*Label) Constraints ¶
func (l *Label) Constraints() Constraints
Constraints implements ConstraintsProvider.
type LabelTheme ¶
LabelTheme defines styles for Label widgets.
type OverlayRegistry ¶
OverlayRegistry allows widgets to register floating overlay content at absolute coordinates.
type Padding ¶
type Padding struct {
Top, Right, Bottom, Left int
}
Padding holds inset values for each side of a container.
func NewPadding ¶
NewPadding creates a Padding using CSS shorthand notation:
NewPadding(all) — all four sides equal NewPadding(vertical, horizontal) — top/bottom and left/right NewPadding(top, right, bottom, left)
type Positioner ¶
type Positioner interface {
SetPosition(x, y int)
}
Positioner allows a parent container to push absolute screen coordinates into a child widget.
type RadioGroup ¶
type RadioGroup struct {
// contains filtered or unexported fields
}
RadioGroup is an interactive widget that renders a vertical list of options. Each option is displayed as "( ) Option" or "(•) Option". Up/Down navigate between options; Space/Enter selects the focused option.
func NewRadioGroup ¶
func NewRadioGroup(options []string) *RadioGroup
NewRadioGroup creates a new RadioGroup with the given options. The first option is selected by default if options is non-empty.
Example ¶
ExampleNewRadioGroup shows a teaware.RadioGroup with a pre-selected value.
package main
import (
"fmt"
tea "charm.land/bubbletea/v2"
"github.com/anadale/teaservice/teaware"
)
func main() {
rg := teaware.NewRadioGroup([]string{"Small", "Medium", "Large"}).
Value("Medium").
OnChange(func(v string) tea.Cmd {
fmt.Println("selected:", v)
return nil
})
fmt.Println("value:", rg.GetValue())
}
Output: value: Medium
func (*RadioGroup) Constraints ¶
func (r *RadioGroup) Constraints() Constraints
Constraints implements ConstraintsProvider.
func (*RadioGroup) Disabled ¶
func (r *RadioGroup) Disabled(v bool) *RadioGroup
Disabled sets whether the radio group is disabled.
func (*RadioGroup) GetValue ¶
func (r *RadioGroup) GetValue() string
GetValue returns the currently selected option value, or empty string if none.
func (*RadioGroup) OnChange ¶
func (r *RadioGroup) OnChange(fn func(string) tea.Cmd) *RadioGroup
OnChange sets a callback invoked when the selected option changes.
func (*RadioGroup) Update ¶
func (r *RadioGroup) Update(msg tea.Msg) tea.Cmd
Update implements Updater.
func (*RadioGroup) Value ¶
func (r *RadioGroup) Value(v string) *RadioGroup
Value sets the selected option by value (builder).
type RadioTheme ¶
type RadioTheme struct {
Unselected string
Selected string
Normal lipgloss.Style
Focused lipgloss.Style
Disabled lipgloss.Style
}
RadioTheme defines styles and symbols for RadioGroup widgets.
type Separator ¶
type Separator struct {
// contains filtered or unexported fields
}
Separator is a non-interactive line widget: horizontal (─) or vertical (│).
func NewSeparator ¶
NewSeparator creates a new Separator in the given direction.
Example ¶
ExampleNewSeparator shows horizontal and vertical separators.
package main
import (
"fmt"
"github.com/anadale/teaservice/teaware"
)
func main() {
_ = teaware.NewSeparator(teaware.Horizontal)
_ = teaware.NewSeparator(teaware.Vertical)
fmt.Println("separators created")
}
Output: separators created
func (*Separator) Constraints ¶
func (s *Separator) Constraints() Constraints
Constraints implements ConstraintsProvider.
type SeparatorTheme ¶
SeparatorTheme defines styles for Separator widgets.
type SizeMode ¶
type SizeMode int
SizeMode controls how a child is sized along the main axis.
const ( SizeModePreferred SizeMode = iota // SizeModePreferred uses the child's preferred size (or min size if preferred is zero). SizeModeFixed // SizeModeFixed allocates a fixed number of cells along the main axis. SizeModeStretch // SizeModeStretch expands the child to fill the remaining space along the main axis. )
Available SizeMode values.
type Sizer ¶
type Sizer interface {
SetSize(width, height int)
}
Sizer lets the parent container push the calculated size into the widget.
type Spacer ¶
type Spacer struct {
// contains filtered or unexported fields
}
Spacer is a non-interactive widget that fills available space. In horizontal layouts it renders as spaces of the given width, enabling right-alignment. In vertical layouts it renders as an empty line.
func (*Spacer) Constraints ¶
func (s *Spacer) Constraints() Constraints
Constraints implements ConstraintsProvider.
type TextInput ¶
type TextInput struct {
// contains filtered or unexported fields
}
TextInput is a single-line text input widget wrapping charm.land/bubbles/v2/textinput.
func NewTextInput ¶
func NewTextInput() *TextInput
NewTextInput creates a new TextInput with default settings.
Example ¶
ExampleNewTextInput shows configuring a teaware.TextInput with placeholder, initial value, character limit, and an OnChange callback.
package main
import (
"fmt"
tea "charm.land/bubbletea/v2"
"github.com/anadale/teaservice/teaware"
)
func main() {
var lastValue string
input := teaware.NewTextInput().
Placeholder("Search…").
Value("initial").
CharLimit(100).
OnChange(func(v string) tea.Cmd {
lastValue = v
return nil
})
fmt.Println("value:", input.GetValue())
_ = lastValue
}
Output: value: initial
func (*TextInput) Constraints ¶
func (t *TextInput) Constraints() Constraints
Constraints implements ConstraintsProvider.
func (*TextInput) OnChange ¶
OnChange sets a callback invoked when the value changes and passes validation.
func (*TextInput) Placeholder ¶
Placeholder sets the placeholder text shown when the input is empty.
func (*TextInput) Validate ¶
Validate sets a validation function called on every value change. When it returns a non-nil error, OnChange is not fired.
type Textarea ¶
type Textarea struct {
// contains filtered or unexported fields
}
Textarea is a multi-line text input widget wrapping charm.land/bubbles/v2/textarea.
func NewTextarea ¶
func NewTextarea() *Textarea
NewTextarea creates a new Textarea with default settings.
Example ¶
ExampleNewTextarea shows a multi-line teaware.Textarea.
package main
import (
"fmt"
"github.com/anadale/teaservice/teaware"
)
func main() {
area := teaware.NewTextarea().
Placeholder("Enter notes…").
Lines(4)
fmt.Println("lines configured:", area.GetValue() == "")
}
Output: lines configured: true
func (*Textarea) Constraints ¶
func (t *Textarea) Constraints() Constraints
Constraints implements ConstraintsProvider.
func (*Textarea) Placeholder ¶
Placeholder sets the placeholder text shown when the textarea is empty.
type Theme ¶
type Theme struct {
Label LabelTheme
Separator SeparatorTheme
Input InputTheme
Button ButtonTheme
ButtonSecondary ButtonTheme
Checkbox CheckboxTheme
Radio RadioTheme
Dropdown DropdownTheme
}
Theme defines styles for all widget types.
func DefaultTheme ¶
func DefaultTheme() Theme
DefaultTheme returns the default TurboVision-inspired theme. Buttons use solid fill with no border; checkbox/radio symbols are configurable.
type Widget ¶
type Widget interface {
FocusOwner
Painter
Sizer
ConstraintsProvider
}
Widget is the full interface for interactive widgets.