widgets

package
v0.0.0-...-1e2fe69 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DrawBorder

func DrawBorder(screen tcell.Screen, x, y, width, height int, style tcell.Style)

DrawBorder draws a border around the widget

Types

type Alignment

type Alignment int

Alignment represents text alignment in table cells

const (
	// AlignLeft aligns text to the left of the cell
	AlignLeft Alignment = iota
	// AlignCenter centers text in the cell
	AlignCenter
	// AlignRight aligns text to the right of the cell
	AlignRight
)

Text alignment constants

type BaseWidget

type BaseWidget struct {
	X, Y          int
	Width, Height int
	Style         tcell.Style
	Screen        tcell.Screen
}

BaseWidget provides common functionality for all widgets

func NewBaseWidget

func NewBaseWidget(screen tcell.Screen, x, y, width, height int) BaseWidget

NewBaseWidget creates a new base widget

func (*BaseWidget) Clear

func (w *BaseWidget) Clear()

Clear removes the widget from the screen

func (*BaseWidget) GetBounds

func (w *BaseWidget) GetBounds() (x, y, width, height int)

GetBounds returns the widget's position and size

func (*BaseWidget) SetBounds

func (w *BaseWidget) SetBounds(x, y, width, height int)

SetBounds sets the widget's position and size

func (*BaseWidget) SetStyle

func (w *BaseWidget) SetStyle(style tcell.Style)

SetStyle sets the widget's style

type Column

type Column struct {
	Title     string
	Width     int
	MinWidth  int
	MaxWidth  int
	Alignment Alignment // Left, Right, Center
}

Column represents a table column

type Graph

type Graph struct {
	X, Y          int
	Width, Height int
	Style         tcell.Style
	Screen        tcell.Screen
	GraphStyle    GraphStyle
	Data          []float64
	MaxValue      float64
	MinValue      float64
	Inverted      bool
}

Graph represents a percentage graph widget

func NewGraph

func NewGraph(screen tcell.Screen, x, y, width, height int) *Graph

NewGraph creates a new graph widget

func (*Graph) Clear

func (g *Graph) Clear()

Clear clears the graph data

func (*Graph) Draw

func (g *Graph) Draw()

Draw draws the graph on the screen

func (*Graph) SetData

func (g *Graph) SetData(data []float64)

SetData sets the data points for the graph

func (*Graph) SetGraphStyle

func (g *Graph) SetGraphStyle(style GraphStyle)

SetGraphStyle sets the style of graph to be drawn

func (*Graph) SetInverted

func (g *Graph) SetInverted(inverted bool)

SetInverted sets whether to invert the graph

func (*Graph) SetRange

func (g *Graph) SetRange(min, max float64)

SetRange sets the value range for the graph

func (*Graph) SetStyle

func (g *Graph) SetStyle(style tcell.Style)

SetStyle sets the style for the graph

type GraphStyle

type GraphStyle int

GraphStyle represents the style of graph to be drawn

const (
	// GraphStyleBraille uses Braille characters for drawing the graph
	GraphStyleBraille GraphStyle = iota
	// GraphStyleBlock uses block characters for drawing the graph
	GraphStyleBlock
	// GraphStyleTTY uses TTY characters for drawing the graph
	GraphStyleTTY
)

Graph styles

type InfoField

type InfoField struct {
	Label      string
	Value      string
	LabelStyle tcell.Style
	ValueStyle tcell.Style
}

InfoField represents a field in the info panel

type InfoPanel

type InfoPanel struct {
	X, Y          int
	Width, Height int
	Screen        tcell.Screen
	Style         tcell.Style
	TitleStyle    tcell.Style

	Title        string
	Fields       []InfoField
	ShowBorder   bool
	ScrollOffset int
	LabelWidth   int
}

InfoPanel represents an info panel widget

func NewInfoPanel

func NewInfoPanel(screen tcell.Screen, x, y, width, height int) *InfoPanel

