table

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2025 License: MIT Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewFilterTable

func NewFilterTable(title string, cols Columns, rows []Row, styles FilterTableStyles, keymap FilterTableKeyMap) tea.Model

func NewTable

func NewTable(title string, cols Columns, rows []Row, styles Styles, keymap KeyMap) tea.Model

func StringStyler

func StringStyler(styles map[string]lipgloss.Style) func(string) string

StringStyler attempts to match a string to the lookup map of styles. If the string does not match, it is not changed.

It's useful for styling cells in a table, using the lipgloss.Style Transform method.

Types

type CellStyle

type CellStyle struct {
	// Style is the style for the cell.
	Style lipgloss.Style
	// Format is a printf-style format string for the cell value.
	// If not specified, the default format is "%v".
	Format string
}

CellStyle specifies a customized style for a cell in a column, overriding the table's Cell and Selected styles.

NOTE: Table renders the row by taking this style and inheriting from the table's Selected/Cell style, Any style attributes from the base Style are overridden if also specified in Selected/Cell style. This may result in unexpected behavior. E.g., if the base Style has a background color, but the base style has a black background, then the column's row will have a black background, which is probably not what you want.

type Column

type Column struct {
	// RowStyle overrides the style for row cells in this column, as specified in Styles.Selected and Styles.Cell.
	//
	// NOTE: Table renders the row by taking this style and inheriting from the table's Selected/Cell style,
	// Any style attributes from the base Style are overridden if also specified in Selected/Cell style.
	// This may result in unexpected behavior. E.g., if the base Style has a background color,
	// but the base style has a black background, then the column's row will have a black background,
	// which is probably not what you want.
	RowStyle CellStyle
	// Name of the column.
	Name string
	// Width <= 0 indicates flexible (auto) width to be computed from available space.
	Width int
}

Column specifies a column in the table (the name and width), as well as an optional CellStyle to override the table's Cell and Selected styles.

type Columns

type Columns []Column

Columns contain the columns of the table.

type FilterKeyMap

type FilterKeyMap struct {
	Activate key.Binding
	Close    key.Binding
	Clear    key.Binding
}

func DefaultFilterKeyMap

func DefaultFilterKeyMap() FilterKeyMap

func (FilterKeyMap) FullHelp

func (f FilterKeyMap) FullHelp() [][]key.Binding

func (FilterKeyMap) ShortHelp

func (f FilterKeyMap) ShortHelp() []key.Binding

type FilterStateChangeMsg added in v0.5.0

type FilterStateChangeMsg struct {
	State bool
}

FilterStateChangeMsg is sent when the filter is switched on or off. State indicates the new state.

type FilterStyles

type FilterStyles struct {
	// Border is the style for the border of the filter.
	Border lipgloss.Style
	// TextArea is the style for the text area of the filter.
	TextArea textarea.Style
}

type FilterTable

type FilterTable struct {
	// contains filtered or unexported fields
}

func (FilterTable) Init

func (f FilterTable) Init() tea.Cmd

func (FilterTable) Update

func (f FilterTable) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (FilterTable) View

func (f FilterTable) View() string

type FilterTableKeyMap

type FilterTableKeyMap struct {
	TableKeyMap  KeyMap
	FilterKeyMap FilterKeyMap
}

func DefaultFilterTableKeyMap

func DefaultFilterTableKeyMap() FilterTableKeyMap

func (FilterTableKeyMap) FullHelp

func (f FilterTableKeyMap) FullHelp() [][]key.Binding

func (FilterTableKeyMap) ShortHelp

func (f FilterTableKeyMap) ShortHelp() []key.Binding

type FilterTableStyles

type FilterTableStyles struct {
	Table  Styles
	Filter FilterStyles
}

type KeyMap

type KeyMap struct {
	MoveUp   key.Binding
	MoveDown key.Binding
	PgUp     key.Binding
	PgDown   key.Binding
}

func DefaultKeyMap

func DefaultKeyMap() KeyMap

func (KeyMap) FullHelp

func (k KeyMap) FullHelp() [][]key.Binding

func (KeyMap) ShortHelp

func (k KeyMap) ShortHelp() []key.Binding

type Row

type Row []any

type RowChangedMsg added in v0.5.0

type RowChangedMsg struct {
	Row       Row
	OldCursor int
	NewCursor int
}

RowChangedMsg is sent when the selected row changes.

type SetRowsMsg

type SetRowsMsg struct {
	Rows []Row
}

SetRowsMsg sets the rows in the table.

type SetSizeMsg

type SetSizeMsg struct {
	Width  int
	Height int
}

SetSizeMsg sets the size of the table (including any border requested by styles

type SetTitleMsg

type SetTitleMsg struct {
	Title string
}

SetTitleMsg sets the title of the table.

type Styles

type Styles struct {
	// Border formats the border of the table.
	Frame frame.Styles
	// Header formats the column headers.
	Header lipgloss.Style
	// Selected formats the selected row.
	Selected lipgloss.Style
	// Cell formats the non-selected rows in the table.
	Cell lipgloss.Style
}

type Table

type Table struct {
	// contains filtered or unexported fields
}

func (Table) Init

func (t Table) Init() tea.Cmd

Init is called once when the program starts. Always returns nil (no initialization required).

func (Table) Update

func (t Table) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update processes incoming messages and returns the new state.

func (Table) View

func (t Table) View() string

View renders the table.

type UserData

type UserData struct {
	Data any
}

UserData is a cell that is not rendered. Its main purpose is to attach user data to a row without affecting rendering or column alignment.

Jump to

Keyboard shortcuts

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