Documentation
¶
Index ¶
- func AdjustArea(area image.Rectangle, style lipgloss.Style) image.Rectangle
- func Highlight(content string, area image.Rectangle, startLine, startCol, endLine, endCol int, ...) string
- func HighlightBuffer(content string, area image.Rectangle, startLine, startCol, endLine, endCol int, ...) *uv.ScreenBuffer
- func HighlightContent(content string, area image.Rectangle, startLine, startCol, endLine, endCol int) string
- func ToStyle(lgStyle lipgloss.Style) uv.Style
- type FilterableItem
- type FilterableItemsSource
- type FilterableList
- func (f *FilterableList) AppendItems(items ...FilterableItem)
- func (f *FilterableList) FilteredItems() []Item
- func (f *FilterableList) PrependItems(items ...FilterableItem)
- func (f *FilterableList) Render() string
- func (f *FilterableList) SetFilter(q string)
- func (f *FilterableList) SetItems(items ...FilterableItem)
- type Focusable
- type Highlightable
- type Highlighter
- type Item
- type List
- func (l *List) AppendItems(items ...Item)
- func (l *List) AtBottom() bool
- func (l *List) BeginSelectionDrag(startIdx, endIdx int)
- func (l *List) Blur()
- func (l *List) EndSelectionDrag()
- func (l *List) Focus()
- func (l *List) Focused() bool
- func (l *List) Gap() int
- func (l *List) Height() int
- func (l *List) InsertItems(at int, items ...Item)
- func (l *List) Invalidate(item Item)
- func (l *List) InvalidateFrozen(item Item)
- func (l *List) IsSelectedFirst() bool
- func (l *List) IsSelectedLast() bool
- func (l *List) ItemAt(index int) Item
- func (l *List) ItemIndexAtPosition(x, y int) (itemIdx int, itemY int)
- func (l *List) Len() int
- func (l *List) Offset() int
- func (l *List) PrependItems(items ...Item)
- func (l *List) RegisterRenderCallback(cb RenderCallback)
- func (l *List) RemoveItem(idx int)
- func (l *List) Render() string
- func (l *List) ScrollBy(lines int)
- func (l *List) ScrollToBottom()
- func (l *List) ScrollToIndex(index int)
- func (l *List) ScrollToSelected()
- func (l *List) ScrollToTop()
- func (l *List) SelectFirst() bool
- func (l *List) SelectFirstInView()
- func (l *List) SelectLast() bool
- func (l *List) SelectLastInView()
- func (l *List) SelectNext() bool
- func (l *List) SelectNextCyclic()
- func (l *List) SelectPrev() bool
- func (l *List) SelectPrevCyclic()
- func (l *List) Selected() int
- func (l *List) SelectedItem() Item
- func (l *List) SelectedItemInView() bool
- func (l *List) SetGap(gap int)
- func (l *List) SetItems(items ...Item)
- func (l *List) SetReverse(reverse bool)
- func (l *List) SetSelected(index int)
- func (l *List) SetSize(width, height int)
- func (l *List) TotalHeight() int
- func (l *List) VisibleItemIndices() (startIdx, endIdx int)
- func (l *List) Width() int
- func (l *List) WrapToEnd() bool
- func (l *List) WrapToStart() bool
- type MatchSettable
- type MouseClickable
- type RawRenderable
- type RenderCallback
- type SpacerItem
- type Versioned
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AdjustArea ¶
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.
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 ¶
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 (*List) AppendItems ¶
AppendItems appends items to the list.
func (*List) BeginSelectionDrag ¶
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) 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) InsertItems ¶
InsertItems inserts items at the given index, shifting subsequent items down.
func (*List) Invalidate ¶
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 ¶
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 ¶
IsSelectedFirst returns whether the first item is selected.
func (*List) IsSelectedLast ¶
IsSelectedLast returns whether the last item is selected.
func (*List) ItemIndexAtPosition ¶
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) PrependItems ¶
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 ¶
RemoveItem removes the item at the given index from the list.
func (*List) Render ¶
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) ScrollToBottom ¶
func (l *List) ScrollToBottom()
ScrollToBottom scrolls the list to the bottom.
func (*List) ScrollToIndex ¶
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) SelectFirst ¶
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 ¶
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 ¶
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 ¶
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 ¶
Selected returns the index of the currently selected item. It returns -1 if no item is selected.
func (*List) SelectedItem ¶
SelectedItem returns the currently selected item. It may be nil if no item is selected.
func (*List) SelectedItemInView ¶
SelectedItemInView returns whether the selected item is currently in view.
func (*List) SetItems ¶
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 ¶
SetReverse shows the list in reverse order.
func (*List) SetSelected ¶
SetSelected sets the selected item index in the list. It returns -1 if the index is out of bounds.
func (*List) SetSize ¶
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 ¶
TotalHeight returns the total height of all items in the list.
func (*List) VisibleItemIndices ¶
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) WrapToEnd ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.