Documentation
¶
Overview ¶
Package widget provides built-in UI components for the tui framework.
Widgets fall into two categories: passive widgets that only render (like Text and Progress) and interactive widgets that handle input events (like Input, List, and Table).
Interactive widgets follow a consistent pattern:
// In your Component's Update method: a.list, cmd = a.list.Update(msg) // In your Component's Render method: a.list.Render(buf, area)
Most widgets support an optional tui.Block for borders and titles:
block := tui.NewBlock() block.Title = "Items" a.list.SetBlock(block)
Image widgets use the Kitty Graphics Protocol via tui.ImagePlacement for rendering pixel-based graphics inline in the terminal.
Index ¶
- Variables
- type Alignment
- type AnimatedImage
- type Dialog
- type FocusInputMsg
- type Form
- type FormField
- type Gauge
- type Image
- type Input
- type List
- type ListItem
- type Progress
- type Scrollbar
- type Sparkline
- func (s *Sparkline) PushData(val float64, maxLen int) *Sparkline
- func (s *Sparkline) Render(buf *tui.Buffer, area tui.Rect)
- func (s *Sparkline) SetBlock(b tui.Block) *Sparkline
- func (s *Sparkline) SetData(data []float64) *Sparkline
- func (s *Sparkline) SetMaxVal(v float64) *Sparkline
- func (s *Sparkline) SetStyle(st tui.Style) *Sparkline
- type SparklineGroup
- type Spinner
- func (s *Spinner) Render(buf *tui.Buffer, area tui.Rect)
- func (s *Spinner) SetLabel(label string) *Spinner
- func (s *Spinner) SetSpinnerStyle(ss SpinnerStyle) *Spinner
- func (s *Spinner) SetStyle(st tui.Style) *Spinner
- func (s *Spinner) Tick() tui.Cmd
- func (s *Spinner) Update(msg tui.Msg) (*Spinner, tui.Cmd)
- func (s *Spinner) View() string
- type SpinnerStyle
- type SpinnerTickMsg
- type Table
- func (t *Table) Render(buf *tui.Buffer, area tui.Rect)
- func (t *Table) SelectedRow() []string
- func (t *Table) SetBlock(b tui.Block) *Table
- func (t *Table) SetColWidths(widths []int) *Table
- func (t *Table) SetRows(rows [][]string) *Table
- func (t *Table) SetSelectedStyle(s tui.Style) *Table
- func (t *Table) Update(msg tui.Msg) (*Table, tui.Cmd)
- type Tabs
- type Text
- type Tree
- type TreeNode
- type Viewport
- func (v *Viewport) LineCount() int
- func (v *Viewport) Render(buf *tui.Buffer, area tui.Rect)
- func (v *Viewport) ScrollTo(y int)
- func (v *Viewport) SetBlock(b tui.Block) *Viewport
- func (v *Viewport) SetContent(content string) *Viewport
- func (v *Viewport) SetStyle(s tui.Style) *Viewport
- func (v *Viewport) Update(msg tui.Msg) (*Viewport, tui.Cmd)
Constants ¶
This section is empty.
Variables ¶
var ( SpinnerDots = SpinnerStyle{ Frames: []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"}, Interval: 80 * time.Millisecond, } SpinnerLine = SpinnerStyle{ Frames: []string{"|", "/", "-", "\\"}, Interval: 100 * time.Millisecond, } SpinnerCircle = SpinnerStyle{ Frames: []string{"◐", "◓", "◑", "◒"}, Interval: 120 * time.Millisecond, } SpinnerBounce = SpinnerStyle{ Frames: []string{"⠁", "⠂", "⠄", "⡀", "⢀", "⠠", "⠐", "⠈"}, Interval: 100 * time.Millisecond, } SpinnerMeter = SpinnerStyle{ Frames: []string{"▱▱▱", "▰▱▱", "▰▰▱", "▰▰▰", "▰▰▱", "▰▱▱"}, Interval: 150 * time.Millisecond, } SpinnerGlobe = SpinnerStyle{ Frames: []string{"🌍", "🌎", "🌏"}, Interval: 200 * time.Millisecond, } SpinnerBlock = SpinnerStyle{ Frames: []string{"█", "▓", "▒", "░", "▒", "▓"}, Interval: 100 * time.Millisecond, } )
Predefined spinner styles.
Functions ¶
This section is empty.
Types ¶
type AnimatedImage ¶
type AnimatedImage struct {
Animation *tui.Animation
Block *tui.Block
// contains filtered or unexported fields
}
AnimatedImage displays an animated image using KGP animation frames.
func NewAnimatedImage ¶
func NewAnimatedImage(anim *tui.Animation) *AnimatedImage
NewAnimatedImage creates an animated image widget. The base image is transmitted as frame 1, and the Animation contains subsequent frames.
func (*AnimatedImage) Render ¶
func (a *AnimatedImage) Render(buf *tui.Buffer, area tui.Rect)
Render draws the animated image. On the first render, it transmits all frames.
func (*AnimatedImage) SetBlock ¶
func (a *AnimatedImage) SetBlock(b tui.Block) *AnimatedImage
SetBlock adds a border block.
type Dialog ¶
type Dialog struct {
Title string
Message string
Buttons []string
Selected int
Style tui.Style
Border tui.BorderStyle
// Styling
ButtonStyle tui.Style
SelectedButtonStyle tui.Style
MessageStyle tui.Style
}
Dialog is a modal dialog box with a message and buttons.
func (*Dialog) SelectedButton ¶
SelectedButton returns the text of the currently selected button.
func (*Dialog) SetButtons ¶
SetButtons sets the dialog buttons.
type FocusInputMsg ¶
type FocusInputMsg struct{}
FocusInputMsg signals that the input should receive focus.
type Form ¶
type Form struct {
Fields []FormField
FocusIndex int
Style tui.Style
LabelStyle tui.Style
LabelWidth int
Block *tui.Block
}
Form is a collection of labeled input fields.
func (*Form) FocusedField ¶
FocusedField returns the currently focused field.
type FormField ¶
FormField represents a single field in a form.
func NewFormField ¶
NewFormField creates a form field with label and placeholder.
type Gauge ¶
type Gauge struct {
Percent float64
Label string
Style tui.Style
FilledStyle tui.Style
Block *tui.Block
}
Gauge is a full-width progress gauge with a label overlay.
func (*Gauge) SetPercent ¶
SetPercent sets the gauge value (0.0 to 1.0).
type Image ¶
Image displays an image using the Kitty Graphics Protocol.
func NewImageFromFile ¶
NewImageFromFile creates an image widget that loads from a file path.
func NewImageFromID ¶
NewImageFromID creates an image widget for a previously transmitted image.
func NewImageFromPNG ¶
NewImageFromPNG creates an image widget from raw PNG data.
func NewImageFromRGB ¶
NewImageFromRGB creates an image widget from raw RGB pixel data.
func NewImageFromRGBA ¶
NewImageFromRGBA creates an image widget from raw RGBA pixel data.
func (*Image) SetCompression ¶
SetCompression enables ZLIB compression for RGBA/RGB data.
func (*Image) SetVirtual ¶
SetVirtual enables virtual (Unicode placeholder) placement.
type Input ¶
type Input struct {
Value string
Placeholder string
Style tui.Style
CursorStyle tui.Style
Focused bool
Block *tui.Block
// contains filtered or unexported fields
}
Input is a single-line text input widget.
type List ¶
type List struct {
Items []ListItem
Selected int
Style tui.Style
SelectedStyle tui.Style
Block *tui.Block
// contains filtered or unexported fields
}
List is a scrollable, selectable list widget.
func NewListFromItems ¶
NewListFromItems creates a list from ListItem values.
func (*List) SelectedItem ¶
SelectedItem returns the currently selected item, or nil if the list is empty.
func (*List) SetSelectedStyle ¶
SetSelectedStyle sets the selected item style.
type Progress ¶
type Progress struct {
Percent float64 // 0.0 to 1.0
Style tui.Style
FilledChar rune
EmptyChar rune
FilledStyle tui.Style
EmptyStyle tui.Style
Block *tui.Block
ShowLabel bool
}
Progress renders a progress bar.
func (*Progress) SetPercent ¶
SetPercent sets the progress value (0.0 to 1.0).
type Scrollbar ¶
type Scrollbar struct {
Total int // Total number of items/lines
Visible int // Number visible at once
Offset int // Current scroll offset
// Characters
TrackChar rune
ThumbChar rune
Style tui.Style
ThumbStyle tui.Style
Vertical bool // true = vertical (default), false = horizontal
}
Scrollbar renders a vertical or horizontal scrollbar.
func NewHScrollbar ¶
NewHScrollbar creates a horizontal scrollbar.
func NewScrollbar ¶
NewScrollbar creates a vertical scrollbar.
type Sparkline ¶
type Sparkline struct {
Data []float64
Style tui.Style
MaxVal float64 // 0 = auto
Block *tui.Block
}
Sparkline renders a mini line chart using braille/block characters.
func NewSparkline ¶
NewSparkline creates a new sparkline chart.
type SparklineGroup ¶
SparklineGroup renders multiple sparklines stacked vertically.
func NewSparklineGroup ¶
func NewSparklineGroup(sparklines ...*Sparkline) *SparklineGroup
NewSparklineGroup creates a group of sparklines.
func (*SparklineGroup) Render ¶
func (g *SparklineGroup) Render(buf *tui.Buffer, area tui.Rect)
Render draws all sparklines stacked.
func (*SparklineGroup) SetBlock ¶
func (g *SparklineGroup) SetBlock(b tui.Block) *SparklineGroup
SetBlock adds a border block.
type Spinner ¶
type Spinner struct {
SpinnerStyle SpinnerStyle
Style tui.Style
Label string
// contains filtered or unexported fields
}
Spinner is an animated loading indicator.
func (*Spinner) SetSpinnerStyle ¶
func (s *Spinner) SetSpinnerStyle(ss SpinnerStyle) *Spinner
SetSpinnerStyle changes the spinner animation.
type SpinnerStyle ¶
SpinnerStyle defines the frames of a spinner animation.
type SpinnerTickMsg ¶
SpinnerTickMsg triggers a spinner frame advance.
type Table ¶
type Table struct {
Headers []string
Rows [][]string
ColWidths []int // Fixed column widths (0 = auto)
Selected int
Style tui.Style
HeaderStyle tui.Style
SelectedStyle tui.Style
Block *tui.Block
// contains filtered or unexported fields
}
Table renders a data table with headers and rows.
func (*Table) SelectedRow ¶
SelectedRow returns the selected row data, or nil if empty.
func (*Table) SetColWidths ¶
SetColWidths sets fixed column widths.
func (*Table) SetSelectedStyle ¶
SetSelectedStyle sets the selected row style.
type Tabs ¶
type Tabs struct {
Titles []string
Selected int
Style tui.Style
ActiveStyle tui.Style
InactiveStyle tui.Style
Block *tui.Block
Separator string
}
Tabs renders a tab bar with selectable tabs.
type Text ¶
Text renders static text content.
func (*Text) SetAlignment ¶
SetAlignment sets text alignment.
type Tree ¶
type Tree struct {
Root []*TreeNode
Selected int // index in the flattened visible list
Style tui.Style
SelectedStyle tui.Style
Block *tui.Block
IndentSize int
// contains filtered or unexported fields
}
Tree is a navigable tree view widget.
func (*Tree) SelectedNode ¶
SelectedNode returns the currently selected tree node.
func (*Tree) SetSelectedStyle ¶
SetSelectedStyle sets the selected node style.
type TreeNode ¶
TreeNode represents a node in a tree view.
func NewTreeNode ¶
NewTreeNode creates a tree node.
type Viewport ¶
type Viewport struct {
Content string
Style tui.Style
Block *tui.Block
YOffset int
// contains filtered or unexported fields
}
Viewport is a scrollable text display widget.
func (*Viewport) SetContent ¶
SetContent updates the displayed text.