NewInfoPanel creates a new info panel widget

func (*InfoPanel) AddField

func (p *InfoPanel) AddField(label, value string)

AddField adds a field to the panel

func (*InfoPanel) ClearFields

func (p *InfoPanel) ClearFields()

ClearFields clears all fields

func (*InfoPanel) Draw

func (p *InfoPanel) Draw()

Draw draws the info panel

func (*InfoPanel) GetHeight

func (p *InfoPanel) GetHeight() int

GetHeight returns the total height of the panel

func (*InfoPanel) GetWidth

func (p *InfoPanel) GetWidth() int

GetWidth returns the total width of the panel

func (*InfoPanel) HandleEvent

func (p *InfoPanel) HandleEvent(ev *tcell.EventKey) bool

HandleEvent handles keyboard events for scrolling

func (*InfoPanel) SetFields

func (p *InfoPanel) SetFields(fields []InfoField)

SetFields sets the info fields

func (*InfoPanel) SetLabelWidth

func (p *InfoPanel) SetLabelWidth(width int)

SetLabelWidth sets the width of the label column

func (*InfoPanel) SetShowBorder

func (p *InfoPanel) SetShowBorder(show bool)

SetShowBorder sets whether to show the border

func (*InfoPanel) SetStyle

func (p *InfoPanel) SetStyle(style tcell.Style)

SetStyle sets the default style for the panel

func (*InfoPanel) SetTitle

func (p *InfoPanel) SetTitle(title string)

SetTitle sets the panel title

func (*InfoPanel) SetTitleStyle

func (p *InfoPanel) SetTitleStyle(style tcell.Style)

SetTitleStyle sets the style for the title

func (*InfoPanel) UpdateField

func (p *InfoPanel) UpdateField(label, value string)

UpdateField updates the value of a field with the given label

type Meter

type Meter struct {
	X, Y    int
	Width   int
	Style   tcell.Style
	Screen  tcell.Screen
	Value   float64
	ShowPct bool
	Label   string

	// New fields for block style and gradient
	BlockStyle   bool
	BlockSpacing int
	StartColor   tcell.Color
	EndColor     tcell.Color
	UseGradient  bool
}

Meter represents a percentage meter widget

func NewMeter

func NewMeter(screen tcell.Screen, x, y, width int) *Meter

NewMeter creates a new meter widget

func (*Meter) Draw

func (m *Meter) Draw()

Draw draws the meter on the screen

func (*Meter) SetBlockSpacing

func (m *Meter) SetBlockSpacing(spacing int)

SetBlockSpacing sets the spacing between blocks

func (*Meter) SetBlockStyle

func (m *Meter) SetBlockStyle(enabled bool)

SetBlockStyle sets whether to use block style display

func (*Meter) SetGradient

func (m *Meter) SetGradient(start, end tcell.Color)

SetGradient sets the start and end colors for gradient

func (*Meter) SetLabel

func (m *Meter) SetLabel(label string)

SetLabel sets the label for the meter

func (*Meter) SetShowPercentage

func (m *Meter) SetShowPercentage(show bool)

SetShowPercentage sets whether to show the percentage value

func (*Meter) SetStyle

func (m *Meter) SetStyle(style tcell.Style)

SetStyle sets the style for the meter

func (*Meter) SetValue

func (m *Meter) SetValue(value float64)

SetValue sets the current value of the meter (0-1)

type MeterItem

type MeterItem struct {
	Label          string
	Value          float64
	MaxValue       float64
	Style          tcell.Style
	GradientColors []tcell.Color
	Height         int
}

MeterItem represents a single meter in the multi meter widget

type MultiMeter

type MultiMeter struct {
	X, Y          int
	Width, Height int
	Screen        tcell.Screen
	Style         tcell.Style
	LabelStyle    tcell.Style

	Items       []MeterItem
	ShowLabels  bool
	ShowValues  bool
	ShowBorder  bool
	Orientation Orientation
	LabelWidth  int
	MeterHeight int
	Spacing     int
}

