widgets

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SpinnerLine           = []string{"|", "/", "-", "\\"}
	SpinnerDots           = []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"}
	SpinnerMiniDots       = []string{"⠋", "⠙", "⠚", "⠞", "⠖", "⠦", "⠴", "⠲", "⠳", "⠓"}
	SpinnerPulse          = []string{"█", "▓", "▒", "░"}
	SpinnerPoints         = []string{"∙∙∙", "●∙∙", "∙●∙", "∙∙●", "∙∙∙"}
	SpinnerGlobe          = []string{"🌍", "🌎", "🌏"}
	SpinnerMoon           = []string{"🌑", "🌒", "🌓", "🌔", "🌕", "🌖", "🌗", "🌘"}
	SpinnerClock          = []string{"🕛", "🕐", "🕑", "🕒", "🕓", "🕔", "🕕", "🕖", "🕗", "🕘", "🕙", "🕚"}
	SpinnerMonkey         = []string{"🙈", "🙉", "🙊"}
	SpinnerStar           = []string{"✶", "✸", "✹", "✺", "✹", "✸"}
	SpinnerHamburger      = []string{"☱", "☲", "☴"}
	SpinnerGrowVertical   = []string{" ", "▃", "▄", "▅", "▆", "▇", "█", "▇", "▆", "▅", "▄", "▃"}
	SpinnerGrowHorizontal = []string{"▉", "▊", "▋", "▌", "▍", "▎", "▏", "▎", "▍", "▌", "▋", "▊", "▉"}
	SpinnerArrow          = []string{"←", "↖", "↑", "↗", "→", "↘", "↓", "↙"}
	SpinnerTriangle       = []string{"◢", "◣", "◤", "◥"}
	SpinnerCircleHalves   = []string{"◐", "◓", "◑", "◒"}
	SpinnerBouncingBall   = []string{"⠁", "⠂", "⠄", "⡀", "⢀", "⠠", "⠐", "⠈"}
)

Functions

This section is empty.

Types

type BarChart

type BarChart struct {
	ui.Block
	BarColors    []ui.Color
	LabelStyles  []ui.Style
	NumStyles    []ui.Style
	NumFormatter func(float64) string
	Data         []float64
	Labels       []string
	BarWidth     int
	BarGap       int
	MaxVal       float64
}

BarChart represents a widget that displays a bar chart.

func NewBarChart

func NewBarChart() *BarChart

NewBarChart returns a new BarChart.

func (*BarChart) Draw

func (bc *BarChart) Draw(buf *ui.Buffer)

Draw draws the bar chart to the buffer.

type Button

type Button struct {
	ui.Block
	Text        string
	TextStyle   ui.Style
	ActiveStyle ui.Style
	IsActive    bool
	OnClick     func()
}

Button represents a clickable button widget.

func NewButton

func NewButton(text string) *Button

NewButton returns a new Button with the given text.

func (*Button) Activate

func (b *Button) Activate()

func (*Button) Deactivate

func (b *Button) Deactivate()

func (*Button) Draw

func (b *Button) Draw(buf *ui.Buffer)

Draw draws the button to the buffer.

type Calendar

type Calendar struct {
	ui.Block
	Month       time.Month
	Year        int
	CurrentDay  int
	SelectedDay int
	HeaderStyle ui.Style
	DayStyle    ui.Style
}

func NewCalendar

func NewCalendar() *Calendar

func (*Calendar) Draw

func (c *Calendar) Draw(buf *ui.Buffer)

type Checkbox

type Checkbox struct {
	ui.Block
	Label       string
	Checked     bool
	CheckedRune rune
	TextStyle   ui.Style
}

Checkbox represents a checkbox widget.

func NewCheckbox

func NewCheckbox(label string) *Checkbox

NewCheckbox returns a new Checkbox with the given label.

func (*Checkbox) Draw

func (c *Checkbox) Draw(buf *ui.Buffer)

Draw draws the checkbox to the buffer.

func (*Checkbox) Toggle

func (c *Checkbox) Toggle()

type DrawDirection

type DrawDirection uint

DrawDirection represents the direction of drawing.

