table

package
v1.21.98 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

README

Shared terminal tables

The table.Model consumes Clicky's api.TextTable and caller-supplied stable row IDs. It has no Bubble Tea dependency and can be used from either major version. The host owns data fetching, native query filters, ordering and sample navigation.

var view table.Model
if err := view.Set(api.NewTableFrom(rows), rowIDs); err != nil {
    return err
}
view.SetSize(80, 20) // e.g. from tea.WindowSizeMsg
view.Key("down")
output := view.View()

Set rejects missing or duplicate identities and keeps the selected identity through reordering. SetSize(width, height) records the viewport in terminal cells. View() prioritizes declared column order, hides default-hidden columns, respects column width limits and clips by terminal cells. Put identity, primary metric and status first. Additional fields belong in RowDetail() as well as the column picker of a web consumer.

Pass enter to open detail, esc to close it, and arrows or j/k to move or scroll. Detail scrolling stops at the last line that fits the viewport. A model in detail mode retains its inspected table when Set is called. The host should pin the corresponding sample and require an explicit resume action before applying a newer sample. Selected, Detail and DetailOffset are available for controlled host state.

go test ./tui/table

The focused tests cover stable selection, frozen detail, Unicode cell widths, narrow/wide terminals and scrolling through the final detail line.

Documentation

Overview

Package table provides a terminal table state usable from either Bubble Tea version.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Model

type Model struct {
	Table        api.TextTable
	IDs          []string
	Selected     string
	Detail       bool
	DetailOffset int
	// Width and Height are the viewport in terminal cells; see SetSize.
	Width, Height int
}

func (Model) Index

func (m Model) Index() int

func (*Model) Key

func (m *Model) Key(key string) bool

func (*Model) Set

func (m *Model) Set(data api.TextTable, ids []string) error

func (*Model) SetSize

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

SetSize records the viewport, for example from a tea.WindowSizeMsg, and keeps the detail offset within the content it now shows.

func (Model) View

func (m Model) View() string

Jump to

Keyboard shortcuts

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