list

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AdjustArea

func AdjustArea(area image.Rectangle, style lipgloss.Style) image.Rectangle

AdjustArea adjusts the given area rectangle by subtracting margins, borders, and padding from the style.

func Highlight

func Highlight(content string, area image.Rectangle, startLine, startCol, endLine, endCol int, highlighter Highlighter) string

Highlight highlights a region of text within the given content and region.

func HighlightBuffer

func HighlightBuffer(content string, area image.Rectangle, startLine, startCol, endLine, endCol int, highlighter Highlighter) *uv.ScreenBuffer

HighlightBuffer highlights a region of text within the given content and region, returning a uv.ScreenBuffer.

func HighlightContent

func HighlightContent(content string, area image.Rectangle, startLine, startCol, endLine, endCol int) string

HighlightContent returns the content with highlighted regions based on the specified parameters.

func ToStyle

func ToStyle(lgStyle lipgloss.Style) uv.Style

ToStyle converts an inline lipgloss.Style to a uv.Style.

Types

type FilterableItem

type FilterableItem interface {
	Item
	// Filter returns the value to be used for filtering.
	Filter() string
}

FilterableItem is an item that can be filtered via a query.

type FilterableItemsSource

type FilterableItemsSource []FilterableItem

FilterableItemsSource is a type that implements fuzzy.Source for filtering [FilterableItem]s.

func (FilterableItemsSource) Len

func (f FilterableItemsSource) Len() int

Len returns the length of the source.

func (FilterableItemsSource) String

func (f FilterableItemsSource) String(i int) string

String returns the string representation of the item at index i.

type FilterableList

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

FilterableList is a list that takes filterable items that can be filtered via a settable query.

func NewFilterableList

func NewFilterableList(items ...FilterableItem) *FilterableList

NewFilterableList creates a new filterable list.

func (*FilterableList) AppendItems

func (f *FilterableList) AppendItems(items ...FilterableItem)

AppendItems appends items to the list and updates the filtered items.

func (*FilterableList) FilteredItems

func (f *FilterableList) FilteredItems() []Item

FilteredItems returns the visible items after filtering.

func (*FilterableList) PrependItems

func (f *FilterableList) PrependItems(items ...FilterableItem)

PrependItems prepends items to the list and updates the filtered items.

func (*FilterableList) Render

func (f *FilterableList) Render() string

Render renders the filterable list.

func (*FilterableList) SetFilter

func (f *FilterableList) SetFilter(q string)

SetFilter sets the filter query and updates the list items.

func (*FilterableList) SetItems

func (f *FilterableList) SetItems(items ...FilterableItem)

SetItems sets the list items and updates the filtered items.

type Focusable

type Focusable interface {
	// SetFocused sets the focus state of the item.
	SetFocused(focused bool)
}

Focusable represents an item that can be aware of focus state changes.

type Highlightable

type Highlightable interface {
	// SetHighlight highlights the content from the given start to end
	// positions. Use -1 for no highlight.
	SetHighlight(startLine, startCol, endLine, endCol int)
	// Highlight returns the current highlight positions within the item.
	Highlight() (startLine, startCol, endLine, endCol int)
}

Highlightable represents an item that can highlight a portion of its content.

type Highlighter

type Highlighter func(x, y int, c *uv.Cell) *uv.Cell

Highlighter represents a function that defines how to highlight text.

var DefaultHighlighter Highlighter = func(x, y int, c *uv.Cell) *uv.Cell {
	if c == nil {
		return c
	}
	c.Style.Attrs |= uv.AttrReverse
	return c
}

DefaultHighlighter is the default highlighter function that applies inverse style.

func ToHighlighter

func ToHighlighter(lgStyle lipgloss.Style) Highlighter

ToHighlighter converts a lipgloss.Style to a Highlighter.

type Item

type Item interface {
	// Render returns the string representation of the item for the given
	// width.
	Render(width int) string

	// Version returns a monotonic counter that the list-level cache
	// uses to detect mutations. Items must increment the version
	// (via Versioned.Bump) on every state change that would alter
	// the rendered output.
	Version() uint64

	// Finished reports whether the item's rendered output has reached
	// a terminal state and may be frozen by the list cache. Items
	// that animate, stream, or otherwise still mutate must return
	// false. A finished item that later mutates must bump its
	// version on the mutation; the cache treats version bumps as
	// implicit unfreeze + invalidate.
	Finished() bool
}

Item represents a single item in the lazy-loaded list.

Items participate in the list-level render memo (F6). The cache key for each item is (pointer, width, version). Items must:

  • Bump their version (via the embedded *Versioned helper) on every mutation that changes the rendered output.
  • Return Finished() == true once their rendered output will not change again unless an explicit mutator is invoked. Frozen entries are emitted verbatim — no Render call — until either Version() bumps, the viewport width changes, or the list explicitly invalidates the entry.

type List

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

List represents a list of items that can be lazily rendered. A list is always rendered like a chat conversation where items are stacked vertically from top to bottom.

func NewList

func NewList(items ...Item) *List