MultiMeter represents a multi meter widget

func NewMultiMeter

func NewMultiMeter(screen tcell.Screen, x, y, width, height int) *MultiMeter

NewMultiMeter creates a new multi meter widget

func (*MultiMeter) AddItem

func (m *MultiMeter) AddItem(item MeterItem)

AddItem adds a meter item to the multi meter

func (*MultiMeter) ClearItems

func (m *MultiMeter) ClearItems()

ClearItems clears all meter items

func (*MultiMeter) Draw

func (m *MultiMeter) Draw()

Draw draws the multi meter

func (*MultiMeter) GetHeight

func (m *MultiMeter) GetHeight() int

GetHeight returns the total height of the widget

func (*MultiMeter) GetWidth

func (m *MultiMeter) GetWidth() int

GetWidth returns the total width of the widget

func (*MultiMeter) SetItems

func (m *MultiMeter) SetItems(items []MeterItem)

SetItems sets the meter items

func (*MultiMeter) SetLabelStyle

func (m *MultiMeter) SetLabelStyle(style tcell.Style)

SetLabelStyle sets the style for labels

func (*MultiMeter) SetLabelWidth

func (m *MultiMeter) SetLabelWidth(width int)

SetLabelWidth sets the width of labels

func (*MultiMeter) SetMeterHeight

func (m *MultiMeter) SetMeterHeight(height int)

SetMeterHeight sets the height of each meter

func (*MultiMeter) SetOrientation

func (m *MultiMeter) SetOrientation(orientation Orientation)

SetOrientation sets the orientation of the meters

func (*MultiMeter) SetShowBorder

func (m *MultiMeter) SetShowBorder(show bool)

SetShowBorder sets whether to show the border

func (*MultiMeter) SetShowLabels

func (m *MultiMeter) SetShowLabels(show bool)

SetShowLabels sets whether to show labels

func (*MultiMeter) SetShowValues

func (m *MultiMeter) SetShowValues(show bool)

SetShowValues sets whether to show values

func (*MultiMeter) SetSpacing

func (m *MultiMeter) SetSpacing(spacing int)

SetSpacing sets the spacing between meters

func (*MultiMeter) SetStyle

func (m *MultiMeter) SetStyle(style tcell.Style)

SetStyle sets the default style for the widget

func (*MultiMeter) UpdateMeter

func (m *MultiMeter) UpdateMeter(label string, value float64)

UpdateMeter updates the value of a meter with the given label

type Orientation

type Orientation int

Orientation represents the orientation of the multi meter

const (
	// Horizontal orientation for the multi meter
	Horizontal Orientation = iota
	// Vertical orientation for the multi meter
	Vertical
)

Meter orientations

type StatusBar

type StatusBar struct {
	X, Y          int
	Width, Height int
	Screen        tcell.Screen
	Style         tcell.Style

	Items     []StatusItem
	Separator string
	Padding   int
}

StatusBar represents a status bar widget

func NewStatusBar

func NewStatusBar(screen tcell.Screen, x, y, width int) *StatusBar

NewStatusBar creates a new status bar widget

func (*StatusBar) AddItem

func (s *StatusBar) AddItem(item StatusItem)

AddItem adds an item to the status bar

func (*StatusBar) ClearItems

func (s *StatusBar) ClearItems()

ClearItems clears all items from the status bar

func (*StatusBar) Draw

func (s *StatusBar) Draw()

Draw draws the status bar

func (*StatusBar) GetHeight

func (s *StatusBar) GetHeight() int

GetHeight returns the height of the status bar (always 1)

func (*StatusBar) GetWidth

func (s *StatusBar) GetWidth() int

GetWidth returns the total width of all items

func (*StatusBar) SetItems

