table

package
v0.0.0-...-cfe8827 Latest Latest
Warning

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

Go to latest
Published: May 18, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package table is a customized implementation of the simple table implementation at "charm.land/bubbles/v2/table".

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Column

type Column struct {
	Title        string
	Suffix       string
	Width        int
	DynamicWidth int
	InVisible    bool
}

Column defines the table structure.

type Field

type Field interface {
	Value() string
}

type FieldDelegate

type FieldDelegate func(row Row, col Column, colIdx, rowIdx, colWidth, padL, padR int, selected bool) string

type HeaderDelegate

type HeaderDelegate func(col Column, colIdx, colWidth, padL, padR int) string

type KeyMap

type KeyMap struct {
	LineUp       key.Binding
	LineDown     key.Binding
	ScrollRight  key.Binding
	ScrollLeft   key.Binding
	ShiftRight   key.Binding
	ShiftLeft    key.Binding
	PageUp       key.Binding
	PageDown     key.Binding
	HalfPageUp   key.Binding
	HalfPageDown key.Binding
	GotoTop      key.Binding
	GotoBottom   key.Binding
	GotoLeft     key.Binding
	GotoRight    key.Binding
}

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

func DefaultKeyMap

func DefaultKeyMap() *KeyMap

DefaultKeyMap returns a default set of keybindings.

func (*KeyMap) FullHelp

func (km *KeyMap) FullHelp() [][]key.Binding

FullHelp implements the KeyMap interface.

func (*KeyMap) ShortHelp

func (km *KeyMap) ShortHelp() []key.Binding

ShortHelp implements the KeyMap interface.

type Model

type Model struct {
	KeyMap *KeyMap
	Help   help.Model
	// contains filtered or unexported fields
}

Model defines a state for the table widget.

func New

func New(opts ...Option) *Model

New creates a new model for the table widget.

func (*Model) AppendRows

func (m *Model) AppendRows(r []Row)

AppendRows appends rows to the table's state. This can be unsafe if the number of columns is not equal to that of existing rows.

func (*Model) Blur

func (m *Model) Blur()

Blur blurs the table, preventing selection or movement.

func (*Model) Columns

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

Columns returns the current columns.

func (*Model) Cursor

func (m *Model) Cursor() int

Cursor returns the index of the selected row.

func (*Model) CursorAtEnd

func (m *Model) CursorAtEnd() bool

CursorAtEnd returns whether the selected row is the last available row

func (*Model) DynamicColumnWidth

func (m *Model) DynamicColumnWidth() bool

DynamicColumnWidth returns the current setting for dynamic-column-width

func (*Model) Focus

func (m *Model) Focus()

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

func (*Model) Focused

func (m *Model) Focused() bool

Focused returns the focus state of the table.

func (*Model) FromValues

func (m *Model) FromValues(value, separator string, cb func(v string) Field)

FromValues create the table rows from a simple string. It uses `\n` by default for getting all the rows and the given separator for the fields on each row. This does not apply styling

func (*Model) GotoBottom

func (m *Model) GotoBottom()

GotoBottom moves the selection to the last row.

func (*Model) GotoLeft

func (m *Model) GotoLeft()

GotoLeft scrolls back to the row beginning

func (*Model) GotoRight

func (m *Model) GotoRight()

GotoRight scrolls to the rows ending

func (*Model) GotoTop

func (m *Model) GotoTop()

GotoTop moves the selection to the first row.

func (*Model) Height

func (m *Model) Height() int

Height returns the viewport height of the table.

func (*Model) HelpView

func (m *Model) 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) MoveContentBoundaries

func (m *Model) MoveContentBoundaries(n int)

func (*Model) MoveDown

func (m *Model) MoveDown(n int)

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

func (*Model) MoveUp

func (m *Model) MoveUp(n int)

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

func (*Model) ResetVirtualRows

func (m *Model) ResetVirtualRows()

resetVirtaulRows empties virtual rows and ensures that the base rows are returned

func (*Model) Rows

func (m *Model) Rows() []Row

Rows returns the current rows.

func (*Model) ScrollLeft

func (m *Model) ScrollLeft(n int)

ScrollLeft scrolls the header and viewport contents to the left

func (*Model) ScrollRight

func (m *Model) ScrollRight(n int)

ScrollRight scrolls the header and viewport contents to the right