const (
	DrawLeft DrawDirection = iota
	DrawRight
)

type EchoMode

type EchoMode int
const (
	EchoNormal EchoMode = iota
	EchoPassword
)

type Flex

type Flex struct {
	ui.Block
	Items     []*flexItem
	Direction FlexDirection
}

Flex represents a flex container widget.

func NewFlex

func NewFlex() *Flex

NewFlex returns a new Flex container.

func (*Flex) AddItem

func (f *Flex) AddItem(widget ui.Drawable, fixedSize, proportion int, focus bool)

AddItem adds a new widget to the flex container.

func (*Flex) Draw

func (f *Flex) Draw(buf *ui.Buffer)

type FlexDirection

type FlexDirection int

FlexDirection represents the direction of the flex container.

const (
	FlexRow FlexDirection = iota
	FlexColumn
)

type FunnelChart

type FunnelChart struct {
	ui.Block
	Data          []float64
	Labels        []string
	Colors        []ui.Color
	UniformHeight bool
}

FunnelChart represents a widget that displays a funnel chart.

func NewFunnelChart

func NewFunnelChart() *FunnelChart

NewFunnelChart returns a new FunnelChart.

func (*FunnelChart) Draw

func (fc *FunnelChart) Draw(buf *ui.Buffer)

Draw draws the funnel chart to the buffer.

type Gauge

type Gauge struct {
	ui.Block
	Percent       int
	BarColor      ui.Color
	Label         string
	LabelStyle    ui.Style // Style for labels outside the filled bar
	BarLabelStyle ui.Style // Style for labels inside the filled bar
	Gradient      ui.Gradient
}

Gauge represents a widget that displays a progress bar.

func NewGauge

func NewGauge() *Gauge

NewGauge returns a new Gauge.

func (*Gauge) Draw

func (g *Gauge) Draw(buf *ui.Buffer)

Draw draws the gauge to the buffer.

type Heatmap

type Heatmap struct {
	ui.Block
	Data      [][]float64
	CellWidth int
	CellGap   int
	XLabels   []string
	YLabels   []string
	Colors    []ui.Color
	TextColor ui.Style
}

Heatmap represents a widget that displays a heat map.

func NewHeatmap

func NewHeatmap() *Heatmap

NewHeatmap returns a new Heatmap.

func (*Heatmap) Draw

func (h *Heatmap) Draw(buf *ui.Buffer)

Draw draws the heatmap to the buffer.

type Image

type Image struct {
	ui.Block
	Image               image.Image
	Monochrome          bool
	MonochromeThreshold uint8
	MonochromeInvert    bool
}

Image represents a widget that displays an image.

func NewImage

func NewImage(img image.Image) *Image

NewImage returns a new Image.

func (*Image) Draw

func (img *Image) Draw(buf *ui.Buffer)

Draw draws the image to the buffer.

type Input

type Input struct {
	ui.Block
	Text        string
	TextStyle   ui.Style
	CursorStyle ui.Style
	Placeholder string
	EchoMode    EchoMode
	Cursor      int

	sync.Mutex
	// contains filtered or unexported fields
}

Input represents a text input widget.

func NewInput

func NewInput() *Input

NewInput returns a new Input.

func (*Input) Backspace

func (i *Input) Backspace()

func (*Input) Draw

func (i *Input) Draw(buf *ui.Buffer)

Draw draws the input to the buffer.

func (*Input) InsertRune

func (i *Input) InsertRune(r rune)

func (*Input) MoveCursorLeft

func (i *Input) MoveCursorLeft()

func (*Input) MoveCursorRight

func (i *Input) MoveCursorRight()

type LineGauge

type LineGauge struct {
	ui.Block
	Percent        int
	LineColor      ui.Color
	Label          string
	LabelStyle     ui.Style
	LabelAlignment ui.Alignment
	BarRune        rune
	BarRuneEmpty   rune
}

LineGauge represents a widget that displays a line gauge.

func NewLineGauge

func NewLineGauge() *LineGauge

NewLineGauge returns a new LineGauge.

func (*LineGauge) Draw

