table

package
v0.0.43 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Column

type Column[T any] struct {
	Title    string
	Width    int
	Renderer func(Column[T], T, bool) string
}

Column defines the table structure.

type Model

type Model[T any] struct {
	KeyMap teaModel.KeyMap
	Help   help.Model
	// contains filtered or unexported fields
}

Model defines a state for the table widget.

func New

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

New creates a new model for the table widget.

func (*Model[T]) Blur

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

Blur blurs the table, preventing selection or movement.

func (Model[T]) Columns

func (m Model[T]) Columns() []Column[T]

Columns returns the current columns.

func (Model[T]) Cursor

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

Cursor returns the index of the selected row.

func (*Model[T]) Focus

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

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

func (Model[T]) Focused

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

Focused returns the focus state of the table.

func (*Model[T]) GotoBottom

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

GotoBottom moves the selection to the last row.

func (*Model[T]) GotoTop

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

GotoTop moves the selection to the first row.

func (Model[T]) Height

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

Height returns the viewport height of the table.

func (Model[T]) HelpView

func (m Model[T]) HelpView() string

HelpView is a helper method for rendering the help menu from the keymap. Note that this view is not rendered by default and you must call it manually in your application, where applicable.

func (*Model[T]) MoveDown

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

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

func (*Model[T]) MoveUp

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

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

func (Model[T]) Rows

func (m Model[T]) Rows() []T

Rows returns the current rows.

func (Model[T]) SelectedRow

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

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

func (*Model[T]) SetColumns

func (m *Model[T]) SetColumns(c []Column[T])

SetColumns sets a new columns state.

func (*Model[T]) SetCursor

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

SetCursor sets the cursor position in the table.

func (*Model[T]) SetHeight

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

SetHeight sets the height of the viewport of the table.

func (*Model[T]) SetRows

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

SetRows sets a new rows state.

func (*Model[T]) SetStyles

func (m *Model[T]) SetStyles(s teaModel.Styles)

SetStyles sets the table styles.

func (*Model[T]) SetWidth

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

SetWidth sets the width of the viewport of the table.

func (Model[T]) Update

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

Update is the Bubble Tea update loop.

func (*Model[T]) UpdateViewport

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

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

func (Model[T]) View

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

View renders the component.

func (Model[T]) Width

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

Width returns the viewport width of the table.

type Option

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

func WithColumns

func WithColumns[T any](cols []Column[T]) Option[T]

WithColumns sets the table columns (headers).

func WithFocused

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

WithFocused sets the focus state of the table.

func WithHeight

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

WithHeight sets the height of the table.

func WithKeyMap

func WithKeyMap[T any](km teaModel.KeyMap) Option[T]

WithKeyMap sets the key map.

func WithRows

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

WithRows sets the table rows (data).

func WithStyles

func WithStyles[T any](s teaModel.Styles) Option[T]

WithStyles sets the table styles.

func WithWidth

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

WithWidth sets the width of the table.

Jump to

Keyboard shortcuts

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