func (*Model) SelectedRow

func (m *Model) SelectedRow() *Row

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

func (*Model) SetColumns

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

SetColumns sets a new columns state. Can be unsafe if the number of columns changes. Use SetContent if rows and columns change together.

func (*Model) SetContent

func (m *Model) SetContent(c []Column, r []Row)

SetContent is suited when columns and rows change simultaneously, especially when the number of columns changes from the previous content state. This operation also completely resets any virtual rows.

func (*Model) SetCursor

func (m *Model) SetCursor(n int)

SetCursor sets the cursor position in the table.

func (*Model) SetDynamicColumnWidth

func (m *Model) SetDynamicColumnWidth(b bool)

SetDynamicColumnWidth updates the setting for dynamic-column-width and updates the view appropriately

func (*Model) SetHeight

func (m *Model) SetHeight(h int)

SetHeight sets the height of the viewport of the table.

func (*Model) SetRows

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

SetRows sets a new rows state.Can be unsafe if the number of columns changes. Use SetContent if rows and columns change together.

func (*Model) SetStyles

func (m *Model) SetStyles(s Styles)

SetStyles sets the table styles.

func (*Model) SetVirtualRows

func (m *Model) SetVirtualRows(r []Row)

SetVirtualRows sets the virtual rows Note that supplying nil or [] does not reset the view. To completely remove virtual rows (even if empty) from view, use the `ResetVirtualRows` method.

func (*Model) SetWidth

func (m *Model) SetWidth(w int)

SetWidth sets the width of the viewport of the table.

func (*Model) Update

func (m *Model) Update(msg tea.Msg) tea.Cmd

Update is the Bubble Tea update loop.

func (*Model) UpdateContent

func (m *Model) UpdateContent() (updateHeader bool)

UpdateContent updates the list content based on the previously defined columns and rows. OPTIM: update-content cannot reflect on previous state to determine what rows actually require new rendering; therefore, it renders everything, even if the row was already included in the viewport contents and its selection-state did not change.

func (*Model) UpdateHeader

func (m *Model) UpdateHeader()

func (*Model) View

func (m *Model) View() string

View renders the component.

func (*Model) ViewAtEnd

func (m *Model) ViewAtEnd() bool

ViewAtEnd returns whether the last available row is in view

func (*Model) VirtualRows

func (m *Model) VirtualRows() []Row

VirtualRows returns the current virtual rows.

func (*Model) VisualRows

func (m *Model) VisualRows() []Row

Visual rows returns virtual rows when set or falls back to rows

func (*Model) Width

func (m *Model) Width() int

Width returns the viewport width of the table.

type Option

type Option func(*Model)

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

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

func WithColumns

func WithColumns(cols []Column) Option

WithColumns sets the table columns (headers).

func WithDynamicColumnWidth

func WithDynamicColumnWidth(b bool) Option

func WithFieldDelegate

func WithFieldDelegate(f FieldDelegate) Option

WithFieldDelegate sets the field delegate

func WithFocused

func WithFocused(f bool) Option

WithFocused sets the focus state of the table.

func WithHeaderDelegate

func WithHeaderDelegate(f HeaderDelegate) Option

WithHeaderDelegate sets the header delegate

func WithHeight

func WithHeight(h int) Option

WithHeight sets the height of the table.

func WithKeyMap

func WithKeyMap(km KeyMap) Option

WithKeyMap sets the key map.

func WithRows

func WithRows(rows []Row) Option

WithRows sets the table rows (data).

func WithStyles

func WithStyles(s Styles) Option

WithStyles sets the table styles.

func WithVirtualRows

func WithVirtualRows(rows []Row) Option

WithVirtualRows sets the table virtual rows (data view).

func WithWidth

func WithWidth(w int) Option

WithWidth sets the width of the table.

type Row

type Row struct {
	Fields   []Field
	Metadata map[string]any
}

Row represents one line in the table.

func (Row) String

func (r Row) String() string

type Rows

type Rows []Row

func (Rows) ToStrings

func (r Rows) ToStrings() []string

Convenience function for obtaining plain string representation of each row. Useful for searching.

type Styles

type Styles struct {
	Header lipgloss.Style
	// only affects default styling, remains unused when using a delegate
	Cell lipgloss.Style
	// only affects default styling, remains unused when using a delegate
	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