table

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: MPL-2.0 Imports: 15 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:     3,
	}
	WorkspaceColumn = Column{
		Key:        "workspace",
		Title:      "WORKSPACE",
		FlexFactor: 2,
	}
	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,
	}
)

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 DeselectMsg

type DeselectMsg struct{}

DeselectMsg deselects any table rows currently selected.

type Model

type Model[K comparable, V any] struct {
	Selected map[K]V
	// contains filtered or unexported fields
}

Model defines a state for the table widget.

func New

func New[K comparable, V any](columns []Column, fn RowRenderer[V], width, height int) Model[K, V]

New creates a new model for the table widget.

func (*Model[K, V]) Blur

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

Blur blurs the table, preventing selection or movement.

func (Model[K, V]) Cursor

func (m Model[K, V]) Cursor() int

Cursor returns the index of the highlighted row.

func (*Model[K, V]) DeselectAll

func (m *Model[K, V]) DeselectAll()

DeselectAll de-selects any rows that are currently selected

func (*Model[K, V]) Focus

func (m *Model[K, V]) Focus()

Focus focuses the table, allowing the user to move around the rows and interact.

func (Model[K, V]) Focused

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

Focused returns the focus state of the table.

func (*Model[K, V]) GotoBottom

func (m *Model[K, V]) GotoBottom()

GotoBottom moves the highlightion to the last row.

func (*Model[K, V]) GotoTop

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

GotoTop moves the highlightion to the first row.

func (Model[K, V]) Height

func (m Model[K, V]) Height() int

Height returns the viewport height of the table.

func (Model[K, V]) Highlighted

func (m Model[K, V]) Highlighted() (Row[K, V], bool)

Highlighted returns the currently highlighted entity.

func (Model[K, V]) HighlightedKey

func (m Model[K, V]) HighlightedKey() (K, bool)

Highlighted returns the currently highlighted entity key.

func (Model[K, V]) HighlightedOrSelected

func (m Model[K, V]) HighlightedOrSelected() []Row[K, V]

HighlightedOrSelected returns either the selected entities, if there are no selections, the currently highlighted entity.

func (Model[K, V]) HighlightedOrSelectedKeys

func (m Model[K, V]) HighlightedOrSelectedKeys() []K

func (Model[K, V]) Items

func (m Model[K, V]) Items() map[K]V

Items returns the current items.

func (*Model[K, V]) MoveDown

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

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

func (*Model[K, V]) MoveUp

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

MoveUp moves the highlightion up by any number of rows. It can not go above the first row.

func (*Model[K, V]) SetColumns

func (m *Model[K, V]) SetColumns(c []Column)

SetColumns sets a new columns state.

func (*Model[K, V]) SetCursor

func (m *Model[K, V]) SetCursor(n int)

SetCursor sets the cursor position in the table.

func (*Model[K, V]) SetItems

func (m *Model[K, V]) SetItems(items map[K]V)

SetItems sets new items on the table, overwriting existing items.

func (*Model[K, V]) SetStyles

func (m *Model[K, V]) SetStyles(s Styles)

SetStyles sets the table styles.

func (*Model[K, V]) ToggleSelectAll

func (m *Model[K, V]) ToggleSelectAll()

ToggleSelectAll toggles the selection of all rows.

func (*Model[K, V]) ToggleSelection

func (m *Model[K, V]) ToggleSelection()

ToggleSelection toggles the selection of the currently highlighted row.

func (*Model[K, V]) ToggleSelectionByKey

func (m *Model[K, V]) ToggleSelectionByKey(key K)

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

func (Model[K, V]) Update

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

Update is the Bubble Tea update loop.

func (*Model[K, V]) UpdateViewport

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

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

func (Model[K, V]) View

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

View renders the component.

func (Model[K, V]) Width

func (m Model[K, V]) Width() int

Width returns the viewport width of the table.

func (Model[K, V]) WithFocused

func (m Model[K, V]) WithFocused(f bool) Model[K, V]

WithFocused sets the focus state of the table.

func (Model[K, V]) WithSelectable

func (m Model[K, V]) WithSelectable(s bool) Model[K, V]

WithSelectable sets whether rows are selectable.

func (Model[K, V]) WithSortFunc

func (m Model[K, V]) WithSortFunc(sortFunc func(V, V) int) Model[K, V]

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

func (Model[K, V]) WithStyles

func (m Model[K, V]) WithStyles(s Styles) Model[K, V]

WithStyles sets the table styles.

type RenderedRow

type RenderedRow map[ColumnKey]string

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

type Resource

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

Resource is a wrapper of table.Model specifically for use with pug resources.

func NewResource

func NewResource[K resource.ID, V ResourceValue](opts ResourceOptions[V]) Resource[K, V]

NewResource creates a new resource table

func (*Resource[K, V]) Prune added in v0.1.4

func (m *Resource[K, V]) Prune(fn func(value V) (resource.ID, error)) ([]resource.ID, error)

Prune passes each value from the selected rows (or if there are no selections, from the highlighted row) to the provided func. If the func returns an error the row is de-selected (or if there are no selections, then an error is returned). The resulting IDs from the provided func are returned. If all selections are de-selected then an error is returned.

func (*Resource[K, V]) SetItems

func (m *Resource[K, V]) SetItems(items map[K]V)

SetItems populates the table with the given items. Each item must be a descendent of the table's parent resource.

func (Resource[K, V]) Update

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

type ResourceOptions

type ResourceOptions[V ResourceValue] struct {
	Columns       []Column
	Renderer      RowRenderer[V]
	Width, Height int
	Parent        resource.Resource
	SortFunc      SortFunc[V]
}

type ResourceValue

type ResourceValue interface {
	HasAncestor(id resource.ID) bool
	RowKey() resource.ID
}

type Row

type Row[K comparable, V any] struct {
	Key   K
	Value V
}

type RowRenderer

type RowRenderer[V any] func(V) RenderedRow

type SortFunc

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

type Styles

type Styles struct {
	Header      lipgloss.Style
	Highlighted lipgloss.Style
	Selected    lipgloss.Style
}

Styles contains style definitions for this list component. By default, these values are generated by DefaultStyles.

func DefaultStyles

func DefaultStyles() Styles

DefaultStyles returns a set of default style definitions for this table.

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