item.go

 1package list
 2
 3import (
 4	"github.com/charmbracelet/x/ansi"
 5)
 6
 7// Item represents a single item in the lazy-loaded list.
 8type Item interface {
 9	// Render returns the string representation of the item for the given
10	// width.
11	Render(width int) string
12}
13
14// Focusable represents an item that can be aware of focus state changes.
15type Focusable interface {
16	// SetFocused sets the focus state of the item.
17	SetFocused(focused bool)
18}
19
20// Highlightable represents an item that can highlight a portion of its content.
21type Highlightable interface {
22	// Highlight highlights the content from the given start to end positions.
23	// Use -1 for no highlight.
24	Highlight(startLine, startCol, endLine, endCol int)
25}
26
27// MouseClickable represents an item that can handle mouse click events.
28type MouseClickable interface {
29	// HandleMouseClick processes a mouse click event at the given coordinates.
30	// It returns true if the event was handled, false otherwise.
31	HandleMouseClick(btn ansi.MouseButton, x, y int) bool
32}