Documentation ¶
Index ¶
- 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]) Blur()
- func (m Model[V]) BottomRowIndex() int
- func (m Model[V]) CurrentRow() (Row[V], bool)
- func (m *Model[V]) DeselectAll()
- func (m *Model[V]) Focus()
- func (m Model[V]) Focused() bool
- func (m *Model[V]) GotoBottom()
- func (m *Model[V]) GotoTop()
- func (m *Model[V]) MoveDown(n int)
- func (m *Model[V]) MoveUp(n int)
- func (m *Model[V]) Prune(fn func(value V) (resource.ID, bool)) ([]resource.ID, error)
- 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.Color)
- func (m *Model[V]) SetItems(items map[resource.ID]V)
- func (m *Model[V]) ToggleSelection()
- func (m *Model[V]) ToggleSelectionByID(id resource.ID)
- func (m Model[V]) TopRowIndex() int
- func (m Model[V]) TotalString() string
- func (m Model[V]) Update(msg tea.Msg) (Model[V], tea.Cmd)
- func (m *Model[V]) UpdateViewport()
- func (m Model[V]) View() string
- type Option
- type RenderedRow
- type Row
- type RowRenderer
- type SortFunc
- type TruncationFunc
Constants ¶
This section is empty.
Variables ¶
var ( IDColumn = Column{ Key: "id", Title: "ID", Width: resource.IDEncodedMaxLen, FlexFactor: 1, } ModuleColumn = Column{ Key: "module", Title: "MODULE", TruncationFunc: TruncateLeft, FlexFactor: 2, } WorkspaceColumn = Column{ Key: "workspace", Title: "WORKSPACE", FlexFactor: 1, } RunColumn = Column{ Key: "run", Title: "RUN", Width: resource.IDEncodedMaxLen, FlexFactor: 1, } TaskColumn = Column{ Key: "task", Title: "TASK", Width: resource.IDEncodedMaxLen, FlexFactor: 1, } RunStatusColumn = Column{ Key: "run_status", Title: "STATUS", Width: run.MaxStatusLen, } RunChangesColumn = Column{ Key: "run_changes", Title: "CHANGES", FlexFactor: 1, } ResourceCountColumn = Column{ Key: "resource_count", Title: "RESOURCES", Width: len("RESOURCES"), FlexFactor: 1, } )
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 }
Column defines the table structure.
type Model ¶
type Model[V resource.Resource] struct { Selected map[resource.ID]V // contains filtered or unexported fields }
Model defines a state for the table widget.
func New ¶
func New[V resource.Resource](columns []Column, fn RowRenderer[V], width, height int, opts ...Option[V]) Model[V]
New creates a new model for the table widget.
func (*Model[V]) Blur ¶
func (m *Model[V]) Blur()
Blur blurs the table, preventing selection or movement.
func (Model[V]) BottomRowIndex ¶ added in v0.2.0
BottomRowNumber returns the index of the bottom visible row.
func (Model[V]) CurrentRow ¶ added in v0.2.0
CurrentRow returns the row on which the cursor currently sits. If the cursor is out of bounds then false is returned along with an empty row.
func (*Model[V]) DeselectAll ¶
func (m *Model[V]) DeselectAll()
DeselectAll de-selects any rows that are currently selected
func (*Model[V]) Focus ¶
func (m *Model[V]) Focus()
Focus focuses the table, allowing the user to move around the rows and interact.
func (*Model[V]) GotoBottom ¶
func (m *Model[V]) GotoBottom()
GotoBottom makes the bottom row the current row.
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]) Prune ¶ added in v0.2.0
Prune invokes the provided function with each selected value, and if the function returns true then it is de-selected. If there are any de-selections then an error is returned. If no pruning occurs then the id from each function invocation is returned.
In the case where there are no selections then the current value is passed to the function, and if the function returns true then an error is reported. If it returns false then the resulting id is returned.
If there are no rows in the table then a nil error is returned.
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 (*Model[V]) SetItems ¶
SetItems sets new items on the table, overwriting existing items. If the table has a parent resource, then items that are not a descendent of that resource are skipped.
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.
func (Model[V]) TopRowIndex ¶ added in v0.2.0
TopRowNumber returns the index of the top visible row.
func (Model[V]) TotalString ¶ added in v0.1.9
func (*Model[V]) UpdateViewport ¶
func (m *Model[V]) UpdateViewport()
UpdateViewport updates the list content based on the previously defined columns and rows.
type Option ¶ added in v0.2.0
func WithParent ¶ added in v0.2.0
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