widgets

package
v0.0.0-...-a33e0d3 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BarChart

type BarChart struct {
	ui.Block
	BarColors    []ui.Color
	LabelStyles  []ui.Style
	NumStyles    []ui.Style // only Fg and Modifier are used
	NumFormatter func(float64) string
	Data         []float64
	Labels       []string
	BarWidth     int
	BarGap       int
	MaxVal       float64
}

func NewBarChart

func NewBarChart() *BarChart

func (*BarChart) Draw

func (bc *BarChart) Draw(buf *ui.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 DrawDirection

type DrawDirection uint
const (
	DrawLeft DrawDirection = iota
	DrawRight
)

type EchoMode

type EchoMode int
const (
	EchoNormal EchoMode = iota
	EchoPassword
)

type FunnelChart

type FunnelChart struct {
	ui.Block
	Data   []float64
	Labels []string
	Colors []ui.Color
	// If false, all trapezoids have height proportional to value
	// If true, uniform height
	UniformHeight bool
}

func NewFunnelChart

func NewFunnelChart() *FunnelChart

func (*FunnelChart) Draw

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

type Gauge

type Gauge struct {
	ui.Block
	Percent    int
	BarColor   ui.Color
	Label      string
	LabelStyle ui.Style
}

func NewGauge

func NewGauge() *Gauge

func (*Gauge) Draw

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

type Heatmap

type Heatmap struct {
	ui.Block
	Data      [][]float64
	CellWidth int
	CellGap   int
	XLabels   []string
	YLabels   []string
	Colors    []ui.Color // Gradient colors from low to high
	TextColor ui.Style
}

func NewHeatmap

func NewHeatmap() *Heatmap

func (*Heatmap) Draw

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

type Image

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

func NewImage

func NewImage(img image.Image) *Image

func (*Image) Draw

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

type Input

type Input struct {
	ui.Block
	Text        string
	TextStyle   ui.Style
	CursorStyle ui.Style
	Placeholder string
	EchoMode    EchoMode
	Cursor      int // cursor position (index in []rune)

	sync.Mutex
	// contains filtered or unexported fields
}

func NewInput

func NewInput() *Input

func (*Input) Backspace

func (i *Input) Backspace()

func (*Input) Draw

func (i *Input) Draw(buf *ui.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
}

func NewLineGauge

func NewLineGauge() *LineGauge

func (*LineGauge) Draw

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

type List

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

func NewList

func NewList() *List

func (*List) Draw

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

func (*List) ScrollAmount

func (l *List) ScrollAmount(amount int)

ScrollAmount scrolls by amount given. If amount is < 0, then scroll up. There is no need to set l.topRow, as this will be set automatically when drawn, since if the selected item is off screen then the topRow variable will change accordingly.

func (*List) ScrollBottom

func (l *List) ScrollBottom()

func (*List) ScrollDown

func (l *List) ScrollDown()

func (*List) ScrollHalfPageDown

func (l *List) ScrollHalfPageDown()

func (*List) ScrollHalfPageUp

func (l *List) ScrollHalfPageUp()

func (*List) ScrollPageDown

func (l *List) ScrollPageDown()

func (*List) ScrollPageUp

func (l *List) ScrollPageUp()

func (*List) ScrollTop

func (l *List) ScrollTop()

func (*List) ScrollUp

func (l *List) ScrollUp()
type Logo struct {
	ui.Block
}

Logo widget renders a hardcoded logo (Gotui)

func NewLogo() *Logo

func (*Logo) Draw

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

type Paragraph

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

func NewParagraph

func NewParagraph() *Paragraph

func (*Paragraph) Draw

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

type PieChart

type PieChart struct {
	ui.Block
	Data           []float64     // list of data items
	Colors         []ui.Color    // colors to by cycled through
	LabelFormatter PieChartLabel // callback function for labels
	AngleOffset    float64       // which angle to start drawing at? (see piechartOffsetUp)
	InnerRadius    float64       // 0.0 to 1.0, defines the size of the hole
}

func NewPieChart

func NewPieChart() *PieChart

NewPieChart Creates a new pie chart with reasonable defaults and no labels.

func (*PieChart) Draw

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

type PieChartLabel

type PieChartLabel func(dataIndex int, currentValue float64) string

PieChartLabel callback

type Plot

type Plot struct {
	ui.Block

	Data       [][]float64
	DataLabels []string
	MaxVal     float64

	LineColors []ui.Color
	AxesColor  ui.Color // TODO
	ShowAxes   bool
	Fill       bool // Fills the area under the line (like nvtop)

	Marker          PlotMarker
	DotMarkerRune   rune
	PlotType        PlotType
	HorizontalScale int
	DrawDirection   DrawDirection // TODO
}

Plot has two modes: line(default) and scatter. Plot also has two marker types: braille(default) and dot. A single braille character is a 2x4 grid of dots, so using braille gives 2x X resolution and 4x Y resolution over dot mode.

func NewPlot

func NewPlot() *Plot

func (*Plot) Draw

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

type PlotMarker

type PlotMarker uint
const (
	MarkerBraille PlotMarker = iota
	MarkerDot
)

type PlotType

type PlotType uint
const (
	LineChart PlotType = iota
	ScatterPlot
)

type RadarChart

type RadarChart struct {
	ui.Block
	Data       [][]float64
	DataLabels []string // Names for each data slice
	Labels     []string // Names for axes
	MaxVal     float64
	LineColors []ui.Color
	LabelStyle ui.Style
	DotStyle   ui.Style
}

func NewRadarChart

func NewRadarChart() *RadarChart

func (*RadarChart) Draw

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

type Sparkline

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

Sparkline is like: ▅▆▂▂▅▇▂▂▃▆▆▆▅▃. The data points should be non-negative integers.

func NewSparkline

func NewSparkline() *Sparkline

NewSparkline returns a unrenderable single sparkline that needs to be added to a SparklineGroup

type SparklineGroup

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

SparklineGroup is a renderable widget which groups together the given sparklines.

func NewSparklineGroup

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

func (*SparklineGroup) Draw

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

type StackedBarChart

type StackedBarChart struct {
	ui.Block
	BarColors    []ui.Color
	LabelStyles  []ui.Style
	NumStyles    []ui.Style // only Fg and Modifier are used
	NumFormatter func(float64) string
	Data         [][]float64
	Labels       []string
	BarWidth     int
	BarGap       int
	MaxVal       float64
}

func NewStackedBarChart

func NewStackedBarChart() *StackedBarChart

func (*StackedBarChart) Draw

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

type TabPane

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

TabPane is a renderable widget which can be used to conditionally render certain tabs/views. TabPane shows a list of Tab names. The currently selected tab can be found through the `ActiveTabIndex` field.

func NewTabPane

func NewTabPane(names ...string) *TabPane

func (*TabPane) Draw

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

func (*TabPane) FocusLeft

func (tp *TabPane) FocusLeft()

func (*TabPane) FocusRight

func (tp *TabPane) FocusRight()

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

	// ColumnResizer is called on each Draw. Can be used for custom column sizing.
	ColumnResizer func()
}

