table

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2024 License: MPL-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

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
}

Column defines the table structure.

type ColumnKey

type ColumnKey string

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

func (m Model[V]) BottomRowIndex() int

BottomRowNumber returns the index of the bottom visible row.

func (Model[V]) CurrentRow added in v0.2.0

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

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]) 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) (resource.ID, bool)) ([]resource.ID, 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.Color)

func (*Model[V]) SetItems

func (m *Model[V]) SetItems(items map[resource.ID]V)

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

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

func (m Model[V]) TopRowIndex() int

TopRowNumber returns the index of the top visible row.

func (Model[V]) TotalString added in v0.1.9

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

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

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

UpdateViewport updates the list content based on the previously defined columns and rows.

func (Model[V]) View

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

View renders the component.

type Option added in v0.2.0

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

func WithParent added in v0.2.0

func WithParent[V resource.Resource](parent resource.Resource) Option[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