NewList creates a new lazy-loaded list.

func (*List) AppendItems

func (l *List) AppendItems(items ...Item)

AppendItems appends items to the list.

func (*List) AtBottom

func (l *List) AtBottom() bool

AtBottom returns whether the list is showing the last item at the bottom.

func (*List) BeginSelectionDrag

func (l *List) BeginSelectionDrag(startIdx, endIdx int)

BeginSelectionDrag marks the items in the inclusive [startIdx, endIdx] range as un-freezable for the duration of an active selection drag. Frozen entries inside the range are dropped so the next render reflects live selection-overlay output. The corresponding EndSelectionDrag clears the suppression set and lets items re-freeze on their next render. Indices outside the items slice are clipped silently.

func (*List) Blur

func (l *List) Blur()

Blur removes the focus state from the list.

func (*List) EndSelectionDrag

func (l *List) EndSelectionDrag()

EndSelectionDrag clears the selection-drag freeze suppression. Items inside the previous range will re-freeze on their next render once their Finished() reports true again.

func (*List) Focus

func (l *List) Focus()

Focus sets the focus state of the list.

func (*List) Focused

func (l *List) Focused() bool

Focused returns whether the list is focused.

func (*List) Gap

func (l *List) Gap() int

Gap returns the gap between items.

func (*List) Height

func (l *List) Height() int

Height returns the height of the list viewport.

func (*List) InsertItems

func (l *List) InsertItems(at int, items ...Item)

InsertItems inserts items at the given index, shifting subsequent items down.

func (*List) Invalidate

func (l *List) Invalidate(item Item)

Invalidate drops the cache entry for the given item, forcing a re-render on the next getItem call. No-op if the item is not in the cache.

func (*List) InvalidateFrozen

func (l *List) InvalidateFrozen(item Item)

InvalidateFrozen drops the frozen flag (and stored content) for the given item. Equivalent to Invalidate but exposed under the F6 frozen-items vocabulary so external callers can express intent.

func (*List) IsSelectedFirst

func (l *List) IsSelectedFirst() bool

IsSelectedFirst returns whether the first item is selected.

func (*List) IsSelectedLast

func (l *List) IsSelectedLast() bool

IsSelectedLast returns whether the last item is selected.

func (*List) ItemAt

func (l *List) ItemAt(index int) Item

ItemAt returns the item at the given index.

func (*List) ItemIndexAtPosition

func (l *List) ItemIndexAtPosition(x, y int) (itemIdx int, itemY int)

ItemIndexAtPosition returns the item at the given viewport-relative y coordinate. Returns the item index and the y offset within that item. It returns -1, -1 if no item is found.

func (*List) Len

func (l *List) Len() int

Len returns the number of items in the list.

func (*List) Offset

func (l *List) Offset() int

Offset returns the current scroll offset in lines from the top.

func (*List) PrependItems

func (l *List) PrependItems(items ...Item)

PrependItems prepends items to the list.

func (*List) RegisterRenderCallback

func (l *List) RegisterRenderCallback(cb RenderCallback)

RegisterRenderCallback registers a callback to be called when rendering items. This can be used to modify items before they are rendered.

func (*List) RemoveItem

func (l *List) RemoveItem(idx int)

RemoveItem removes the item at the given index from the list.

func (*List) Render

func (l *List) Render() string

Render renders the list and returns the visible lines.

F7: per-item slicing is bounded by the remaining viewport budget so per-frame work is O(viewport) rather than O(total item heights). We never append beyond l.height lines to the output buffer; the final trim is therefore unnecessary. Reverse mode applies the same final reversal as before, which is byte-identical because the pre-F7 trim happened at the tail of the joined buffer (the same lines we now drop implicitly per item).

func (*List) ScrollBy

func (l *List) ScrollBy(lines int)

ScrollBy scrolls the list by the given number of lines.

func (*List) ScrollToBottom

func (l *List) ScrollToBottom()

ScrollToBottom scrolls the list to the bottom.

func (*List) ScrollToIndex

func (l *List) ScrollToIndex(index int)

ScrollToIndex scrolls the list to the given item index.

func (*List) ScrollToSelected

func (l *List) ScrollToSelected()

ScrollToSelected scrolls the list to the selected item.

func (*List) ScrollToTop

func (l *List) ScrollToTop()

ScrollToTop scrolls the list to the top.

func (*List) SelectFirst

func (l *List) SelectFirst() bool

SelectFirst selects the first item in the list. It returns whether the selection changed.

func (*List) SelectFirstInView

func (l *List) SelectFirstInView()

SelectFirstInView selects the first item currently in view.

func (*List) SelectLast

func (l *List) SelectLast() bool

SelectLast selects the last item in the list (highest index). It returns whether the selection changed.

func (*List) SelectLastInView

func (l *List) SelectLastInView()

SelectLastInView selects the last item currently in view.

func (*List) SelectNext

func (l *List) SelectNext() bool

SelectNext selects the next item in the list. It returns whether the selection changed.

func (*List) SelectNextCyclic