Table is like: ┌ Awesome Table ───────────────────────────────────────────────┐ │ Col0 | Col1 | Col2 | Col3 | Col4 | Col5 | Col6 | │──────────────────────────────────────────────────────────────│ │ Some Item #1 | AAA | 123 | CCCCC | EEEEE | GGGGG | IIIII | │──────────────────────────────────────────────────────────────│ │ Some Item #2 | BBB | 456 | DDDDD | FFFFF | HHHHH | JJJJJ | └──────────────────────────────────────────────────────────────┘

func NewTable

func NewTable() *Table

func (*Table) Draw

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

type TextArea

type TextArea struct {
	ui.Block
	Text        string
	TextStyle   ui.Style
	CursorStyle ui.Style
	Cursor      image.Point // Cursor position in the text (Column, Line) 0-indexed
	ShowCursor  bool

	sync.Mutex
	// contains filtered or unexported fields
}

func NewTextArea

func NewTextArea() *TextArea

func (*TextArea) DeleteRune

func (ta *TextArea) DeleteRune()

DeleteRune deletes the rune before the cursor (backspace)

func (*TextArea) Draw

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

func (*TextArea) InsertNewline

func (ta *TextArea) InsertNewline()

InsertNewline inserts a newline at the cursor

func (*TextArea) InsertRune

func (ta *TextArea) InsertRune(r rune)

InsertRune inserts a rune at the current cursor position

func (*TextArea) MoveCursor

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

MoveCursor moves the cursor safely

type Tree

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

Tree is a tree widget.

func NewTree

func NewTree() *Tree

NewTree creates a new Tree widget.

func (*Tree) Collapse

func (t *Tree) Collapse()

func (*Tree) CollapseAll

func (t *Tree) CollapseAll()

func (*Tree) Draw

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

func (*Tree) Expand

func (t *Tree) Expand()

func (*Tree) ExpandAll

func (t *Tree) ExpandAll()

func (*Tree) ScrollAmount

func (t *Tree) ScrollAmount(amount int)

ScrollAmount scrolls by amount given. If amount is < 0, then scroll up. There is no need to set t.topRow, as this will be set automatically when drawn, since if the selected item is off screen then the topRow variable will change accordingly.

func (*Tree) ScrollBottom

func (t *Tree) ScrollBottom()

func (*Tree) ScrollDown

func (t *Tree) ScrollDown()

func (*Tree) ScrollHalfPageDown

func (t *Tree) ScrollHalfPageDown()

func (*Tree) ScrollHalfPageUp

func (t *Tree) ScrollHalfPageUp()

func (*Tree) ScrollPageDown

func (t *Tree) ScrollPageDown()

func (*Tree) ScrollPageUp

func (t *Tree) ScrollPageUp()

func (*Tree) ScrollTop

func (t *Tree) ScrollTop()

func (*Tree) ScrollUp

func (t *Tree) ScrollUp()

func (*Tree) SelectedNode

func (t *Tree) SelectedNode() *TreeNode

func (*Tree) SetNodes

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

func (*Tree) ToggleExpand

func (t *Tree) ToggleExpand()

func (*Tree) Walk

func (t *Tree) Walk(fn TreeWalkFn)

type TreeMap

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

func NewTreeMap

func NewTreeMap() *TreeMap

func (*TreeMap) Draw

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

type TreeMapNode

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

type TreeNode

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

TreeNode is a tree node.

type TreeWalkFn

type TreeWalkFn func(*TreeNode) bool

TreeWalkFn is a function used for walking a Tree. To interrupt the walking process function should return false.

Jump to

Keyboard shortcuts

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