func (s *StatusBar) SetItems(items []StatusItem)

SetItems sets the status bar items

func (*StatusBar) SetPadding

func (s *StatusBar) SetPadding(padding int)

SetPadding sets the padding between items

func (*StatusBar) SetSeparator

func (s *StatusBar) SetSeparator(sep string)

SetSeparator sets the separator between status items

func (*StatusBar) SetStyle

func (s *StatusBar) SetStyle(style tcell.Style)

SetStyle sets the default style for the status bar

func (*StatusBar) UpdateItem

func (s *StatusBar) UpdateItem(index int, text string, style ...tcell.Style)

UpdateItem updates an item at the specified index

type StatusItem

type StatusItem struct {
	Text      string
	Style     tcell.Style
	MinWidth  int
	MaxWidth  int
	Alignment Alignment
}

StatusItem represents a single item in the status bar

type Table

type Table struct {
	X, Y          int
	Width, Height int
	Screen        tcell.Screen
	Style         tcell.Style
	HeaderStyle   tcell.Style
	SelectedStyle tcell.Style

	Columns     []Column
	Rows        [][]string
	SelectedRow int

	ShowHeader    bool
	ShowBorder    bool
	Sortable      bool
	SortColumn    int
	SortAscending bool
	HighlightRow  bool
	ScrollOffset  int
	VisibleRows   int
}

Table represents a table widget

func NewTable

func NewTable(screen tcell.Screen, x, y, width, height int) *Table

NewTable creates a new table widget

func (*Table) AddRow

func (t *Table) AddRow(row []string)

AddRow adds a row to the table

func (*Table) ClearRows

func (t *Table) ClearRows()

ClearRows clears all rows from the table

func (*Table) Draw

func (t *Table) Draw()

Draw draws the table on the screen

func (*Table) GetSelectedRow

func (t *Table) GetSelectedRow() ([]string, int)

GetSelectedRow returns the currently selected row

func (*Table) HandleEvent

func (t *Table) HandleEvent(ev *tcell.EventKey) bool

HandleEvent handles keyboard events

func (*Table) SetColumns

func (t *Table) SetColumns(columns []Column)

SetColumns sets the table columns

func (*Table) SetHighlightRow

func (t *Table) SetHighlightRow(highlight bool)

SetHighlightRow sets whether to highlight the selected row

func (*Table) SetRows

func (t *Table) SetRows(rows [][]string)

SetRows sets the table rows

func (*Table) SetShowBorder

func (t *Table) SetShowBorder(show bool)

SetShowBorder sets whether to show the border

func (*Table) SetShowHeader

func (t *Table) SetShowHeader(show bool)

SetShowHeader sets whether to show the header

func (*Table) SetSortColumn

func (t *Table) SetSortColumn(col int)

SetSortColumn sets the column to sort by

func (*Table) SetSortable

func (t *Table) SetSortable(sortable bool)

SetSortable sets whether the table is sortable

type TreeNode

type TreeNode struct {
	Text     string
	Children []*TreeNode
	Parent   *TreeNode
	Expanded bool
	Data     interface{} // Optional data associated with the node
	Style    tcell.Style
}

TreeNode represents a node in the tree

type TreeView

type TreeView struct {
	X, Y          int
	Width, Height int
	Screen        tcell.Screen
	Style         tcell.Style
	SelectedStyle tcell.Style

	Root         *TreeNode
	Selected     *TreeNode
	ScrollOffset int
	VisibleNodes int

	ShowLines bool
	Indent    int
}

TreeView represents a tree view widget

func NewTreeView

func NewTreeView(screen tcell.Screen, x, y, width, height int) *TreeView

NewTreeView creates a new tree view widget

func (*TreeView) AddNode

func (t *TreeView) AddNode(parent *TreeNode, text string) *TreeNode

AddNode adds a child node to the specified parent If parent is nil, the node will be set as the root node

