Help us shape the future of Go! Take the 2026 Go Developer Survey

listview

package
v1.47.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package listview provides lazy terminal list navigation and loaded-page rendering.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RenderLabels

func RenderLabels(items []gjson.Result, transform transformers.Transformer, opts clioutput.ReadableOptions) (string, error)

RenderLabels preserves complete values independently of table widths.

func RenderTable

func RenderTable(ctx context.Context, operation string, items []gjson.Result, width int, diagnostics bool, style Style) (string, bool, error)

RenderTable only presents loaded API items. The caller owns routing, automatic-terminal selection, fetching, cancellation, and fallback output.

func Run

func Run(opts Options, fetch func() (Page, error), cancel context.CancelFunc) error

Run owns the terminal event loop and restores it before final printing.

func ShowPages

func ShowPages[P JSONListPage[P]](first func(context.Context) (P, error), itemsToDisplay int64, opts Options, cursorField string) error

ShowPages requests pages only when the viewer needs them. The first request receives the same cancelable context as all subsequent SDK requests. cursorField is empty for item-ID cursors, or the SDK's envelope cursor field.

Types

type JSONListPage

type JSONListPage[P any] interface {
	comparable
	RawJSON() string
	GetNextPage() (P, error)
}

JSONListPage is implemented by the SDK's explicit API page types.

type Model

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

Model owns navigation state and the lifetime of its single fetch worker.

func New

func New(opts Options, fetch func() (Page, error), cancel context.CancelFunc, width, height int) *Model

New constructs the loaded-page event model without taking terminal ownership. The caller must call Finish after its event loop restores the terminal.

func (*Model) Finish

func (m *Model) Finish(outputErr, runErr error) error

Finish cancels and joins the worker, retains failures, and prints after restoration.

func (*Model) Init

func (m *Model) Init() tea.Cmd

func (*Model) Update

func (m *Model) Update(message tea.Msg) (tea.Model, tea.Cmd)

func (*Model) View

func (m *Model) View() tea.View

type Options

type Options struct {
	Context    context.Context
	Stdout     io.Writer
	Style      Style
	RenderPage func([]gjson.Result, int) (string, error)
	Interrupt  func(error) error
	// The caller cancels Context on process signals and retains their exit status.
	CallerHandlesSignals bool
}

Options supplies presentation and feature policy for the shared viewer. Context and render functions must be non-nil. Stdout must be a terminal file when used by Run; New also permits buffered output for an embedded event loop.

type Page

type Page struct {
	Items []gjson.Result
	More  bool
	// Line and half-page keys can cross a local page boundary without making a request.
	Local bool
}

Page contains loaded records and whether another page can be requested.

type PaginationError

type PaginationError struct{}

PaginationError is a fixed diagnostic that never includes API cursors or response data.

func (*PaginationError) Error

func (*PaginationError) Error() string

type Style added in v1.43.2

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

Style decorates list presentation after layout. Its zero value preserves plain output.

func NewStyle added in v1.43.2

func NewStyle(profile colorprofile.Profile, dark bool) Style

NewStyle uses the same normal-weight blue and secondary colors as command help.

func (Style) Note added in v1.43.2

func (s Style) Note(content string) string

Note colors secondary text without changing its whitespace.

func (Style) Table added in v1.43.2

func (s Style) Table(content string) string

Table colors only the header of a nonempty table, preserving every data row.

Jump to

Keyboard shortcuts

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