table

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2025 License: MPL-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

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

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

func TruncateLeft

func TruncateLeft(s string, w int, prefix string) string

func TruncateRight

func TruncateRight(s string, w int, tail string) string

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 ColumnKey

type ColumnKey string

type Model

type Model[V resource.Resource] struct {
	// contains filtered or unexported fields
}

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

func (m Model[V]) CurrentRow() (Row[V], bool)

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]) GotoTop

func (m *Model[V]) GotoTop()

GotoTop makes the top row the current row.

func (*Model[V]) Metadata added in v0.6.0

func (m *Model[V]) Metadata() string

Metadata renders a short string summarizing table row metadata.

func (*Model[V]) MoveDown

func (m *Model[V]) MoveDown(n int)

MoveDown moves the current row down by any number of rows. It can not go below the last row.

func (*Model[V]) MoveUp

func (m *Model[V]) MoveUp(n int)

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 (m *Model[V]) PreviewCurrentRow() (tui.Kind, resource.ID, bool)

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

func (m Model[V]) SelectedOrCurrent() []Row[V]

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 (m Model[V]) SelectedOrCurrentIDs() []resource.ID

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

func (m *Model[V]) ToggleSelectionByID(id resource.ID)

ToggleSelectionByID toggles the selection of the row with the given id. If the id does not exist no action is taken.

func (Model[V]) Update

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

Update is the Bubble Tea update loop.

func (Model[V]) View

func (m Model[V]) View() string

View renders the table.

type Option added in v0.2.0

type Option[V resource.Resource] func(m *Model[V])

func WithPreview added in v0.6.0

func WithPreview[V resource.Resource](maker tui.Kind) Option[V]

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

func WithSelectable[V resource.Resource](s bool) Option[V]

WithSelectable sets whether rows are selectable.

func WithSortFunc added in v0.2.0

func WithSortFunc[V resource.Resource](sortFunc func(V, V) int) Option[V]

WithSortFunc configures the table to sort rows using the given func.

type RenderedRow

type RenderedRow map[ColumnKey]string

RenderedRow provides the rendered string for each column in a row.

type Row

type Row[V any] struct {
	ID    resource.ID
	Value V
}

type RowRenderer

type RowRenderer[V any] func(V) RenderedRow

type SortFunc

type SortFunc[V any] func(V, V) int

type TruncationFunc

type TruncationFunc func(s string, w int, tailOrPrefix string) string

Jump to

Keyboard shortcuts

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