func (g *LineGauge) Draw(buf *ui.Buffer)

Draw draws the line gauge to the buffer.

type List

type List struct {
	ui.Block
	Rows          []string
	WrapText      bool
	TextStyle     ui.Style
	SelectedStyle ui.Style
	TextAlignment ui.Alignment
	SelectedRow   int
	Gradient      ui.Gradient
	// contains filtered or unexported fields
}

List represents a widget that displays a list of items.

func NewList

func NewList() *List

NewList returns a new List.

func (*List) Draw

func (l *List) Draw(buf *ui.Buffer)

Draw draws the list to the buffer.

func (*List) ScrollAmount

func (l *List) ScrollAmount(amount int)

ScrollAmount scrolls the list by the given amount.

func (*List) ScrollBottom

func (l *List) ScrollBottom()

ScrollBottom scrolls the list to the bottom.

func (*List) ScrollDown

func (l *List) ScrollDown()

ScrollDown scrolls the list down by one row.

func (*List) ScrollHalfPageDown

func (l *List) ScrollHalfPageDown()

ScrollHalfPageDown scrolls the list down by half a page.

func (*List) ScrollHalfPageUp

func (l *List) ScrollHalfPageUp()

ScrollHalfPageUp scrolls the list up by half a page.

func (*List) ScrollPageDown

func (l *List) ScrollPageDown()

ScrollPageDown scrolls the list down by one page.

func (*List) ScrollPageUp

func (l *List) ScrollPageUp()

ScrollPageUp scrolls the list up by one page.

func (*List) ScrollTop

func (l *List) ScrollTop()

ScrollTop scrolls the list to the top.

func (*List) ScrollUp

func (l *List) ScrollUp()

ScrollUp scrolls the list up by one row.

type Logo struct {
	ui.Block
	Gradient ui.Gradient
}

Logo represents a widget that displays the gotui logo.

func NewLogo() *Logo

NewLogo returns a new Logo.

func (*Logo) Draw

func (l *Logo) Draw(buf *ui.Buffer)

Draw draws the logo to the buffer.

type Modal struct {
	ui.Block
	Text              string
	TextStyle         ui.Style
	Buttons           []*Button
	ActiveButtonIndex int
}

Modal represents a widget that displays a modal dialog.

func NewModal

func NewModal(text string) *Modal

NewModal returns a new Modal with the given text.

func (*Modal) AddButton

func (m *Modal) AddButton(text string, onClick func()) *Button

AddButton adds a button to the modal.

func (*Modal) CenterIn

func (m *Modal) CenterIn(x1, y1, x2, y2, width, height int)

CenterIn centers the modal in the given rectangle.

func (*Modal) Draw

func (m *Modal) Draw(buf *ui.Buffer)

Draw draws the modal to the buffer.

func (*Modal) SetRect

func (m *Modal) SetRect(x1, y1, x2, y2 int)

SetRect sets the rectangle of the modal.

type Paragraph

type Paragraph struct {
	ui.Block
	Text              string
	TextStyle         ui.Style
	WrapText          bool
	VerticalAlignment ui.VerticalAlignment
	TextAlignment     ui.Alignment
	Gradient          ui.Gradient
}

Paragraph represents a widget that displays a paragraph of text.

func NewParagraph

func NewParagraph() *Paragraph

NewParagraph returns a new Paragraph.

func (*Paragraph) Draw

func (p *Paragraph) Draw(buf *ui.Buffer)

Draw draws the paragraph to the buffer.

type PieChart

type PieChart struct {
	ui.Block
	Data           []float64
	Colors         []ui.Color
	LabelFormatter PieChartLabel
	AngleOffset    float64
	InnerRadius    float64
}

PieChart represents a widget that displays a pie chart.

func NewPieChart

func NewPieChart() *PieChart

NewPieChart returns a new PieChart.

func (*PieChart) Draw

func (pc *PieChart) Draw(buf *ui.Buffer)

Draw draws the pie chart to the buffer.

type PieChartLabel

type PieChartLabel func(dataIndex int, currentValue float64) string

