Documentation
¶
Overview ¶
Package table renders a column-aligned data grid with sortable headers, keyboard navigation, internal scrolling, and optional row selection. It's the primitive every operator surface reaches for once a list outgrows a single column: a queue of jobs with status and owner, a roster of repos with engagement counts, a sweep of PRs with CI state.
A table owns the cursor, the scroll window, the active sort column, and an optional "active" header used to steer the next sort. It does not own the detail view. The parent reads SelectedRow() to drive the panel beside the table, and listens for SelectMsg on Enter when row selection is enabled.
Index ¶
- type Align
- type Column
- type CursorMsg
- type Model
- func (m Model) Columns() []Column
- func (m Model) Cursor() int
- func (m Model) Init() tea.Cmd
- func (m Model) Rows() []Row
- func (m Model) SelectedRow() (Row, bool)
- func (m Model) SortBy() (string, bool)
- func (m Model) Update(msg tea.Msg) (Model, tea.Cmd)
- func (m Model) View() string
- func (m Model) WithColumns(cols ...Column) Model
- func (m Model) WithHighlightCursor(enabled bool) Model
- func (m Model) WithRowSelection(enabled bool) Model
- func (m Model) WithRows(rows ...Row) Model
- func (m Model) WithSelectedRow(index int) Model
- func (m Model) WithSize(width, height int) Model
- func (m Model) WithSortBy(columnKey string, descending bool) Model
- func (m Model) WithTheme(t theme.Theme) Model
- type Row
- type SelectMsg
- type SortMsg
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Align ¶
type Align int
Align controls horizontal alignment of a column's cells. AlignLeft is the default and is what string-flavored columns want; AlignRight is what numeric columns want; AlignCenter is for narrow status badges.
type Column ¶
Column describes one vertical column of the table. Width == 0 means auto-fit to the widest content seen across rows (capped at 40 cells) and the title. Otherwise Width is treated as the fixed render width in cells.
type CursorMsg ¶
type CursorMsg struct {
Index int
}
CursorMsg is emitted on cursor movement. The parent can ignore it; it exists for surfaces that mirror the cursor in a separate detail pane.
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
Model is the table's Bubble Tea model. Construct with New and chain builder calls; every method returns a new Model.
func New ¶
func New() Model
New constructs an empty table with safe defaults: cursor highlight on, no row selection, a generous 80x12 render box.
func (Model) SelectedRow ¶
SelectedRow returns the row under the cursor. Bool is false on empty.
func (Model) SortBy ¶
SortBy returns the current sort key and direction. Empty key means no active sort.
func (Model) Update ¶
Update routes key and resize messages. Returns (Model, tea.Cmd) to match the convention of every other glyph component; the table value is also a tea.Model so callers can pass it through tea.Program.
func (Model) View ¶
View renders the header, separator, and visible window of rows. An empty row set produces header + separator + a placeholder line.
func (Model) WithColumns ¶
WithColumns replaces the column set. The active sort column is cleared if the previous sort key no longer matches any column.
func (Model) WithHighlightCursor ¶
WithHighlightCursor toggles the surface highlight applied to the row under the cursor. Default true.
func (Model) WithRowSelection ¶
WithRowSelection toggles Enter-emits-SelectMsg behavior.
func (Model) WithRows ¶
WithRows replaces the row set. Cursor clamps to the new length; the active sort (if any) is re-applied so callers can hand in unsorted data and trust the view.
func (Model) WithSelectedRow ¶
WithSelectedRow positions the cursor. Clamped to [0, len(rows)).
func (Model) WithSize ¶
WithSize sets the render width and total height. Height includes the header row plus one separator line, so visible-row count is height-2.
func (Model) WithSortBy ¶
WithSortBy sets the active sort column by key and direction. Pass columnKey == "" to clear the sort. Applies a stable sort immediately.
type Row ¶
Row is one record. Cells must line up with Columns by index; missing trailing cells render as blank. Value is opaque payload the parent can read off SelectedRow() or pull off SelectMsg.
