list.go

 1package list
 2
 3import (
 4	tea "github.com/charmbracelet/bubbletea/v2"
 5	"github.com/charmbracelet/crush/internal/tui/components/core/layout"
 6	"github.com/charmbracelet/crush/internal/tui/util"
 7)
 8
 9type Item interface {
10	util.Model
11	layout.Sizeable
12}
13
14type List interface {
15	util.Model
16}
17
18type list struct {
19	width, height int
20	gap           int
21
22	items []Item
23
24	// Filter options
25	filterable        bool
26	filterPlaceholder string
27}
28
29type listOption func(*list)
30
31// WithFilterable enables filtering on the list.
32func WithFilterable(placeholder string) listOption {
33	return func(l *list) {
34		l.filterable = true
35		l.filterPlaceholder = placeholder
36	}
37}
38
39// WithItems sets the initial items for the list.
40func WithItems(items ...Item) listOption {
41	return func(l *list) {
42		l.items = items
43	}
44}
45
46// WithSize sets the size of the list.
47func WithSize(width, height int) listOption {
48	return func(l *list) {
49		l.width = width
50		l.height = height
51	}
52}
53
54// WithGap sets the gap between items in the list.
55func WithGap(gap int) listOption {
56	return func(l *list) {
57		l.gap = gap
58	}
59}
60
61func New(opts ...listOption) List {
62	list := &list{
63		items: make([]Item, 0),
64	}
65	for _, opt := range opts {
66		opt(list)
67	}
68	return list
69}
70
71// Init implements List.
72func (l *list) Init() tea.Cmd {
73	if l.height <= 0 || l.width <= 0 {
74		return nil
75	}
76	return nil
77}
78
79// Update implements List.
80func (l *list) Update(tea.Msg) (tea.Model, tea.Cmd) {
81	panic("unimplemented")
82}
83
84// View implements List.
85func (l *list) View() string {
86	panic("unimplemented")
87}