table

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2026 License: MIT Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StringStyler added in v0.4.0

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,
	// This may result in unexpected behavior. E.g., if the RowStyle specifies a background color,
	// but row's style calls for a different background, then the cell will have the RowStyle background,
	// which is probably not what you want.
	//
	// It is recommended to limit use of the CellStyle to set alignment of the cell
	// and use the Transform functionality.
	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 added in v0.4.0

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.2.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 added in v0.4.0

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

func NewFilterTable added in v0.4.0

func NewFilterTable(title string, cols Columns, rows []Row, styles FilterTableStyles, keymap FilterTableKeyMap) *FilterTable

func (*FilterTable) Init added in v0.4.0

func (f *FilterTable) Init() tea.Cmd

func (*FilterTable) SetRows added in v0.6.1

func (f *FilterTable) SetRows(rows []Row)

func (*FilterTable) SetSize added in v0.6.1

func (f *FilterTable) SetSize(width, height int)

func (*FilterTable) Update added in v0.4.0

func (f *FilterTable) Update(msg tea.Msg) tea.Cmd

func (*FilterTable) View added in v0.4.0

func (f *FilterTable) View() string

type FilterTableKeyMap added in v0.4.0

type FilterTableKeyMap struct {
	TableKeyMap  KeyMap
	FilterKeyMap FilterKeyMap
}

func DefaultFilterTableKeyMap added in v0.4.0

func DefaultFilterTableKeyMap() FilterTableKeyMap

func (FilterTableKeyMap) FullHelp added in v0.4.0

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

func (FilterTableKeyMap) ShortHelp added in v0.4.0

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

type FilterTableStyles added in v0.4.0

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 added in v0.4.0

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

Row is a single row of the table. It is a slice of any type.

By default, row items are formatted with the `fmt.Sprintf("%v", item)` function and styled with the table's Selected & Cell styles. You can override this by setting the `RowStyle` of a column.

For example, to format a cell containing an int as a hex number, you could do this:

	table.Column{
	    Title: "Percentage",
	    RowStyle: table.CellStyle{Format: "%x"},
    }

The number of items in the slice must match the number of columns.

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 {
	SelectedRow Row
	// contains filtered or unexported fields
}

func NewTable added in v0.4.0

func NewTable(title string, cols Columns, rows []Row, styles Styles, keymap KeyMap) *Table

func (*Table) Init added in v0.3.0

func (t *Table) Init() tea.Cmd

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

func (*Table) SetRows added in v0.6.1

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

func (*Table) SetSize added in v0.6.1

func (t *Table) SetSize(width, height int)

func (*Table) SetTitle added in v0.6.1

func (t *Table) SetTitle(title string)

func (*Table) Update

func (t *Table) Update(msg tea.Msg) tea.Cmd

Update processes incoming messages and returns any commands in response to those messages

func (*Table) View

func (t *Table) View() string

View renders the table.

type UserData added in v0.2.0

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