Documentation
¶
Index ¶
- Constants
- Variables
- func TruncateLeft(s string, w int, prefix string) string
- func TruncateRight(s string, w int, tail string) string
- type BulkInsertMsg
- type Column
- type ColumnKey
- type Model
- func (m *Model[V]) AddItems(items ...V)
- func (m Model[V]) CurrentRow() (Row[V], bool)
- func (m *Model[V]) DeselectAll()
- func (m *Model[V]) GotoBottom()
- func (m *Model[V]) GotoTop()
- func (m *Model[V]) Metadata() string
- func (m *Model[V]) MoveDown(n int)
- func (m *Model[V]) MoveUp(n int)
- func (m *Model[V]) PreviewCurrentRow() (tui.Kind, resource.ID, bool)
- func (m *Model[V]) SelectAll()
- func (m *Model[V]) SelectRange()
- func (m Model[V]) SelectedOrCurrent() []Row[V]
- func (m Model[V]) SelectedOrCurrentIDs() []resource.ID
- func (m *Model[V]) SetBorderStyle(border lipgloss.Border, color lipgloss.TerminalColor)
- func (m *Model[V]) SetItems(items ...V)
- func (m *Model[V]) ToggleSelection()
- func (m *Model[V]) ToggleSelectionByID(id resource.ID)
- func (m Model[V]) Update(msg tea.Msg) (Model[V], tea.Cmd)
- func (m Model[V]) View() string
- type Option
- type RenderedRow
- type Row
- type RowRenderer
- type SortFunc
- type TruncationFunc
Constants ¶
const ( // Minimum recommended height for the table widget. Respecting this minimum // ensures the header and the borders and the filter widget are visible. MinHeight = 6 )
Variables ¶
var ( ModuleColumn = Column{ Key: "module", Title: "MODULE", TruncationFunc: TruncateLeft, FlexFactor: 2, } WorkspaceColumn = Column{ Key: "workspace", Title: "WORKSPACE", FlexFactor: 1, } SummaryColumn = Column{ Key: "summary", Title: "SUMMARY", FlexFactor: 1, } ResourceCountColumn = Column{ Key: "resource_count", Title: "RESOURCES", Width: len("RESOURCES"), } CostColumn = Column{ Key: "cost", Title: "COST", FlexFactor: 1, RightAlign: true, } )
Functions ¶
Types ¶
type BulkInsertMsg ¶
type BulkInsertMsg[T any] []T
BulkInsertMsg performs a bulk insertion of entities into a table
type Column ¶
type Column struct { Key ColumnKey // TODO: Default to upper case of key Title string Width int FlexFactor int TruncationFunc func(s string, w int, tail string) string // RightAlign aligns content to the right. If false, content is aligned to // the left. RightAlign bool }
Column defines the table structure.
type Model ¶
Model defines a state for the table widget.
func New ¶
func New[V resource.Resource](cols []Column, fn RowRenderer[V], width, height int, opts ...Option[V]) Model[V]
New creates a new model for the table widget.
func (*Model[V]) AddItems ¶ added in v0.5.0
func (m *Model[V]) AddItems(items ...V)
AddItems idempotently adds items to the table, updating any items that exist on the table already.
func (Model[V]) CurrentRow ¶ added in v0.2.0
CurrentRow returns the current row the user has highlighted. If the table is empty then false is returned.
func (*Model[V]) DeselectAll ¶
func (m *Model[V]) DeselectAll()
DeselectAll de-selects any rows that are currently selected
func (*Model[V]) GotoBottom ¶
func (m *Model[V]) GotoBottom()
GotoBottom makes the bottom row the current row.
func (*Model[V]) Metadata ¶ added in v0.6.0
Metadata renders a short string summarizing table row metadata.
func (*Model[V]) MoveDown ¶
MoveDown moves the current row down by any number of rows. It can not go below the last row.
func (*Model[V]) MoveUp ¶
MoveUp moves the current row up by any number of rows. It can not go above the first row.
func (*Model[V]) PreviewCurrentRow ¶ added in v0.6.0
func (*Model[V]) SelectAll ¶ added in v0.2.0
func (m *Model[V]) SelectAll()
SelectAll selects all rows. Any rows not currently selected are selected.
func (*Model[V]) SelectRange ¶ added in v0.1.8
func (m *Model[V]) SelectRange()
SelectRange selects a range of rows. If the current row is *below* a selected row then rows between them are selected, including the current row. Otherwise, if the current row is *above* a selected row then rows between them are selected, including the current row. If there are no selected rows then no action is taken.
func (Model[V]) SelectedOrCurrent ¶ added in v0.2.0
SelectedOrCurrent returns either the selected rows, or if there are no selections, the current row
func (Model[V]) SelectedOrCurrentIDs ¶ added in v0.2.0
func (*Model[V]) SetBorderStyle ¶ added in v0.2.0
func (m *Model[V]) SetBorderStyle(border lipgloss.Border, color lipgloss.TerminalColor)
func (*Model[V]) SetItems ¶
func (m *Model[V]) SetItems(items ...V)
SetItems overwrites all existing items in the table with items.
func (*Model[V]) ToggleSelection ¶
func (m *Model[V]) ToggleSelection()
ToggleSelection toggles the selection of the current row.
func (*Model[V]) ToggleSelectionByID ¶ added in v0.2.0
ToggleSelectionByID toggles the selection of the row with the given id. If the id does not exist no action is taken.
type Option ¶ added in v0.2.0
func WithPreview ¶ added in v0.6.0
WithPreview configures the table to automatically populate the bottom right pane with a model corresponding to the current row.
func WithSelectable ¶ added in v0.2.0
WithSelectable sets whether rows are selectable.
type RenderedRow ¶
RenderedRow provides the rendered string for each column in a row.
type RowRenderer ¶
type RowRenderer[V any] func(V) RenderedRow