PieChartLabel is a function that returns a label for a pie chart slice.

type Plot

type Plot struct {
	ui.Block
	Data            [][]float64
	DataLabels      []string
	MaxVal          float64
	LineColors      []ui.Color
	AxesColor       ui.Color
	ShowAxes        bool
	Fill            bool
	Marker          PlotMarker
	DotMarkerRune   rune
	PlotType        PlotType
	HorizontalScale int
	DrawDirection   DrawDirection
}

Plot represents a widget that displays a plot.

func NewPlot

func NewPlot() *Plot

NewPlot returns a new Plot.

func (*Plot) Draw

func (plt *Plot) Draw(buf *ui.Buffer)

Draw draws the plot to the buffer.

type PlotMarker

type PlotMarker uint

PlotMarker represents the marker type for the plot.

const (
	MarkerBraille PlotMarker = iota
	MarkerDot
)

type PlotType

type PlotType uint

PlotType represents the type of the plot.

const (
	LineChart PlotType = iota
	ScatterPlot
)

type RadarChart

type RadarChart struct {
	ui.Block
	Data       [][]float64
	DataLabels []string
	Labels     []string
	MaxVal     float64
	LineColors []ui.Color
	LabelStyle ui.Style
	DotStyle   ui.Style
}

RadarChart represents a widget that displays a radar chart.

func NewRadarChart

func NewRadarChart() *RadarChart

NewRadarChart returns a new RadarChart.

func (*RadarChart) Draw

func (rc *RadarChart) Draw(buf *ui.Buffer)

Draw draws the radar chart to the buffer.

type Scrollbar

type Scrollbar struct {
	ui.Block
	Orientation ScrollbarOrientation
	Max         int
	Current     int
	PageSize    int
	ThumbStyle  ui.Style
	TrackStyle  ui.Style
	ThumbRune   rune
	TrackRune   rune
	BeginRune   rune
	EndRune     rune
}

Scrollbar represents a widget that displays a scrollbar.

func NewScrollbar

func NewScrollbar() *Scrollbar

NewScrollbar returns a new Scrollbar.

func (*Scrollbar) Draw

func (s *Scrollbar) Draw(buf *ui.Buffer)

Draw draws the scrollbar to the buffer.

type ScrollbarOrientation

type ScrollbarOrientation int

ScrollbarOrientation represents the orientation of the scrollbar.

const (
	ScrollbarVertical ScrollbarOrientation = iota
	ScrollbarHorizontal
)

type Sparkline

type Sparkline struct {
	Data            []float64
	Title           string
	TitleStyle      ui.Style
	LineColor       ui.Color
	BackgroundColor ui.Color
	MaxVal          float64
	MaxHeight       int
}

Sparkline represents a single sparkline.

func NewSparkline

func NewSparkline() *Sparkline

NewSparkline returns a new Sparkline.

type SparklineGroup

type SparklineGroup struct {
	ui.Block
	Sparklines []*Sparkline
}

SparklineGroup represents a group of sparklines.

func NewSparklineGroup

func NewSparklineGroup(sls ...*Sparkline) *SparklineGroup

NewSparklineGroup returns a new SparklineGroup.

func (*SparklineGroup) Draw

func (sg *SparklineGroup) Draw(buf *ui.Buffer)

Draw draws the sparkline group to the buffer.

type Spinner

type Spinner struct {
	ui.Block
	Frames       []string
	Index        int
	Label        string
	LabelOnRight bool
	FormatString string
	TextStyle    ui.Style
}

Spinner represents a widget that displays a spinner.

func NewSpinner

func NewSpinner() *Spinner

NewSpinner returns a new Spinner.

func (*Spinner) Advance

func (s *Spinner) Advance()

Advance advances the spinner to the next frame.

func (*Spinner) Draw

func (s *Spinner) Draw(buf *ui.Buffer)

Draw draws the spinner to the buffer.

type StackedBarChart

type StackedBarChart struct {
	ui.Block
	BarColors    []ui.Color
	LabelStyles  []ui.Style
	NumStyles    []ui.Style
	NumFormatter func(float64) string
	Data         [][]float64
	Labels       []string
	BarWidth     int
	BarGap       int
	MaxVal       float64
}

