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

bounded

package
v0.0.51 Latest Latest
Warning

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

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

Documentation

Overview

Package bounded provides pointer-owned, ANSI-aware bounded terminal controls.

Viewport offsets and List logical selection are independent. ViewportView is a contentless projection over lines supplied by its caller for each render; ListView contains ListRow metadata. Layout is measured in terminal display cells and invalid geometry produces an empty view. Item IDs must be unique and stable across refreshes: refreshes preserve the selected ID and top-visible semantic anchor; a missing selection adopts its clamped replacement and does not snap back. Lists configure one selection cell plus zero to two status cells. ListItem status cells are opaque one-display-cell markers; invalid, multi-cell, or multiline values are omitted before ListRow projects them. Callers own selected styling and hit regions. Controls are stateful and pointer-owned; they have no Bubble Tea, theme, or Mecatl domain dependency.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type List

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

List manages selectable items in a bounded viewport.

func (*List) Cursor

func (l *List) Cursor() int

Cursor returns the selected item index.

func (*List) CursorID

func (l *List) CursorID() string

CursorID returns the selected item ID.

func (*List) Height

func (l *List) Height() int

Height returns the configured list viewport height.

func (*List) Move

func (l *List) Move(move Move)

Move changes the selection or pages through the list.

func (*List) Offset

func (l *List) Offset() int

Offset returns the list's current scroll offset.

func (*List) RevealPending

func (l *List) RevealPending() bool

RevealPending reports whether the cursor should be brought into view.

func (*List) Scroll

func (l *List) Scroll(move Move)

Scroll moves the list viewport without changing the selection.

func (*List) SetCursor

func (l *List) SetCursor(index int)

SetCursor selects the item at index and reveals it.

func (*List) SetGeometry

func (l *List) SetGeometry(width, height, gutterCells int, policy Policy)

SetGeometry configures the list viewport dimensions, gutter-cell count, and fitting policy. Every list has one selection cell and zero to two status cells; a trailing padding cell separates that gutter from content.

func (*List) SetItems

func (l *List) SetItems(items []ListItem)

SetItems replaces the list contents while preserving compatible viewport anchors.

func (*List) Valid

func (l *List) Valid() bool

Valid reports whether the list viewport has usable dimensions.

func (*List) View

func (l *List) View() ListView

View returns the visible list rows and the counts outside the viewport.

func (*List) ViewWithIndicators

func (l *List) ViewWithIndicators(capacity int, reveal bool) ListView

ViewWithIndicators applies the shared logical-item indicator policy. Indicators report only complete items outside the physical window; partial oversized-item segments remain reachable through normal paging rather than becoming overflow.

type ListItem

type ListItem struct {
	ID, Text    string
	StatusCells [2]string
}

ListItem is an entry rendered by a List. StatusCells are optional one-display-cell markers for the two cells after the selection cell; invalid markers are omitted.

type ListRow

type ListRow struct {
	Text, ID               string
	ItemIndex, ItemLine    int
	Selected, CursorMarker bool
	StatusCells            [2]string
	GutterCells            int
}

ListRow is one rendered line in a ListView. StatusCells and GutterCells are presentation metadata: the caller renders their cells. GutterCells is always in [1, 3], and StatusCells contain only valid one-display-cell markers.

type ListView

type ListView struct {
	Rows         []ListRow
	Above, Below int
}

ListView is the bounded portion of a list and its scroll indicators.

type Move

type Move uint8

Move identifies a viewport navigation operation.

const (
	LineUp Move = iota
	LineDown
	PageUp
	PageDown
	Top
	End
)

Viewport navigation operations.

type Policy

type Policy uint8

Policy controls how content is fitted to the viewport.

const (
	Wrap Policy = iota
	Clip
)

Content fitting policies.

type Viewport

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

Viewport tracks the visible window over caller-provided laid-out lines.

func (*Viewport) Clamp

func (v *Viewport) Clamp(total int)

Clamp constrains the current offset to the configured geometry and content size.

func (*Viewport) Height

func (v *Viewport) Height() int

Height returns the configured viewport height.

func (*Viewport) Move

func (v *Viewport) Move(move Move, total int)

Move scrolls the viewport according to move.

func (*Viewport) Offset

func (v *Viewport) Offset() int

Offset returns the current scroll offset.

func (*Viewport) Reset

func (v *Viewport) Reset()

Reset scrolls the viewport to its beginning.

func (*Viewport) SetGeometry

func (v *Viewport) SetGeometry(width, height, gutter int, policy Policy)

SetGeometry configures the viewport dimensions and fitting policy.

func (*Viewport) SetOffset added in v0.0.45

func (v *Viewport) SetOffset(offset, total int)

SetOffset positions the viewport at a physical row, clamped to its content.

func (*Viewport) Valid

func (v *Viewport) Valid() bool

Valid reports whether the viewport has usable dimensions.

func (*Viewport) View

func (v *Viewport) View(lines []string) ViewportView

View returns the bounded projection of lines. Callers provide lines for each render.

type ViewportView

type ViewportView struct {
	Rows         []string
	Above, Below int
}

ViewportView is the bounded projection of caller-provided lines.

Jump to

Keyboard shortcuts

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