tableview

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2026 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NormalizeSelectedRow

func NormalizeSelectedRow(content string, selected lipgloss.Style) string

NormalizeSelectedRow ensures that selected rows emitted by the table component keep the highlight active across all columns when wrapped by another style.

func RegisterChildLoader

func RegisterChildLoader(parentType, field string, loader ChildLoader)

RegisterChildLoader associates a loader with a parent type and field label. Typically invoked from resource-specific packages during init.

func Render

func Render(streams *iostreams.IOStreams, data any, opts ...Option) error

Render displays structured data using the Bubble Tea table component when the output stream is a TTY. For non-interactive streams it falls back to a static table rendering with truncated columns.

func RenderForFormat

func RenderForFormat(
	helper cmdpkg.Helper,
	interactive bool,
	outType cmdCommon.OutputFormat,
	printer cli.PrintFlusher,
	streams *iostreams.IOStreams,
	display any,
	raw any,
	title string,
	extraOpts ...Option,
) error

RenderForFormat renders structured data according to the requested output format. For interactive output it delegates to Render, otherwise it uses the provided printer.

Types

type ChildLoader

type ChildLoader func(ctx context.Context, helper cmd.Helper, parent any) (ChildView, error)

ChildLoader knows how to fetch and render nested resources for a specific parent field.

type ChildView

type ChildView struct {
	Headers        []string
	Rows           []table.Row
	DetailRenderer DetailRenderer
	Title          string
	ParentType     string
	DetailContext  DetailContextProvider
	Mode           ChildViewMode
}

func HelperLoader

func HelperLoader(headers []string, rows [][]string, detail DetailRenderer, title string) ChildView

HelperLoader is a convenience for loaders that already produce matrix data.

type ChildViewMode

type ChildViewMode int

ChildViewMode determines how a child view should be presented.

const (
	// ChildViewModeCollection renders the child as a tabular collection with selectable rows.
	ChildViewModeCollection ChildViewMode = iota
	// ChildViewModeDetail renders the child as another detail card view.
	ChildViewModeDetail
)

type DetailContextProvider

type DetailContextProvider func(index int) any

type DetailRenderer

type DetailRenderer func(index int) string

type Option

type Option func(*config)

Option allows configuring optional behaviour for the table renderer.

func WithCustomTable

func WithCustomTable(headers []string, rows []table.Row) Option

WithCustomTable allows overriding the automatically generated table columns/rows. The provided headers and rows are used only for the interactive table; other formats (text/json/yaml) continue to print the original display value.

func WithDetailContext

func WithDetailContext(parentType string, provider DetailContextProvider) Option

WithDetailContext provides parent objects for detail rows, enabling child loaders.

func WithDetailHelper

func WithDetailHelper(helper cmdpkg.Helper) Option

WithDetailHelper supplies the command helper used to resolve child loaders.

func WithDetailRenderer

func WithDetailRenderer(renderer DetailRenderer) Option

WithDetailRenderer enables a side-by-side detail view that updates as the table selection changes.

func WithFooter

func WithFooter(msg string) Option

WithFooter overrides the default footer message when running interactively.

func WithInitialRowSelection

func WithInitialRowSelection(index int, openChild bool) Option

WithInitialRowSelection positions the cursor on the provided row index and optionally opens the associated child view immediately when the interactive session starts.

func WithPreviewRenderer

func WithPreviewRenderer(renderer PreviewRenderer) Option

WithPreviewRenderer renders a preview panel above the table that updates with the current cursor position.

func WithProfileName

func WithProfileName(name string) Option

WithProfileName records the active configuration profile for display in the status area.

func WithRootLabel

func WithRootLabel(label string) Option

WithRootLabel sets the root segment for breadcrumb navigation.

func WithRowLoader

func WithRowLoader(loader RowLoader) Option

WithRowLoader registers a loader that creates a child collection view for the currently selected row when the user presses enter. The loader should return a fully populated ChildView that mirrors the interactive resource view to display.

func WithSelectionAction added in v1.3.0

func WithSelectionAction(action SelectionAction) Option

WithSelectionAction registers an action that can be invoked for the highlighted row.

func WithTableStretch

func WithTableStretch() Option

WithTableStretch expands the primary table to occupy the full available width.

func WithTitle

func WithTitle(title string) Option

WithTitle adds a title above the rendered table.

type PreviewRenderer

type PreviewRenderer func(index int) string

PreviewRenderer allows injecting a synthetic preview above the table that updates with the current cursor position.

type RowLoader

type RowLoader func(index int) (ChildView, error)

type SelectionAction added in v1.3.0

type SelectionAction struct {
	Key     string
	Help    string
	Resolve SelectionActionResolver
}

SelectionAction registers a keyboard action for the current row selection.

type SelectionActionCommand added in v1.3.0

type SelectionActionCommand struct {
	Title               string
	Label               string
	DefaultOutputFile   string
	DefaultNamespace    string
	IncludeChildren     bool
	IncludeChildrenText string
	Run                 SelectionActionRun
}

SelectionActionCommand configures the modal prompt and execution callback for an action.

type SelectionActionResolver added in v1.3.0

type SelectionActionResolver func(SelectionContext) (SelectionActionCommand, error)

SelectionActionResolver converts a highlighted row into an executable action.

type SelectionActionRun added in v1.3.0

type SelectionActionRun func(SelectionActionValues) error

SelectionActionRun executes a confirmed selection action.

type SelectionActionValues added in v1.3.0

type SelectionActionValues struct {
	OutputFile       string
	DefaultNamespace string
	IncludeChildren  bool
}

SelectionActionValues contains user-entered options collected by the action dialog.

type SelectionContext added in v1.3.0

type SelectionContext struct {
	ParentType string
	Parent     any
	Headers    []string
	Row        table.Row
	Label      string
	Index      int
}

SelectionContext describes the currently highlighted row for selection actions.

Jump to

Keyboard shortcuts

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