table

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2026 License: MIT Imports: 14 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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 CellStyle

func CellStyle() lipgloss.Style

CellStyle returns the default style for table cells

func DefaultTableStyles

func DefaultTableStyles() table.Styles

DefaultTableStyles returns table styles matching the GCP theme

func HeaderStyle

func HeaderStyle() lipgloss.Style

HeaderStyle returns the style for table headers

func SelectedStyle

func SelectedStyle() lipgloss.Style

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

func DefaultKeyMap

func DefaultKeyMap() KeyMap

DefaultKeyMap returns the default key bindings

type Model

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

Model represents a filterable table with GCP styling

func New

func New(columns []table.Column, title string) Model

New creates a new table model (backward compatible)

func NewWithColumns

func NewWithColumns(cols []Column, title string) Model

NewWithColumns creates a table with enhanced column definitions. This enables column hiding, flexible growth, and width caching.

func (*Model) AppendRows

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

AppendRows adds rows to the table without resetting cursor or sort. Used for infinite scroll to seamlessly add more data.

func (*Model) Blur

func (m *Model) Blur()

Blur removes focus

func (*Model) ClearSort

func (m *Model) ClearSort()

ClearSort removes the current sort.

func (*Model) FilterValue

func (m *Model) FilterValue() string

FilterValue returns the current filter text

func (*Model) Focus

func (m *Model) Focus()

Focus sets the focus state

func (*Model) GetRegions

func (m *Model) GetRegions() []mouse.Region

GetRegions returns current clickable regions. Implements the Clickable interface.

func (*Model) GetVisibleColumnCount

func (m *Model) GetVisibleColumnCount() int

GetVisibleColumnCount returns the number of visible columns

func (*Model) HandleRegionClick

func (m *Model) HandleRegionClick(regionID string) tea.Cmd

HandleRegionClick processes a click on a specific region. Implements the Clickable interface.

func (*Model) HasTextInputFocused

func (m *Model) HasTextInputFocused() bool

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

func (m *Model) IsFiltering() bool

IsFiltering returns true if filter input is active

func (*Model) IsLoading

func (m *Model) IsLoading() bool

IsLoading returns true if the table is in loading state

func (*Model) IsScrollable

func (m *Model) IsScrollable() bool

IsScrollable returns true when total rows exceed visible height.

func (*Model) IsSortMenuOpen

func (m *Model) IsSortMenuOpen() bool

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) RowCount

func (m *Model) RowCount() int

RowCount returns the number of visible rows

func (*Model) ScrollPercent

func (m *Model) ScrollPercent() float64

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

func (m *Model) SelectedIndex() int

SelectedIndex returns the cursor position

func (*Model) SelectedRow

func (m *Model) SelectedRow() *Row

SelectedRow returns the currently selected row, or nil if none

func (*Model) SetColumnHidden

func (m *Model) SetColumnHidden(title string, hidden bool)

SetColumnHidden changes the visibility of a column by title. Triggers a recalculation of column widths.

func (*Model) SetEmptyText

func (m *Model) SetEmptyText(text string)

SetEmptyText sets the text shown when there are no rows

func (*Model) SetLoading

func (m *Model) SetLoading(loading bool, text string)

SetLoading sets the loading state with optional custom text

func (*Model) SetNearBottomThreshold

func (m *Model) SetNearBottomThreshold(n int)

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) SetRows

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

SetRows updates the table rows. Resets sort since data has changed.

func (*Model) SetSize

func (m *Model) SetSize(width, height int)

SetSize updates the table dimensions

func (*Model) SetStatusSuffix

func (m *Model) SetStatusSuffix(suffix string)

SetStatusSuffix sets extra text appended to the status bar (e.g. "(all loaded)"). Pass empty string to clear.

func (*Model) SetTitle

func (m *Model) SetTitle(title string)

SetTitle updates the table title displayed above the header row.

func (*Model) SortBy

func (m *Model) SortBy(colIndex int, ascending bool)

SortBy sorts the table by a visible column index. Reapplies to current filter.

func (*Model) TotalRowCount

func (m *Model) TotalRowCount() int

TotalRowCount returns the total number of rows (before filtering)

func (Model) Update

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

Update handles messages

func (*Model) UpdateRegions

func (m *Model) UpdateRegions(offsetX, offsetY int)

UpdateRegions recalculates clickable regions based on current state. Implements the Clickable interface.

func (Model) View

func (m Model) View() string

View renders the table

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

Jump to

Keyboard shortcuts

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