func (l *List) SelectNextCyclic()

SelectNextCyclic selects the visually next item, wrapping to the visual start if the visual end is currently selected, and scrolls the new selection into view.

func (*List) SelectPrev

func (l *List) SelectPrev() bool

SelectPrev selects the visually previous item (moves toward visual top). It returns whether the selection changed.

func (*List) SelectPrevCyclic

func (l *List) SelectPrevCyclic()

SelectPrevCyclic selects the visually previous item, wrapping to the visual end if the visual start is currently selected, and scrolls the new selection into view.

func (*List) Selected

func (l *List) Selected() int

Selected returns the index of the currently selected item. It returns -1 if no item is selected.

func (*List) SelectedItem

func (l *List) SelectedItem() Item

SelectedItem returns the currently selected item. It may be nil if no item is selected.

func (*List) SelectedItemInView

func (l *List) SelectedItemInView() bool

SelectedItemInView returns whether the selected item is currently in view.

func (*List) SetGap

func (l *List) SetGap(gap int)

SetGap sets the gap between items.

func (*List) SetItems

func (l *List) SetItems(items ...Item)

SetItems sets the items in the list. Cache entries for items that remain after the swap are preserved; entries for removed items are dropped.

func (*List) SetReverse

func (l *List) SetReverse(reverse bool)

SetReverse shows the list in reverse order.

func (*List) SetSelected

func (l *List) SetSelected(index int)

SetSelected sets the selected item index in the list. It returns -1 if the index is out of bounds.

func (*List) SetSize

func (l *List) SetSize(width, height int)

SetSize sets the size of the list viewport. A width change drops the entire render cache because every entry's wrapped output depends on width; a height-only change is a no-op for the cache.

func (*List) TotalHeight

func (l *List) TotalHeight() int

TotalHeight returns the total height of all items in the list.

func (*List) VisibleItemIndices

func (l *List) VisibleItemIndices() (startIdx, endIdx int)

VisibleItemIndices finds the range of items that are visible in the viewport. This is used for checking if selected item is in view.

func (*List) Width

func (l *List) Width() int

Width returns the width of the list viewport.

func (*List) WrapToEnd

func (l *List) WrapToEnd() bool

WrapToEnd wraps selection to the visual end (for circular navigation). In normal mode, this is the highest index. In reverse mode, this is index 0.

func (*List) WrapToStart

func (l *List) WrapToStart() bool

WrapToStart wraps selection to the visual start (for circular navigation). In normal mode, this is index 0. In reverse mode, this is the highest index.

type MatchSettable

type MatchSettable interface {
	SetMatch(fuzzy.Match)
}

MatchSettable is an interface for items that can have their match indexes and match score set.

type MouseClickable

type MouseClickable interface {
	// HandleMouseClick processes a mouse click event at the given coordinates.
	// It returns true if the event was handled, false otherwise.
	HandleMouseClick(btn ansi.MouseButton, x, y int) bool
}

MouseClickable represents an item that can handle mouse click events.

type RawRenderable

type RawRenderable interface {
	// RawRender returns the raw rendered string without any additional
	// styling.
	RawRender(width int) string
}

RawRenderable represents an item that can provide a raw rendering without additional styling.

type RenderCallback

type RenderCallback func(idx, selectedIdx int, item Item) Item

RenderCallback defines a function that can modify an item before it is rendered.

func FocusedRenderCallback

func FocusedRenderCallback(list *List) RenderCallback

FocusedRenderCallback is a helper function that returns a render callback that marks items as focused during rendering.

type SpacerItem

type SpacerItem struct {
	*Versioned
	Height int
}

SpacerItem is a spacer item that adds vertical space in the list.

func NewSpacerItem

func NewSpacerItem(height int) *SpacerItem

NewSpacerItem creates a new SpacerItem with the specified height.

func (*SpacerItem) Finished

func (s *SpacerItem) Finished() bool

Finished implements Item. SpacerItems are immutable in practice and safe to freeze; any mutation goes through Versioned.Bump which invalidates the frozen entry.

func (*SpacerItem) Render

func (s *SpacerItem) Render(width int) string

Render implements the Item interface for SpacerItem.

type Versioned

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

Versioned is a tiny embeddable helper that satisfies Item.Version() and provides a Bump() method to call from every state-mutating method. Items typically embed *Versioned alongside their other helpers; see chat.AssistantMessageItem for the canonical wiring.

Bump() is not safe for concurrent use; callers must hold whatever synchronization their item type already requires for state mutations. The list itself never reads Version() from a goroutine other than the UI thread.

func NewVersioned

func NewVersioned() *Versioned

NewVersioned returns a fresh *Versioned at version zero.

func (*Versioned) Bump

func (vc *Versioned) Bump()

Bump advances the version counter by one. Mutators on items that affect the rendered output must call Bump exactly once per observable state change. Bumping more than once per change is harmless other than a single extra cache miss.

func (*Versioned) Version

func (vc *Versioned) Version() uint64

Version returns the current version counter.

Jump to

Keyboard shortcuts

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