StackedBarChart represents a widget that displays a stacked bar chart.

func NewStackedBarChart

func NewStackedBarChart() *StackedBarChart

NewStackedBarChart returns a new StackedBarChart.

func (*StackedBarChart) Draw

func (sbc *StackedBarChart) Draw(buf *ui.Buffer)

Draw draws the stacked bar chart to the buffer.

type StepChart

type StepChart struct {
	*Plot
	ShowRightAxis bool
	DataLabels    []string
}

StepChart represents a stepped line chart

func NewStepChart

func NewStepChart() *StepChart

NewStepChart returns a new StepChart initialized with default settings for a solid-line step graph.

func (*StepChart) Draw

func (sc *StepChart) Draw(buf *ui.Buffer)

Draw draws the StepChart to the buffer using box drawing characters for a stepped line.

type TabPane

type TabPane struct {
	ui.Block
	TabNames         []string
	ActiveTabIndex   int
	ActiveTabStyle   ui.Style
	InactiveTabStyle ui.Style

	PadLeft   int
	PadRight  int
	TabGap    int
	Separator string
}

TabPane represents a widget that displays a list of tabs.

func NewTabPane

func NewTabPane(names ...string) *TabPane

NewTabPane returns a new TabPane.

func (*TabPane) Draw

func (tp *TabPane) Draw(buf *ui.Buffer)

Draw draws the tab pane to the buffer.

func (*TabPane) FocusLeft

func (tp *TabPane) FocusLeft()

FocusLeft moves the focus to the left tab.

func (*TabPane) FocusRight

func (tp *TabPane) FocusRight()

FocusRight moves the focus to the right tab.

func (*TabPane) ResolveClick

func (tp *TabPane) ResolveClick(p image.Point) int

ResolveClick returns the index of the tab that was clicked, or -1 if no tab was clicked.

type Table

type Table struct {
	ui.Block
	Rows          [][]string
	ColumnWidths  []int
	TextStyle     ui.Style
	RowSeparator  bool
	TextAlignment ui.Alignment
	RowStyles     map[int]ui.Style
	FillRow       bool
	// TextWrap wraps the text in each cell.
	TextWrap      bool
	ColumnResizer func()

	// Selection and Styling
	SelectedRow      int
	SelectedRowStyle ui.Style
	CursorColor      ui.Color
	ShowCursor       bool
	ShowLocation     bool
	// contains filtered or unexported fields
}

Table represents a widget that displays a table.

func NewTable

func NewTable() *Table

NewTable returns a new Table.

func (*Table) Draw

func (tb *Table) Draw(buf *ui.Buffer)

Draw draws the table to the buffer.

func (*Table) ScrollBottom

func (tb *Table) ScrollBottom()

ScrollBottom scrolls the list to the bottom.

func (*Table) ScrollDown

func (tb *Table) ScrollDown()

ScrollDown scrolls the list down by one row.

func (*Table) ScrollPageDown

func (tb *Table) ScrollPageDown()

ScrollPageDown scrolls the list down by one page.

func (*Table) ScrollPageUp

func (tb *Table) ScrollPageUp()

ScrollPageUp scrolls the list up by one page.

func (*Table) ScrollTop

func (tb *Table) ScrollTop()

ScrollTop scrolls the list to the top.

func (*Table) ScrollUp

func (tb *Table) ScrollUp()

ScrollUp scrolls the list up by one row.

type TextArea

type TextArea struct {
	ui.Block
	Text        string
	TextStyle   ui.Style
	CursorStyle ui.Style
	Cursor      image.Point
	ShowCursor  bool

	sync.Mutex
	// contains filtered or unexported fields
}

TextArea represents a widget that displays a text area.

func NewTextArea

func NewTextArea() *TextArea

NewTextArea returns a new TextArea.

func (*TextArea) DeleteRune

func (ta *TextArea) DeleteRune()

DeleteRune deletes the rune at the cursor position.

func (*TextArea) Draw

func (ta *TextArea) Draw(buf *ui.Buffer)

