1package commands
2
3import (
4 tea "github.com/charmbracelet/bubbletea/v2"
5 "github.com/charmbracelet/crush/internal/tui/components/core"
6 "github.com/charmbracelet/crush/internal/tui/components/core/list"
7 "github.com/charmbracelet/crush/internal/tui/layout"
8 "github.com/charmbracelet/crush/internal/tui/styles"
9 "github.com/charmbracelet/crush/internal/tui/util"
10 "github.com/charmbracelet/x/ansi"
11)
12
13type ItemSection interface {
14 util.Model
15 layout.Sizeable
16 list.SectionHeader
17}
18type itemSectionModel struct {
19 width int
20 title string
21 noPadding bool // No padding for the section header
22}
23
24func NewItemSection(title string) ItemSection {
25 return &itemSectionModel{
26 title: title,
27 }
28}
29
30func (m *itemSectionModel) Init() tea.Cmd {
31 return nil
32}
33
34func (m *itemSectionModel) Update(tea.Msg) (tea.Model, tea.Cmd) {
35 return m, nil
36}
37
38func (m *itemSectionModel) View() tea.View {
39 t := styles.CurrentTheme()
40 title := ansi.Truncate(m.title, m.width-2, "…")
41 style := t.S().Base.Padding(1, 1, 0, 1)
42 title = t.S().Muted.Render(title)
43 return tea.NewView(style.Render(core.Section(title, m.width-2)))
44}
45
46func (m *itemSectionModel) GetSize() (int, int) {
47 return m.width, 1
48}
49
50func (m *itemSectionModel) SetSize(width int, height int) tea.Cmd {
51 m.width = width
52 return nil
53}
54
55func (m *itemSectionModel) IsSectionHeader() bool {
56 return true
57}