Documentation
¶
Overview ¶
Package table provides a reusable table component with GCP styling and filtering support. Enhanced with column caching and flexible column definitions inspired by gh-dash.
Index ¶
- Variables
- func CellStyle() lipgloss.Style
- func DefaultTableStyles() table.Styles
- func HeaderStyle() lipgloss.Style
- func SelectedStyle() lipgloss.Style
- type Column
- type KeyMap
- type Model
- func (m *Model) AppendRows(newRows []Row)
- func (m *Model) Blur()
- func (m *Model) ClearSort()
- func (m *Model) FilterValue() string
- func (m *Model) Focus()
- func (m *Model) GetRegions() []mouse.Region
- func (m *Model) GetVisibleColumnCount() int
- func (m *Model) HandleRegionClick(regionID string) tea.Cmd
- func (m *Model) HasTextInputFocused() bool
- func (m *Model) IsFiltering() bool
- func (m *Model) IsLoading() bool
- func (m *Model) IsScrollable() bool
- func (m *Model) IsSortMenuOpen() bool
- func (m *Model) ResetNearBottom()
- func (m *Model) RowCount() int
- func (m *Model) Rows() []Row
- func (m *Model) ScrollPercent() float64
- func (m *Model) SelectedIndex() int
- func (m *Model) SelectedRow() *Row
- func (m *Model) SetColumnHidden(title string, hidden bool)
- func (m *Model) SetCursor(i int)
- func (m *Model) SetEmptyText(text string)
- func (m *Model) SetFilter(value string)
- func (m *Model) SetLoading(loading bool, text string)
- func (m *Model) SetNearBottomThreshold(n int)
- func (m *Model) SetRows(rows []Row)
- func (m *Model) SetSize(width, height int)
- func (m *Model) SetStatusSuffix(suffix string)
- func (m *Model) SetTitle(title string)
- func (m *Model) SortBy(colIndex int, ascending bool)
- func (m *Model) SortState() (col int, ascending bool)
- func (m *Model) TotalRowCount() int
- func (m Model) Update(msg tea.Msg) (Model, tea.Cmd)
- func (m *Model) UpdateRegions(offsetX, offsetY int)
- func (m Model) View() string
- func (m *Model) VisibleRows() []Row
- type NearBottomMsg
- type Row
- type RowDoubleClickedMsg
- type StatusStyle
Constants ¶
This section is empty.
Variables ¶
var ( ColorPrimary = lipgloss.Color("#4285F4") // Google Blue ColorMuted = lipgloss.Color("#9AA0A6") // Gray ColorWhite = lipgloss.Color("#FFFFFF") ColorBgLight = lipgloss.Color("#303134") // Lighter background )
GCP-inspired color palette
Functions ¶
func DefaultTableStyles ¶
DefaultTableStyles returns table styles matching the GCP theme
func HeaderStyle ¶
HeaderStyle returns the style for table headers
func SelectedStyle ¶
SelectedStyle returns the style for selected rows
Types ¶
type Column ¶
type Column struct {
Title string // Column header text
Width int // Base width (minimum if Grow is true)
Hidden bool // If true, column is not displayed
Grow bool // If true, column expands to fill available space
ComputedWidth int // Cached width after layout calculation (internal)
FilterKeys []string // Keys for field:value filtering (auto-derived from Title if nil)
Sortable bool // Whether column appears in sort menu
}
Column defines a table column with enhanced properties. Inspired by gh-dash's column management pattern.
type KeyMap ¶
type KeyMap struct {
Up key.Binding
Down key.Binding
Enter key.Binding
Filter key.Binding
Escape key.Binding
Refresh key.Binding
Sort key.Binding
}
KeyMap defines the key bindings for the table
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
Model represents a filterable table with GCP styling
func NewWithColumns ¶
NewWithColumns creates a table with enhanced column definitions. This enables column hiding, flexible growth, and width caching.
func (*Model) AppendRows ¶
AppendRows adds rows to the table without resetting cursor or sort. Used for infinite scroll to seamlessly add more data.
func (*Model) FilterValue ¶
FilterValue returns the current filter text
func (*Model) GetRegions ¶
GetRegions returns current clickable regions. Implements the Clickable interface.
func (*Model) GetVisibleColumnCount ¶
GetVisibleColumnCount returns the number of visible columns
func (*Model) HandleRegionClick ¶
HandleRegionClick processes a click on a specific region. Implements the Clickable interface.
func (*Model) HasTextInputFocused ¶
HasTextInputFocused returns true if the filter text input or sort menu is focused. Used to prevent global hotkeys (like 'q' for quit) from triggering while typing.
func (*Model) IsFiltering ¶
IsFiltering returns true if filter input is active
func (*Model) IsScrollable ¶
IsScrollable returns true when total rows exceed visible height.
func (*Model) IsSortMenuOpen ¶
IsSortMenuOpen returns true if the sort menu overlay is active. Views should check this to defer key handling.
func (*Model) ResetNearBottom ¶
func (m *Model) ResetNearBottom()
ResetNearBottom allows the next NearBottomMsg to fire. Call this after new data has been appended.
func (*Model) Rows ¶ added in v0.9.0
Rows returns a deep copy of the current (unfiltered) rows. Callers may mutate the returned slice — including each row's Data cells — without affecting the model; the model only updates when SetRows is called.
func (*Model) ScrollPercent ¶
ScrollPercent returns 0.0–1.0 based on cursor position within all rows. First item = 0%, last item = 100%. Returns 0 when all rows fit on screen.
func (*Model) SelectedIndex ¶
SelectedIndex returns the cursor position
func (*Model) SelectedRow ¶
SelectedRow returns the currently selected row, or nil if none
func (*Model) SetColumnHidden ¶
SetColumnHidden changes the visibility of a column by title. Triggers a recalculation of column widths and re-emits the row data so the underlying bubbles table sees row cells matching its column count.
Implementation note: bubbles' `renderRow` iterates over a row's cells and indexes into the column slice, so any transient state where the cell count and column count disagree panics. Unfortunately bubbles has no atomic "set both" API, and either single ordering (rows-first or columns-first) is wrong in one of the two directions. We instead clear bubbles' rows before changing the column set, then re-emit the reshaped rows. The empty intermediate state is safe in either direction.
func (*Model) SetCursor ¶ added in v0.10.0
SetCursor moves the cursor to row i in the currently visible (filtered) row list. Out-of-range indices are clamped to a valid value.
func (*Model) SetEmptyText ¶
SetEmptyText sets the text shown when there are no rows
func (*Model) SetFilter ¶ added in v0.12.0
SetFilter programmatically sets the filter text and re-applies it. Supports the same field:value syntax as the interactive filter input. Pass an empty string to clear the filter.
func (*Model) SetLoading ¶
SetLoading sets the loading state with optional custom text
func (*Model) SetNearBottomThreshold ¶
SetNearBottomThreshold enables near-bottom detection. The NearBottomMsg fires when the cursor is within n rows of the last row. Set to 0 to disable. Negative values are treated as 0.
func (*Model) SetStatusSuffix ¶
SetStatusSuffix sets extra text appended to the status bar (e.g. "(all loaded)"). Pass empty string to clear.
func (*Model) SortBy ¶
SortBy sorts the table by a visible column index. Reapplies to current filter.
func (*Model) SortState ¶ added in v0.9.0
SortState returns the current sort column index (or -1 when no sort) and the sort direction. Used by callers that need to preserve the user's sort across SetRows() (which clears the sort).
func (*Model) TotalRowCount ¶
TotalRowCount returns the total number of rows (before filtering)
func (*Model) UpdateRegions ¶
UpdateRegions recalculates clickable regions based on current state. Implements the Clickable interface.
func (*Model) VisibleRows ¶ added in v0.10.0
VisibleRows returns a deep copy of the rows currently visible in the table — i.e., after the active filter (if any) is applied. Use this when you need to iterate over what the user actually sees, e.g. for a "select all visible" gesture. Cells in the returned slice are safe to mutate.
type NearBottomMsg ¶
type NearBottomMsg struct{}
NearBottomMsg is emitted when the cursor approaches the bottom of the table. Views can use this to trigger loading more data (infinite scroll).
type Row ¶
type Row struct {
Data []string // Column values
FilterValue string // String used for filtering
ID string // Unique identifier for the row
}
Row represents a table row with filterable content
type RowDoubleClickedMsg ¶
type RowDoubleClickedMsg struct {
RowID string // ID of the double-clicked row
Index int // Index of the double-clicked row
}
RowDoubleClickedMsg is emitted when a row is double-clicked. Views should handle this to perform the default action (e.g., open details).
type StatusStyle ¶
type StatusStyle struct {
Running lipgloss.Style
Stopped lipgloss.Style
Pending lipgloss.Style
Unknown lipgloss.Style
}
StatusStyle returns styles for different status values
func DefaultStatusStyles ¶
func DefaultStatusStyles() StatusStyle
DefaultStatusStyles returns status-specific styles