Draw draws the text area to the buffer.

func (*TextArea) InsertNewline

func (ta *TextArea) InsertNewline()

InsertNewline inserts a newline at the cursor position.

func (*TextArea) InsertRune

func (ta *TextArea) InsertRune(r rune)

InsertRune inserts a rune at the cursor position.

func (*TextArea) MoveCursor

func (ta *TextArea) MoveCursor(dx, dy int)

MoveCursor moves the cursor by the given amount.

type Tree

type Tree struct {
	ui.Block
	TextStyle        ui.Style
	SelectedRowStyle ui.Style
	WrapText         bool
	SelectedRow      int
	// contains filtered or unexported fields
}

Tree represents a widget that displays a tree of items.

func NewTree

func NewTree() *Tree

NewTree returns a new Tree.

func (*Tree) Collapse

func (t *Tree) Collapse()

Collapse collapses the selected node.

func (*Tree) CollapseAll

func (t *Tree) CollapseAll()

CollapseAll collapses all nodes in the tree.

func (*Tree) Draw

func (t *Tree) Draw(buf *ui.Buffer)

Draw draws the tree to the buffer.

func (*Tree) Expand

func (t *Tree) Expand()

Expand expands the selected node.

func (*Tree) ExpandAll

func (t *Tree) ExpandAll()

ExpandAll expands all nodes in the tree.

func (*Tree) ScrollAmount

func (t *Tree) ScrollAmount(amount int)

ScrollAmount scrolls the tree by the given amount.

func (*Tree) ScrollBottom

func (t *Tree) ScrollBottom()

ScrollBottom scrolls the tree to the bottom.

func (*Tree) ScrollDown

func (t *Tree) ScrollDown()

ScrollDown scrolls the tree down by one row.

func (*Tree) ScrollHalfPageDown

func (t *Tree) ScrollHalfPageDown()

ScrollHalfPageDown scrolls the tree down by half a page.

func (*Tree) ScrollHalfPageUp

func (t *Tree) ScrollHalfPageUp()

ScrollHalfPageUp scrolls the tree up by half a page.

func (*Tree) ScrollPageDown

func (t *Tree) ScrollPageDown()

func (*Tree) ScrollPageUp

func (t *Tree) ScrollPageUp()

func (*Tree) ScrollTop

func (t *Tree) ScrollTop()

ScrollTop scrolls the tree to the top.

func (*Tree) ScrollUp

func (t *Tree) ScrollUp()

ScrollUp scrolls the tree up by one row.

func (*Tree) SelectedNode

func (t *Tree) SelectedNode() *TreeNode

SelectedNode returns the currently selected node.

func (*Tree) SetNodes

func (t *Tree) SetNodes(nodes []*TreeNode)

SetNodes sets the nodes of the tree.

func (*Tree) ToggleExpand

func (t *Tree) ToggleExpand()

ToggleExpand toggles the expansion state of the selected node.

func (*Tree) Walk

func (t *Tree) Walk(fn TreeWalkFn)

Walk walks the tree, calling fn for each node.

type TreeMap

type TreeMap struct {
	ui.Block
	Root      *TreeMapNode
	TextColor ui.Color
}

TreeMap represents a widget that displays a tree map.

func NewTreeMap

func NewTreeMap() *TreeMap

NewTreeMap returns a new TreeMap.

func (*TreeMap) Draw

func (tm *TreeMap) Draw(buf *ui.Buffer)

Draw draws the tree map to the buffer.

type TreeMapNode

type TreeMapNode struct {
	Value      float64
	Label      string
	Children   []*TreeMapNode
	Style      ui.Style
	X, Y, W, H int
}

TreeMapNode represents a node in the tree map.

type TreeNode

type TreeNode struct {
	Value    fmt.Stringer
	Expanded bool
	Nodes    []*TreeNode
	// contains filtered or unexported fields
}

TreeNode represents a node in the tree.

type TreeWalkFn

type TreeWalkFn func(*TreeNode) bool

TreeWalkFn is a function that is called for each node in the tree during a walk.

Jump to

Keyboard shortcuts

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