Documentation
¶
Index ¶
- func DefaultCellRenderer(ds TableDataSource, row, col int, selected bool, width int, styles TableStyles) string
- func LayoutHorizontal(children []Component, x, y, availW, availH, spacing int)
- func LayoutTCB(top, center, bottom Component, x, y, availW, availH int)
- func LayoutVertical(children []Component, x, y, availW, availH int)
- func PrepareCell(ds TableDataSource, row, col, width int) string
- type Alignment
- type BaseComponent
- func (bc *BaseComponent) Active() bool
- func (bc *BaseComponent) Alignment() Alignment
- func (bc *BaseComponent) Enabled() bool
- func (bc *BaseComponent) Focusable() bool
- func (bc *BaseComponent) Focused() bool
- func (bc *BaseComponent) HandleEvent(event Event) (tea.Cmd, bool)
- func (bc *BaseComponent) ID() string
- func (bc *BaseComponent) KeyBindings() []key.Binding
- func (bc *BaseComponent) Parent() Container
- func (bc *BaseComponent) Position() (int, int)
- func (bc *BaseComponent) PreferredHeight() int
- func (bc *BaseComponent) PreferredWidth() int
- func (bc *BaseComponent) RegisterKeyBinding(keys, description string, action func() tea.Cmd)
- func (bc *BaseComponent) RemoveKeyBinding(binding key.Binding)
- func (bc *BaseComponent) RenderInSize(content string) string
- func (bc *BaseComponent) ResolveKeyBinding(msg tea.KeyMsg) (func() tea.Cmd, bool)
- func (bc *BaseComponent) SetAlignment(a Alignment)
- func (bc *BaseComponent) SetEnabled(v bool)
- func (bc *BaseComponent) SetFocused(v bool) tea.Cmd
- func (bc *BaseComponent) SetParent(p Container)
- func (bc *BaseComponent) SetPosition(x, y int)
- func (bc *BaseComponent) SetPreferredHeight(h int)
- func (bc *BaseComponent) SetPreferredWidth(w int)
- func (bc *BaseComponent) SetSize(w, h int)
- func (bc *BaseComponent) SetVisible(v bool)
- func (bc *BaseComponent) Size() (int, int)
- func (bc *BaseComponent) View() string
- func (bc *BaseComponent) Visible() bool
- type BaseContainer
- type BorderConfig
- type BorderType
- type Button
- type ButtonStyles
- type Card
- type CardStyles
- type CellRenderer
- type CheckboxItem
- type CheckboxList
- func (cl *CheckboxList) BindDefaultActionToKey(keys string, description ...string)
- func (cl *CheckboxList) Cursor() int
- func (cl *CheckboxList) HandleEvent(event Event) (tea.Cmd, bool)
- func (cl *CheckboxList) Items() []CheckboxItem
- func (cl *CheckboxList) OnChange(fn func([]CheckboxItem) tea.Cmd)
- func (cl *CheckboxList) Selected() []string
- func (cl *CheckboxList) Update(msg tea.KeyMsg) (tea.Cmd, bool)
- func (cl *CheckboxList) View() string
- type CheckboxListStyles
- type ColumnDef
- type Component
- type Container
- type Event
- type Field
- type FieldStyles
- type FocusableComponent
- type FormattedTextInput
- type Layout
- type Leaf
- type MouseClickEvent
- type MouseScrollEvent
- type Panel
- type Position
- type ScrollableText
- func (st *ScrollableText) Content() string
- func (st *ScrollableText) HandleEvent(event Event) (tea.Cmd, bool)
- func (st *ScrollableText) ScrollTo(line int)
- func (st *ScrollableText) ScrollTop()
- func (st *ScrollableText) SetContent(text string)
- func (st *ScrollableText) SetWrap(wrap bool)
- func (st *ScrollableText) Update(msg tea.KeyMsg) (tea.Cmd, bool)
- func (st *ScrollableText) View() string
- type ScrollableTextStyles
- type SliceDataSource
- type TabBar
- func (tb *TabBar) ActiveTab() int
- func (tb *TabBar) BindDefaultActionToKey(keys string, description ...string)
- func (tb *TabBar) CursorTab() int
- func (tb *TabBar) HandleEvent(event Event) (tea.Cmd, bool)
- func (tb *TabBar) OnChange(fn func(int) tea.Cmd)
- func (tb *TabBar) SetActiveTab(i int)
- func (tb *TabBar) SetFocused(v bool) tea.Cmd
- func (tb *TabBar) SetTabKeyBinding(index int, keys string, description ...string)
- func (tb *TabBar) Update(msg tea.KeyMsg) (tea.Cmd, bool)
- func (tb *TabBar) View() string
- type TabBarStyles
- type TabComponent
- func (tc *TabComponent) ActiveTab() int
- func (tc *TabComponent) AddTab(label string, content Component)
- func (tc *TabComponent) OnChange(fn func(int) tea.Cmd)
- func (tc *TabComponent) SetActiveTab(index int)
- func (tc *TabComponent) SetTabKeyBinding(index int, keys string, description ...string)
- func (tc *TabComponent) TabBar() *TabBar
- func (tc *TabComponent) View() string
- type Table
- func (t *Table) Cursor() int
- func (t *Table) DataSource() TableDataSource
- func (t *Table) HandleEvent(event Event) (tea.Cmd, bool)
- func (t *Table) OnRowClick(fn func(row int) tea.Cmd)
- func (t *Table) OnRowKeyPress(fn func(row int, msg tea.KeyMsg) tea.Cmd)
- func (t *Table) SetColumnSpacing(spacing int)
- func (t *Table) SetCursor(c int)
- func (t *Table) SetDataSource(ds TableDataSource)
- func (t *Table) Update(msg tea.KeyMsg) (tea.Cmd, bool)
- func (t *Table) View() string
- type TableDataSource
- type TableStyles
- type Text
- type TextInput
- func (t *TextInput) Error() string
- func (t *TextInput) HandleEvent(event Event) (tea.Cmd, bool)
- func (t *TextInput) OnChange(fn func(string) tea.Cmd)
- func (t *TextInput) OnSubmit(fn func(string) tea.Cmd)
- func (t *TextInput) SetError(e string)
- func (t *TextInput) SetFocused(v bool) tea.Cmd
- func (t *TextInput) SetSize(w, h int)
- func (t *TextInput) SetValue(v string)
- func (t *TextInput) Update(msg tea.KeyMsg) (tea.Cmd, bool)
- func (t *TextInput) Value() string
- func (t *TextInput) View() string
- func (t *TextInput) WithCharLimit(n int) *TextInput
- func (t *TextInput) WithPlaceholder(p string) *TextInput
- type Toggle
- func (t *Toggle) BindDefaultActionToKey(keys string, description ...string)
- func (t *Toggle) HandleEvent(event Event) (tea.Cmd, bool)
- func (t *Toggle) On() bool
- func (t *Toggle) OnChange(fn func(bool) tea.Cmd)
- func (t *Toggle) SetLabels(onLabel, offLabel string)
- func (t *Toggle) SetOn(v bool)
- func (t *Toggle) Update(msg tea.KeyMsg) (tea.Cmd, bool)
- func (t *Toggle) View() string
- type ToggleMode
- type ToggleStyles
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultCellRenderer ¶
func DefaultCellRenderer(ds TableDataSource, row, col int, selected bool, width int, styles TableStyles) string
DefaultCellRenderer is the built-in cell renderer used when ColumnDef.Renderer is nil. It applies styles.Selected (with full width background) for selected rows, and styles.Cell otherwise.
func LayoutHorizontal ¶
LayoutHorizontal arranges children left-to-right within available space. Each child gets availH (unless it has a preferred height). Each child gets its preferred width, or its natural rendered width if no preference. No flexing — remaining space to the right is unused.
func LayoutTCB ¶
LayoutTCB arranges three slots: top, center, bottom. Top and Bottom get their preferred/natural height. Center gets ALL remaining height — this is the only layout that stretches. All slots get availW (unless they have a preferred width). Nil slots use no space.
func LayoutVertical ¶
LayoutVertical arranges children top-to-bottom within available space. Each child gets availW (unless it has a preferred width). Each child gets its preferred height, or its natural rendered height if no preference. No flexing — remaining space below the last child is unused.
func PrepareCell ¶
func PrepareCell(ds TableDataSource, row, col, width int) string
PrepareCell returns the cell value truncated to width, ready for styling. Use this in custom renderers to prevent lipgloss.Width() from wrapping long text into multiple lines.
Types ¶
type Alignment ¶
type Alignment int
Alignment controls horizontal alignment within a component's width.
type BaseComponent ¶
type BaseComponent struct {
// contains filtered or unexported fields
}
BaseComponent provides common fields and methods embedded by all concrete components.
func NewBaseComponent ¶
func NewBaseComponent(id string) *BaseComponent
NewBaseComponent creates a BaseComponent with sensible defaults.
func (*BaseComponent) Active ¶
func (bc *BaseComponent) Active() bool
Active returns true if this component is enabled and its parent (if any) is also active.
func (*BaseComponent) Alignment ¶
func (bc *BaseComponent) Alignment() Alignment
Alignment returns the current horizontal alignment.
func (*BaseComponent) Enabled ¶
func (bc *BaseComponent) Enabled() bool
func (*BaseComponent) Focusable ¶
func (bc *BaseComponent) Focusable() bool
func (*BaseComponent) Focused ¶
func (bc *BaseComponent) Focused() bool
func (*BaseComponent) HandleEvent ¶
func (bc *BaseComponent) HandleEvent(event Event) (tea.Cmd, bool)
HandleEvent default: not consumed, bubble to parent.
func (*BaseComponent) ID ¶
func (bc *BaseComponent) ID() string
func (*BaseComponent) KeyBindings ¶
func (bc *BaseComponent) KeyBindings() []key.Binding
func (*BaseComponent) Parent ¶
func (bc *BaseComponent) Parent() Container
func (*BaseComponent) Position ¶
func (bc *BaseComponent) Position() (int, int)
func (*BaseComponent) PreferredHeight ¶
func (bc *BaseComponent) PreferredHeight() int
func (*BaseComponent) PreferredWidth ¶
func (bc *BaseComponent) PreferredWidth() int
func (*BaseComponent) RegisterKeyBinding ¶
func (bc *BaseComponent) RegisterKeyBinding(keys, description string, action func() tea.Cmd)
RegisterKeyBinding registers a global key binding with its action on this component. keys is the key combo (e.g. "ctrl+q"). description is the help text (e.g. "Quit"). Pass empty description to hide from help/hints.
func (*BaseComponent) RemoveKeyBinding ¶
func (bc *BaseComponent) RemoveKeyBinding(binding key.Binding)
RemoveKeyBinding removes a previously registered key binding by matching its key(s). No-op if the binding is not found.
func (*BaseComponent) RenderInSize ¶
func (bc *BaseComponent) RenderInSize(content string) string
RenderInSize pads content to fill the component's stored width and height using its alignment. MaxWidth prevents wrapping — content is truncated if too wide. Components must render at their allocated size.
func (*BaseComponent) ResolveKeyBinding ¶
ResolveKeyBinding checks if the key message matches any registered binding. Returns the action and true if a match is found.
func (*BaseComponent) SetAlignment ¶
func (bc *BaseComponent) SetAlignment(a Alignment)
SetAlignment sets the horizontal alignment used by RenderInSize.
func (*BaseComponent) SetEnabled ¶
func (bc *BaseComponent) SetEnabled(v bool)
func (*BaseComponent) SetFocused ¶
func (bc *BaseComponent) SetFocused(v bool) tea.Cmd
func (*BaseComponent) SetParent ¶
func (bc *BaseComponent) SetParent(p Container)
func (*BaseComponent) SetPosition ¶
func (bc *BaseComponent) SetPosition(x, y int)
func (*BaseComponent) SetPreferredHeight ¶
func (bc *BaseComponent) SetPreferredHeight(h int)
func (*BaseComponent) SetPreferredWidth ¶
func (bc *BaseComponent) SetPreferredWidth(w int)
func (*BaseComponent) SetSize ¶
func (bc *BaseComponent) SetSize(w, h int)
func (*BaseComponent) SetVisible ¶
func (bc *BaseComponent) SetVisible(v bool)
func (*BaseComponent) Size ¶
func (bc *BaseComponent) Size() (int, int)
func (*BaseComponent) View ¶
func (bc *BaseComponent) View() string
func (*BaseComponent) Visible ¶
func (bc *BaseComponent) Visible() bool
type BaseContainer ¶
type BaseContainer struct {
BaseComponent
// contains filtered or unexported fields
}
BaseContainer is a component composed of other components.
func NewBaseContainer ¶
func NewBaseContainer(id string, self Container) *BaseContainer
NewBaseContainer creates a BaseContainer with sensible defaults. If self is non-nil it is used as the parent reference for AddChild; otherwise the BaseContainer itself is used (useful in tests).
func (*BaseContainer) AddChild ¶
func (bc *BaseContainer) AddChild(child Component)
AddChild appends a child component and sets its parent to bc.self.
func (*BaseContainer) Children ¶
func (bc *BaseContainer) Children() []Component
Children returns the child components.
func (*BaseContainer) Focusable ¶
func (bc *BaseContainer) Focusable() bool
Focusable returns false; containers do not receive focus directly.
func (*BaseContainer) InnerFocused ¶
func (bc *BaseContainer) InnerFocused() bool
InnerFocused returns true if any descendant has focus.
func (*BaseContainer) View ¶
func (bc *BaseContainer) View() string
View returns an empty string; concrete containers override with their layout.
type BorderConfig ¶
type BorderConfig struct {
Type BorderType
Color lipgloss.Color // border color when no inner focus
ActiveColor lipgloss.Color // border color when inner focused
Padding int // horizontal padding inside border (columns per side)
}
BorderConfig defines the border appearance for a Panel.
func DefaultBorder ¶
func DefaultBorder() BorderConfig
DefaultBorder returns the default border configuration.
func SingleLineBorder ¶
func SingleLineBorder(color, activeColor string) BorderConfig
SingleLineBorder creates a BorderConfig with rounded border style.
func (BorderConfig) ChromeHeight ¶
func (bc BorderConfig) ChromeHeight() int
ChromeHeight returns the total vertical chrome (border) in rows.
func (BorderConfig) ChromeWidth ¶
func (bc BorderConfig) ChromeWidth() int
ChromeWidth returns the total horizontal chrome (border + padding) in columns.
func (BorderConfig) HasBorder ¶
func (bc BorderConfig) HasBorder() bool
HasBorder returns true if the border type is not NoBorder.
type BorderType ¶
type BorderType int
BorderType defines the visual style of a panel's border.
const ( NoBorder BorderType = iota // no border (default) RoundedBorder // rounded corners )
type Button ¶
type Button struct {
FocusableComponent
// contains filtered or unexported fields
}
Button is a focusable action button component.
func NewButton ¶
func NewButton(id, label string, styles ButtonStyles) *Button
NewButton creates a new Button with the given ID, label, and styles.
func (*Button) BindDefaultActionToKey ¶
BindDefaultActionToKey registers a global key binding that triggers the button's default action (onPress).
func (*Button) HandleEvent ¶
HandleEvent handles high-level events. MouseClick fires onPress.
type ButtonStyles ¶
ButtonStyles defines the styles used by a Button in different states.
func DefaultButtonStyles ¶
func DefaultButtonStyles() ButtonStyles
DefaultButtonStyles returns a ButtonStyles with sensible defaults.
func DefaultPopupButtonStyles ¶
func DefaultPopupButtonStyles() ButtonStyles
DefaultPopupButtonStyles returns a ButtonStyles with defaults for popup buttons.
type Card ¶
type Card struct {
BaseComponent
// contains filtered or unexported fields
}
Card is a non-focusable bordered display component showing a title and value.
func NewCard ¶
func NewCard(id, title, value string, styles CardStyles) *Card
NewCard creates a new Card with the given ID, title, value, and styles.
func (*Card) SetAlert ¶
SetAlert sets whether the card value should be rendered with the alert style.
type CardStyles ¶
type CardStyles struct {
Border lipgloss.Style
Title lipgloss.Style
Value lipgloss.Style
Alert lipgloss.Style // for values that exceed thresholds
}
CardStyles defines the styles used by a Card component.
func DefaultCardStyles ¶
func DefaultCardStyles() CardStyles
DefaultCardStyles returns a CardStyles with sensible defaults.
type CellRenderer ¶
type CellRenderer func(ds TableDataSource, row, col int, selected bool, width int, styles TableStyles) string
CellRenderer renders a single table cell. The renderer receives the data source (for cross-column lookups), position, selection state, the resolved cell width, and the table's styles. It returns a fully styled string. Use PrepareCell to get a truncated value safe for single-line rendering.
type CheckboxItem ¶
CheckboxItem represents a single item in a CheckboxList.
type CheckboxList ¶
type CheckboxList struct {
FocusableComponent
// contains filtered or unexported fields
}
CheckboxList is a focusable list of checkable items.
func NewCheckboxList ¶
func NewCheckboxList(id string, items []CheckboxItem, styles CheckboxListStyles) *CheckboxList
NewCheckboxList creates a new CheckboxList with the given ID, items, and styles.
func (*CheckboxList) BindDefaultActionToKey ¶
func (cl *CheckboxList) BindDefaultActionToKey(keys string, description ...string)
BindDefaultActionToKey registers a global key binding that triggers the checkbox's default action (toggle the item at cursor).
func (*CheckboxList) Cursor ¶
func (cl *CheckboxList) Cursor() int
Cursor returns the current cursor position.
func (*CheckboxList) HandleEvent ¶
func (cl *CheckboxList) HandleEvent(event Event) (tea.Cmd, bool)
HandleEvent handles high-level events. MouseClick toggles cursor item.
func (*CheckboxList) Items ¶
func (cl *CheckboxList) Items() []CheckboxItem
Items returns the current items.
func (*CheckboxList) OnChange ¶
func (cl *CheckboxList) OnChange(fn func([]CheckboxItem) tea.Cmd)
OnChange sets the callback invoked when an item is toggled.
func (*CheckboxList) Selected ¶
func (cl *CheckboxList) Selected() []string
Selected returns the values of all checked items.
type CheckboxListStyles ¶
type CheckboxListStyles struct {
Cursor lipgloss.Style // "> " marker on current item
Checked lipgloss.Style // "[x] " checked indicator
Unchecked lipgloss.Style // "[ ] " unchecked indicator
Item lipgloss.Style // normal item label
Group lipgloss.Style // group item label
Dim lipgloss.Style // non-cursor items prefix (" ")
}
CheckboxListStyles defines the styles used by a CheckboxList.
func DefaultCheckboxListStyles ¶
func DefaultCheckboxListStyles() CheckboxListStyles
DefaultCheckboxListStyles returns a CheckboxListStyles with sensible defaults.
type ColumnDef ¶
type ColumnDef struct {
Title string
Width int // fixed width; 0 = take remaining space
Renderer CellRenderer // nil = default renderer
}
ColumnDef defines a single column in the table.
type Component ¶
type Component interface {
ID() string
View() string
SetSize(w, h int)
Size() (w, h int)
SetPosition(x, y int)
Position() (x, y int)
Visible() bool
SetVisible(bool)
Enabled() bool
SetEnabled(bool)
Active() bool
Focusable() bool
Focused() bool
SetFocused(bool) tea.Cmd
Parent() Container
SetParent(Container)
KeyBindings() []key.Binding
RegisterKeyBinding(keys, description string, action func() tea.Cmd)
ResolveKeyBinding(tea.KeyMsg) (func() tea.Cmd, bool)
// HandleEvent receives high-level UI events. If not consumed (returns false),
// the base implementation bubbles the event up to the parent.
HandleEvent(event Event) (tea.Cmd, bool)
PreferredWidth() int
PreferredHeight() int
SetPreferredWidth(int)
SetPreferredHeight(int)
}
Component is the base interface for all UI elements.
type Container ¶
type Container interface {
Component
Children() []Component
AddChild(child Component)
InnerFocused() bool
}
Container is a component composed of other components.
type Event ¶
type Event interface {
// contains filtered or unexported methods
}
Event is a high-level UI event dispatched to components.
type Field ¶
type Field struct {
BaseContainer
// contains filtered or unexported fields
}
Field composes a label (Text), separator (Text), and an input component. The Field controls the label's style based on focus state — when any descendant has focus, the label highlights. The separator never highlights.
Construction: NewField("name", "Name", textBox, styles) Renders: <label><separator><input>
func NewField ¶
func NewField(id, labelText string, input Component, styles FieldStyles) *Field
NewField creates a Field with a label, ": " separator, and the given input component.
type FieldStyles ¶
type FieldStyles struct {
Label lipgloss.Style // label when no inner focus
LabelHot lipgloss.Style // label when input has focus
Separator lipgloss.Style // separator style (always the same)
}
FieldStyles defines the styles used by a Field.
func DefaultFieldStyles ¶
func DefaultFieldStyles() FieldStyles
DefaultFieldStyles returns a FieldStyles with sensible defaults.
type FocusableComponent ¶
type FocusableComponent struct {
BaseComponent
// contains filtered or unexported fields
}
FocusableComponent extends BaseComponent for components that can receive focus. Adds OnKeyPress handler and overrides Focusable() to return true. Leaf components embed this instead of BaseComponent.
func NewFocusableComponent ¶
func NewFocusableComponent(id string) FocusableComponent
NewFocusableComponent creates a FocusableComponent with sensible defaults.
func (*FocusableComponent) Focusable ¶
func (fc *FocusableComponent) Focusable() bool
func (*FocusableComponent) OnKeyPress ¶
func (fc *FocusableComponent) OnKeyPress(fn func(tea.KeyMsg) tea.Cmd)
OnKeyPress sets a handler called when the component has focus and receives a key that the component's internal Update doesn't consume.
type FormattedTextInput ¶
type FormattedTextInput struct {
TextInput
// contains filtered or unexported fields
}
FormattedTextInput extends TextInput with validation and formatting.
func NewFormattedTextInput ¶
func NewFormattedTextInput(id string, inputWidth int) *FormattedTextInput
NewFormattedTextInput creates a new FormattedTextInput with the given ID and input width.
func (*FormattedTextInput) SetFocused ¶
func (fti *FormattedTextInput) SetFocused(focused bool) tea.Cmd
SetFocused sets the focused state. On blur, it runs validation and formatting.
func (*FormattedTextInput) WithFormat ¶
func (fti *FormattedTextInput) WithFormat(fn func(string) string)
WithFormat sets the format function applied on blur after successful validation.
func (*FormattedTextInput) WithValidation ¶
func (fti *FormattedTextInput) WithValidation(fn func(string) error)
WithValidation sets the validation function. Validation runs on blur.
type Leaf ¶
Leaf is a focusable component that handles keyboard input. Only focused leaves receive keyboard events. Mouse and other events go through HandleEvent on Component.
type MouseClickEvent ¶
type MouseClickEvent struct {
X, Y int
Button tea.MouseButton
}
MouseClickEvent is sent when a mouse button is pressed on a component.
type MouseScrollEvent ¶
MouseScrollEvent is sent when the mouse wheel is scrolled over a component. Direction: negative = up, positive = down.
type Panel ¶
type Panel struct {
BaseContainer
// contains filtered or unexported fields
}
Panel is the universal container. It has a layout (Vertical, Horizontal, or TCB), an optional border, an optional title, and a unified Add(child, Position) method.
func NewPanel ¶
NewPanel creates a Panel. Layout defaults to Vertical. Optional layout parameter: NewPanel("id") or NewPanel("id", TCB)
func (*Panel) Add ¶
Add places a child component at the given position. For Vertical/Horizontal: use Next to append sequentially. For TCB: use Next (fills Top->Center->Bottom) or explicit TCBTop/TCBCenter/TCBBottom.
func (*Panel) SetBorder ¶
func (p *Panel) SetBorder(config BorderConfig)
SetBorder sets the border configuration.
func (*Panel) SetSpacing ¶
SetSpacing sets spacing between children (Horizontal layout only).
func (*Panel) SetTitle ¶
SetTitle sets the panel's title text (rendered inside the border, above children).
func (*Panel) SetTitleStyle ¶
SetTitleStyle sets the style for the title text.
type ScrollableText ¶
type ScrollableText struct {
FocusableComponent
// contains filtered or unexported fields
}
ScrollableText is a focusable, scrollable, read-only text display area. It renders text within its SetSize bounds and scrolls with keyboard input when focused. Content may contain ANSI color codes.
func NewScrollableText ¶
func NewScrollableText(id string, styles ScrollableTextStyles) *ScrollableText
NewScrollableText creates a new ScrollableText with the given ID and styles.
func (*ScrollableText) Content ¶
func (st *ScrollableText) Content() string
Content returns the current content.
func (*ScrollableText) HandleEvent ¶
func (st *ScrollableText) HandleEvent(event Event) (tea.Cmd, bool)
HandleEvent handles mouse scroll events.
func (*ScrollableText) ScrollTo ¶
func (st *ScrollableText) ScrollTo(line int)
ScrollTo scrolls to a specific line (clamped to valid range).
func (*ScrollableText) ScrollTop ¶
func (st *ScrollableText) ScrollTop()
ScrollTop scrolls to the top.
func (*ScrollableText) SetContent ¶
func (st *ScrollableText) SetContent(text string)
SetContent sets the full text content (may contain newlines and ANSI styling).
func (*ScrollableText) SetWrap ¶
func (st *ScrollableText) SetWrap(wrap bool)
SetWrap sets whether long lines are wrapped to fit the viewport width. When false, lines are truncated. Default is true.
func (*ScrollableText) View ¶
func (st *ScrollableText) View() string
View renders the visible portion of the text content.
type ScrollableTextStyles ¶
type ScrollableTextStyles struct {
Normal lipgloss.Style // unfocused appearance
Focused lipgloss.Style // focused appearance
}
ScrollableTextStyles defines the styles used by ScrollableText.
func DefaultScrollableTextStyles ¶
func DefaultScrollableTextStyles() ScrollableTextStyles
DefaultScrollableTextStyles returns sensible defaults for ScrollableText.
type SliceDataSource ¶
type SliceDataSource struct {
// contains filtered or unexported fields
}
SliceDataSource is a TableDataSource backed by a [][]string.
func NewSliceDataSource ¶
func NewSliceDataSource(data [][]string) *SliceDataSource
NewSliceDataSource creates a SliceDataSource wrapping the given data.
func (*SliceDataSource) CellData ¶
func (s *SliceDataSource) CellData(row, col int) string
func (*SliceDataSource) RowCount ¶
func (s *SliceDataSource) RowCount() int
func (*SliceDataSource) SetData ¶
func (s *SliceDataSource) SetData(data [][]string)
SetData replaces the backing data. The Table re-reads on the next render.
type TabBar ¶
type TabBar struct {
FocusableComponent
// contains filtered or unexported fields
}
TabBar is a focusable horizontal tab selector component. It has two distinct states:
- cursor: which tab the keyboard highlight is on (moves with left/right)
- active: which tab's content is currently displayed (changes on space/enter)
func NewTabBar ¶
func NewTabBar(id string, labels []string, styles TabBarStyles) *TabBar
NewTabBar creates a new TabBar with the given ID, labels, and styles.
func (*TabBar) BindDefaultActionToKey ¶
BindDefaultActionToKey registers a global key binding that triggers the tab bar's default action (activate the tab under cursor).
func (*TabBar) HandleEvent ¶
HandleEvent handles mouse clicks by activating the clicked tab. The click X is relative to the tab bar's position and mapped to a tab using the rendered width of each label (including style padding).
func (*TabBar) OnChange ¶
OnChange sets the callback invoked when the active tab changes (on space/enter).
func (*TabBar) SetActiveTab ¶
SetActiveTab sets the active tab index and moves the cursor to match.
func (*TabBar) SetFocused ¶
SetFocused overrides to reset cursor to active tab when gaining focus.
func (*TabBar) SetTabKeyBinding ¶
SetTabKeyBinding binds a keyboard shortcut to activate a specific tab by index. The keys parameter is a key combo string (e.g. "ctrl+d"). The optional description is used for help text; if omitted, the tab's label is used. Panics if index is out of range. If a binding already exists for this index, it is replaced.
func (*TabBar) Update ¶
Update handles key input. Left/right moves the cursor. Space/enter activates the tab under the cursor.
func (*TabBar) View ¶
View renders the tabs horizontally joined with the appropriate styles.
Rendering rules:
- Active tab (content displayed): Active style
- Cursor tab (when focused and cursor != active): Focused style (yellow, highlighted)
- Active + cursor (focused, cursor on active tab): Active style with underline
- Other tabs: Inactive style
type TabBarStyles ¶
type TabBarStyles struct {
Active lipgloss.Style // selected tab
Inactive lipgloss.Style // non-selected tab
Focused lipgloss.Style // focused inactive tab (keyboard cursor on it but not the selected tab)
}
TabBarStyles defines the styles used by a TabBar in different states.
func DefaultTabBarStyles ¶
func DefaultTabBarStyles() TabBarStyles
DefaultTabBarStyles returns a TabBarStyles with sensible defaults.
type TabComponent ¶
type TabComponent struct {
BaseContainer
// contains filtered or unexported fields
}
TabComponent is a container that manages tab switching. It uses TCB layout internally: the TabBar header at the top, the active tab's content panel at the center (fills remaining space).
Usage:
tabs := widget.NewTabComponent("tabs", themeTabBarStyles())
tabs.AddTab("Dashboard", dashPanel)
tabs.AddTab("Servers", serverPanel)
tabs.AddTab("Settings", settingsPanel)
tabs.SetTabKeyBinding(0, "ctrl+d")
win.Add(tabs, widget.TCBCenter)
func NewTabComponent ¶
func NewTabComponent(id string, styles TabBarStyles) *TabComponent
NewTabComponent creates a TabComponent with the given ID and tab bar styles.
func (*TabComponent) ActiveTab ¶
func (tc *TabComponent) ActiveTab() int
ActiveTab returns the index of the currently active tab.
func (*TabComponent) AddTab ¶
func (tc *TabComponent) AddTab(label string, content Component)
AddTab adds a tab with the given label and content panel.
func (*TabComponent) OnChange ¶
func (tc *TabComponent) OnChange(fn func(int) tea.Cmd)
OnChange sets a callback invoked when the active tab changes.
func (*TabComponent) SetActiveTab ¶
func (tc *TabComponent) SetActiveTab(index int)
SetActiveTab switches to the tab at the given index.
func (*TabComponent) SetTabKeyBinding ¶
func (tc *TabComponent) SetTabKeyBinding(index int, keys string, description ...string)
SetTabKeyBinding binds a keyboard shortcut to activate a specific tab.
func (*TabComponent) TabBar ¶
func (tc *TabComponent) TabBar() *TabBar
TabBar returns the underlying TabBar leaf component.
func (*TabComponent) View ¶
func (tc *TabComponent) View() string
View renders the tab header at the top and the active tab's content filling the remaining height.
type Table ¶
type Table struct {
FocusableComponent
// contains filtered or unexported fields
}
Table is a generic, column-aware scrollable data table with cursor selection and per-cell rendering. Data is provided via a TableDataSource.
func NewTable ¶
func NewTable(id string, columns []ColumnDef, ds TableDataSource, styles TableStyles) *Table
NewTable creates a new Table with the given ID, columns, data source, and styles.
func (*Table) DataSource ¶
func (t *Table) DataSource() TableDataSource
DataSource returns the current data source.
func (*Table) HandleEvent ¶
HandleEvent handles mouse clicks and scroll wheel events. Clicks select the row under the cursor. Scroll wheel moves the cursor up/down by 3 rows (matching typical terminal scroll speed).
func (*Table) OnRowClick ¶
OnRowClick sets a handler called when a data row is clicked. The handler receives the zero-based row index.
func (*Table) OnRowKeyPress ¶
OnRowKeyPress sets a handler called when the table has focus and receives a key that the table's internal navigation doesn't consume. Unlike OnKeyPress, this passes the current cursor row so the handler has row context.
func (*Table) SetColumnSpacing ¶
SetColumnSpacing sets the number of spaces between columns. Default is 1.
func (*Table) SetDataSource ¶
func (t *Table) SetDataSource(ds TableDataSource)
SetDataSource replaces the data source and clamps the cursor.
type TableDataSource ¶
type TableDataSource interface {
// RowCount returns the total number of rows.
RowCount() int
// CellData returns the raw (unstyled) string for the given cell.
// The Table guarantees row < RowCount() and col < len(columns).
CellData(row, col int) string
}
TableDataSource provides row data to a Table. Implementations must return consistent results within a single render cycle. To change the data, call Table.SetDataSource with a new (or updated) source.
type TableStyles ¶
type TableStyles struct {
Header lipgloss.Style
Selected lipgloss.Style
Cell lipgloss.Style // default cell style when no column renderer
}
TableStyles defines the styles used by the Table.
func DefaultTableStyles ¶
func DefaultTableStyles() TableStyles
DefaultTableStyles returns a TableStyles with sensible defaults.
type Text ¶
type Text struct {
BaseComponent
// contains filtered or unexported fields
}
Text is a non-focusable component that renders a styled string. It knows nothing about focus, parents, or context — it just displays text with whatever style has been set on it. The parent controls the style based on application state.
type TextInput ¶
type TextInput struct {
FocusableComponent
// contains filtered or unexported fields
}
TextInput is a focusable text input box. It wraps bubbles/textinput and handles cursor, placeholder, and character input. It does NOT render a label — use Field for label + separator + input.
func NewTextInput ¶
NewTextInput creates a new TextInput with the given ID and input width.
func (*TextInput) HandleEvent ¶
HandleEvent — text inputs do not react to clicks (just focus).
func (*TextInput) SetFocused ¶
SetFocused sets the focused state and focuses/blurs the inner textinput.
func (*TextInput) Update ¶
Update handles key input. Enter triggers onSubmit; all other keys are delegated to the inner textinput. Returns (cmd, true) consuming ALL input when active. If not active, returns (nil, false).
func (*TextInput) WithCharLimit ¶
WithCharLimit sets the character limit for the input.
func (*TextInput) WithPlaceholder ¶
WithPlaceholder sets placeholder text displayed when the field is empty.
type Toggle ¶
type Toggle struct {
FocusableComponent
// contains filtered or unexported fields
}
Toggle is a boolean on/off component with two rendering modes.
func NewToggle ¶
func NewToggle(id, label string, initial bool, mode ToggleMode, styles ToggleStyles) *Toggle
NewToggle creates a new Toggle with the given ID, label, initial state, mode, and styles.
func (*Toggle) BindDefaultActionToKey ¶
BindDefaultActionToKey registers a global key binding that triggers the toggle's default action (toggle state).
func (*Toggle) HandleEvent ¶
HandleEvent handles high-level events. MouseClick toggles state.
type ToggleMode ¶
type ToggleMode int
ToggleMode controls how the toggle is rendered.
const ( // ToggleModeOnOff renders one value at a time: "Feature:[on]" or "Feature:[off]". ToggleModeOnOff ToggleMode = iota // ToggleModeRadio renders both labels side by side: "[Live] [Cache]". ToggleModeRadio )
type ToggleStyles ¶
type ToggleStyles struct {
Label lipgloss.Style // label prefix
OnActive lipgloss.Style // on value, unfocused (green)
OnFocused lipgloss.Style // on value, focused (yellow)
OffActive lipgloss.Style // off value, unfocused (dim for OnOff, orange for Radio)
OffFocused lipgloss.Style // off value, focused (yellow)
OffInactive lipgloss.Style // off value, not selected (dim) — used in Radio mode
}
ToggleStyles defines the styles used by a Toggle in different states.
func DefaultToggleStyles ¶
func DefaultToggleStyles() ToggleStyles
DefaultToggleStyles returns a ToggleStyles with sensible defaults.