table

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2022 License: Apache-2.0 Imports: 11 Imported by: 6

README

Table

Go Reference

TUI table component for Bubble Tea applications.

This component is used in the Calyptia Cloud CLI under the top command.

https://user-images.githubusercontent.com/7969166/155205138-e205b38b-3631-43b2-a369-1f57914da838.mp4

Installation

go get github.com/calyptia/go-bubble-table

Example

For an example please take a look at the /example directory.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type KeyMap

type KeyMap struct {
	End      key.Binding
	Home     key.Binding
	PageDown key.Binding
	PageUp   key.Binding
	Down     key.Binding
	Up       key.Binding
	Right    key.Binding
	Left     key.Binding
}

KeyMap holds the key bindings for the table.

func DefaultKeyMap

func DefaultKeyMap() KeyMap

DefaultKeyMap used by the `New` constructor.

type Model

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

Model of a table component.

func New

func New(cols []string, width, height int) Model

New model.

func (Model) Cursor

func (m Model) Cursor() int

Cursor returns the index of the selected row.

func (Model) CursorIsAtBottom

func (m Model) CursorIsAtBottom() bool

CursorIsAtBottom of the table.

func (Model) CursorIsAtTop

func (m Model) CursorIsAtTop() bool

CursorIsAtTop of the table.

func (Model) CursorIsPastBottom

func (m Model) CursorIsPastBottom() bool

CursorIsPastBottom of the table.

func (*Model) GoBottom

func (m *Model) GoBottom()

GoBottom moves the selection to the last row.

func (*Model) GoDown

func (m *Model) GoDown()

GoDown moves the selection to the next row. It can not go below the last row.

func (*Model) GoLeft added in v0.2.0

func (m *Model) GoLeft()

func (*Model) GoPageDown

func (m *Model) GoPageDown()

GoPageDown moves the selection one page down. It can not go below the last row.

func (*Model) GoPageUp

func (m *Model) GoPageUp()

GoPageUp moves the selection one page up. It can not go above the first row.

func (*Model) GoRight added in v0.2.0

func (m *Model) GoRight()

func (*Model) GoTop

func (m *Model) GoTop()

GoTop moves the selection to the first row.

func (*Model) GoUp

func (m *Model) GoUp()

GoUp moves the selection to the previous row. It can not go above the first row.

func (Model) SelectedRow

func (m Model) SelectedRow() Row

SelectedRow returns the selected row. You can cast it to your own implementation.

func (*Model) SetRows

func (m *Model) SetRows(rows []Row)

SetRows of the table and makes sure to update the view and the selected row does not go out of bounds.

func (*Model) SetSize

func (m *Model) SetSize(width, height int)

SetSize of the table and makes sure to update the view and the selected row does not go out of bounds.

func (Model) Update

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

Update tea.Model implementor. It handles the key events.

func (Model) View

func (m Model) View() string

View tea.Model implementors. It renders the table inside a viewport.

type Row

type Row interface {
	// Render the row into the given tabwriter.
	// To render correctly, join each cell by a tab character '\t'.
	// Use `m.Cursor() == index` to determine if the row is selected.
	// Take a look at the `SimpleRow` implementation for an example.
	Render(w io.Writer, model Model, index int)
}

Row renderer.

type SimpleRow

type SimpleRow []any

SimpleRow is a set of cells that can be rendered into a table. It supports row highlight if selected.

func (SimpleRow) Render

func (row SimpleRow) Render(w io.Writer, model Model, index int)

Render a simple row.

type Styles

type Styles struct {
	Title       lipgloss.Style
	SelectedRow lipgloss.Style
}

Styles holds the styling for the table.

func DefaultStyles

func DefaultStyles() Styles

DefaultStyles used by the `New` constructor.

Directories

Path Synopsis
example module

Jump to

Keyboard shortcuts

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