func (*TreeView) CollapseAll

func (t *TreeView) CollapseAll()

CollapseAll collapses all nodes in the tree

func (*TreeView) CollapseSelected

func (t *TreeView) CollapseSelected() bool

CollapseSelected collapses the currently selected node

func (*TreeView) Draw

func (t *TreeView) Draw()

Draw draws the tree view

func (*TreeView) EnsureVisible

func (t *TreeView) EnsureVisible()

EnsureVisible ensures the selected node is visible in the view

func (*TreeView) ExpandAll

func (t *TreeView) ExpandAll()

ExpandAll expands all nodes in the tree

func (*TreeView) ExpandSelected

func (t *TreeView) ExpandSelected() bool

ExpandSelected expands the currently selected node

func (*TreeView) FindAndSelect

func (t *TreeView) FindAndSelect(text string) bool

FindAndSelect searches for a node with the given text and selects it if found

func (*TreeView) FindNode

func (t *TreeView) FindNode(text string) *TreeNode

FindNode searches for a node with the given text

func (*TreeView) GetSelected

func (t *TreeView) GetSelected() *TreeNode

GetSelected returns the currently selected node

func (*TreeView) HandleKeyEvent

func (t *TreeView) HandleKeyEvent(event *tcell.EventKey) bool

HandleKeyEvent handles keyboard events for the tree view

func (*TreeView) RemoveNode

func (t *TreeView) RemoveNode(node *TreeNode)

RemoveNode removes a node and its children from the tree

func (*TreeView) ScrollBy

func (t *TreeView) ScrollBy(delta int)

ScrollBy scrolls the view by the specified amount

func (*TreeView) ScrollTo

func (t *TreeView) ScrollTo(offset int)

ScrollTo scrolls the view to the specified offset

func (*TreeView) SelectNext

func (t *TreeView) SelectNext() bool

SelectNext selects the next visible node in the tree

func (*TreeView) SelectPrevious

func (t *TreeView) SelectPrevious() bool

SelectPrevious selects the previous visible node

func (*TreeView) SetIndent

func (t *TreeView) SetIndent(indent int)

SetIndent sets the indentation level

func (*TreeView) SetNodeStyle

func (t *TreeView) SetNodeStyle(node *TreeNode, style tcell.Style)

SetNodeStyle sets the style for a specific node

func (*TreeView) SetRoot

func (t *TreeView) SetRoot(root *TreeNode)

SetRoot sets the root node of the tree

func (*TreeView) SetShowLines

func (t *TreeView) SetShowLines(show bool)

SetShowLines sets whether to show tree lines

func (*TreeView) SetStyle

func (t *TreeView) SetStyle(style TreeViewStyle)

SetStyle sets the style configuration for the tree view

func (*TreeView) ToggleSelected

func (t *TreeView) ToggleSelected() bool

ToggleSelected toggles the expanded state of the currently selected node

type TreeViewStyle

type TreeViewStyle struct {
	NodeStyle     tcell.Style // Style for normal nodes
	SelectedStyle tcell.Style // Style for selected node
	LineStyle     tcell.Style // Style for tree lines
	ExpandedIcon  rune        // Icon for expanded nodes
	CollapsedIcon rune        // Icon for collapsed nodes
}

TreeViewStyle represents the style configuration for the tree view

func DefaultTreeViewStyle

func DefaultTreeViewStyle() TreeViewStyle

DefaultTreeViewStyle returns the default style configuration

type Widget

type Widget interface {
	// Draw renders the widget on the screen
	Draw()

	// Clear removes the widget from the screen
	Clear()

	// GetBounds returns the widget's position and size
	GetBounds() (x, y, width, height int)

	// SetBounds sets the widget's position and size
	SetBounds(x, y, width, height int)

	// SetStyle sets the widget's style
	SetStyle(style tcell.Style)
}

Widget defines the interface that all widgets must implement

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