table

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2024 License: MPL-2.0 Imports: 17 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]) Blur

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

Blur blurs the table, preventing selection or movement.

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 its index 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]) Focused

func (m Model[V]) Focused() bool

Focused returns the focus state of the table.

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]) 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]) Prune added in v0.2.0

func (m *Model[V]) Prune(fn func(value V) (task.Spec, error)) ([]task.Spec, error)

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

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