table

package
v0.0.0-...-2b1f001 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ColumnSpec

type ColumnSpec[E any] interface {
	Title() string
	Width() int
	SetWidth(int)
	GetValue(E) string
}

type KeyMap

type KeyMap struct {
	LineUp       key.Binding
	LineDown     key.Binding
	LineLeft     key.Binding
	LineRight    key.Binding
	PageUp       key.Binding
	PageDown     key.Binding
	HalfPageUp   key.Binding
	HalfPageDown key.Binding
	GotoTop      key.Binding
	GotoBottom   key.Binding
	ShrinkColumn key.Binding
	GrowColumn   key.Binding
}

KeyMap defines keybindings. It satisfies to the help.KeyMap interface, which is used to render the menu menu.

func DefaultKeyMap

func DefaultKeyMap() KeyMap

DefaultKeyMap returns a default set of keybindings.

type Model

type Model[E any] struct {
	KeyMap KeyMap
	// contains filtered or unexported fields
}

Model[E] defines a state for the table widget.

func New

func New[E any](opts ...Option[E]) Model[E]

New creates a new model for the table widget.

func (*Model[E]) Blur

func (m *Model[E]) Blur()

Blur blurs the table, preventing selection or movement.

func (Model[E]) Cursor

func (m Model[E]) Cursor() int

Cursor returns the index of the selected row.

func (*Model[E]) Focus

func (m *Model[E]) Focus()

Focus focusses the table, allowing the user to move around the rows and interact.

func (Model[E]) Focused

func (m Model[E]) Focused() bool

Focused returns the focus state of the table.

func (*Model[E]) GotoBottom

func (m *Model[E]) GotoBottom()

GotoBottom moves the selection to the last row.

func (*Model[E]) GotoTop

func (m *Model[E]) GotoTop()

GotoTop moves the selection to the first row.

func (*Model[E]) GrowColumn

func (m *Model[E]) GrowColumn()

GrowColumn grows the current column by one character.

func (Model[E]) Height

func (m Model[E]) Height() int

Height returns the viewport height of the table.

func (*Model[E]) MoveDown

func (m *Model[E]) MoveDown(n int)

MoveDown moves the selection down by any number of row. It can not go below the last row.

func (*Model[E]) MoveLeft

func (m *Model[E]) MoveLeft(n int)

MoveLeft moves the selection left by any number of columns. It can not go left of the first column.

func (*Model[E]) MoveRight

func (m *Model[E]) MoveRight(n int)

MoveRight moves the selection right by any number of columns. It can not go right of the last column.

func (*Model[E]) MoveUp

func (m *Model[E]) MoveUp(n int)

MoveUp moves the selection up by any number of row. It can not go above the first row.

func (Model[E]) SelectedRow

func (m Model[E]) SelectedRow() E

SelectedRow returns the selected row. You can cast it to your own implementation.

func (*Model[E]) SetColumns

func (m *Model[E]) SetColumns(cols []ColumnSpec[E])

SetColumns sets the table columns (headers).

func (*Model[E]) SetCursor

func (m *Model[E]) SetCursor(n int)

SetCursor sets the cursor position in the table.

func (*Model[E]) SetHeight

func (m *Model[E]) SetHeight(h int)

SetHeight sets the height of the viewport of the table.

func (*Model[E]) SetRows

func (m *Model[E]) SetRows(r []E)

SetRows set a new rows state.

func (*Model[E]) SetStyles

func (m *Model[E]) SetStyles(s Styles)

SetStyles sets the table styles.

func (*Model[E]) SetWidth

func (m *Model[E]) SetWidth(w int)

SetWidth sets the width of the viewport of the table.

func (*Model[E]) ShrinkColumn

func (m *Model[E]) ShrinkColumn()

ShrinkColumn shrinks the current column by one character.

func (Model[E]) Update

func (m Model[E]) Update(msg tea.Msg) (Model[E], tea.Cmd)

Update is the Bubble Tea update loop.

func (*Model[E]) UpdateViewport

func (m *Model[E]) UpdateViewport()

UpdateViewport updates the list content based on the previously defined columns and rows.

func (Model[E]) View

func (m Model[E]) View() string

View renders the component.

func (Model[E]) Width

func (m Model[E]) Width() int

Width returns the viewport width of the table.

type Option

type Option[E any] func(*Model[E])

Option[E] is used to set options in New. For example:

table := New(WithColumns([]Column{{Title: "ID", Width: 10}}))

func WithColumns

func WithColumns[E any](cols []ColumnSpec[E]) Option[E]

WithColumns sets the table columns (headers).

func WithFocused

func WithFocused[E any](f bool) Option[E]

WithFocused sets the focus state of the table.

func WithHeight

func WithHeight[E any](h int) Option[E]

WithHeight sets the height of the table.

func WithKeyMap

func WithKeyMap[E any](km KeyMap) Option[E]

WithKeyMap sets the key map.

func WithRows

func WithRows[E any](rows []E) Option[E]

WithRows sets the table rows (data).

func WithStyles

func WithStyles[E any](s Styles) Option[E]

WithStyles sets the table styles.

func WithWidth

func WithWidth[E any](w int) Option[E]

WithWidth sets the width of the table.

type Styles

type Styles struct {
	Header   lipgloss.Style
	Cell     lipgloss.Style
	Selected lipgloss.Style
}

Styles contains style definitions for this list component. By default, these values are generated by DefaultStyles.

func DefaultStyles

func DefaultStyles() Styles

DefaultStyles returns a set of default style definitions for this table.

Jump to

Keyboard shortcuts

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