table

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2022 License: MIT Imports: 5 Imported by: 95

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Border added in v0.2.0

type Border struct {
	Top         string
	Left        string
	Right       string
	Bottom      string
	TopRight    string
	TopLeft     string
	BottomRight string
	BottomLeft  string

	TopJunction    string
	LeftJunction   string
	RightJunction  string
	BottomJunction string

	InnerJunction string

	InnerDivider string
	// contains filtered or unexported fields
}

Border defines the borders in and around the table.

type Column added in v0.3.0

type Column struct {
	Title string
	Key   string
	Width int
	// contains filtered or unexported fields
}

Column is a column in the table.

func NewColumn added in v0.3.0

func NewColumn(key, title string, width int) Column

NewColumn creates a new column with the given information.

func (Column) WithStyle added in v0.5.0

func (c Column) WithStyle(style lipgloss.Style) Column

WithStyle applies a style to the column as a whole.

type KeyMap added in v0.4.0

type KeyMap struct {
	RowDown key.Binding
	RowUp   key.Binding

	RowSelectToggle key.Binding

	PageDown key.Binding
	PageUp   key.Binding
}

KeyMap defines the keybindings for the table when it's focused.

func DefaultKeyMap added in v0.4.0

func DefaultKeyMap() KeyMap

DefaultKeyMap returns a set of sensible defaults for controlling a focused table.

type Model

type Model struct {
	// contains filtered or unexported fields
}

Model is the main table model. Create using New().

func New

func New(columns []Column) Model

New creates a new table ready for further modifications.

func (Model) Border added in v0.2.0

func (m Model) Border(border Border) Model

Border uses the given border components to render the table.

func (Model) BorderDefault added in v0.2.0

func (m Model) BorderDefault() Model

BorderDefault uses the basic square border, useful to reset the border if it was changed somehow.

func (*Model) CurrentPage added in v0.5.0

func (m *Model) CurrentPage() int

CurrentPage returns the current page that the table is on, starting from an index of 1.

func (Model) Focused

func (m Model) Focused(focused bool) Model

Focused allows the table to show highlighted rows and take in controls of up/down/space/etc to let the user navigate the table and interact with it.

func (Model) HeaderStyle

func (m Model) HeaderStyle(style lipgloss.Style) Model

HeaderStyle sets the style to apply to the header text, such as color or bold.

func (Model) HighlightStyle

func (m Model) HighlightStyle(style lipgloss.Style) Model

HighlightStyle sets a custom style to use when the row is being highlighted by the cursor.

func (Model) HighlightedRow

func (m Model) HighlightedRow() Row

HighlightedRow returns the full Row that's currently highlighted by the user.

func (Model) Init

func (m Model) Init() tea.Cmd

Init initializes the table per the Bubble Tea architecture.

func (Model) KeyMap added in v0.4.0

func (m Model) KeyMap() KeyMap

KeyMap returns a copy of the current key map in use.

func (*Model) MaxPages added in v0.5.0

func (m *Model) MaxPages() int

MaxPages returns the maximum number of pages that are visible.

func (*Model) PageSize added in v0.5.0

func (m *Model) PageSize() int

PageSize returns the current page size for the table, or 0 if there is no pagination enabled.

func (Model) SelectableRows

func (m Model) SelectableRows(selectable bool) Model

SelectableRows sets whether or not rows are selectable. If set, adds a column in the front that acts as a checkbox and responds to controls if Focused.

func (Model) SelectedRows

func (m Model) SelectedRows() []Row

SelectedRows returns all rows that have been set as selected by the user.

func (*Model) TotalRows added in v0.5.0

func (m *Model) TotalRows() int

TotalRows returns the current total row count of the table. If the table is paginated, this is the total number of rows across all pages.

func (Model) Update

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

Update responds to input from the user or other messages from Bubble Tea.

func (Model) View

func (m Model) View() string

View renders the table. It does not end in a newline, so that it can be composed with other elements more consistently.

func (*Model) VisibleIndices added in v0.5.0

func (m *Model) VisibleIndices() (start, end int)

VisibleIndices returns the current visible rows by their 0 based index. Useful for custom pagination footers.

func (Model) WithKeyMap added in v0.4.0

func (m Model) WithKeyMap(keyMap KeyMap) Model

WithKeyMap sets the key map to use for controls when focused.

func (Model) WithNoPagination added in v0.5.0

func (m Model) WithNoPagination() Model

WithNoPagination disable pagination in the table.

func (Model) WithPageSize added in v0.5.0

func (m Model) WithPageSize(pageSize int) Model

WithPageSize enables pagination using the given page size.

func (Model) WithRows

func (m Model) WithRows(rows []Row) Model

WithRows sets the rows to show as data in the table.

func (Model) WithStaticFooter added in v0.4.0

func (m Model) WithStaticFooter(footer string) Model

WithStaticFooter adds a footer that only displays the given text.

type Row

type Row struct {
	Style lipgloss.Style
	Data  RowData
	// contains filtered or unexported fields
}

Row represents a row in the table with some data keyed to the table columns> Can have a style applied to it such as color/bold. Create using NewRow().

func NewRow

func NewRow(data RowData) Row

NewRow creates a new row and copies the given row data.

func (Row) WithStyle

func (r Row) WithStyle(style lipgloss.Style) Row

WithStyle uses the given style for the text in the row.

type RowData

type RowData map[string]interface{}

RowData is a map of string column keys to interface{} data.

type StyledCell added in v0.5.0

type StyledCell struct {
	Data  interface{}
	Style lipgloss.Style
}

func NewStyledCell added in v0.5.0

func NewStyledCell(data interface{}, style lipgloss.Style) StyledCell

Jump to

Keyboard shortcuts

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