footer.go

 1package footer
 2
 3import (
 4	"github.com/charmbracelet/bubbles/help"
 5	tea "github.com/charmbracelet/bubbletea"
 6	"github.com/charmbracelet/soft-serve/ui/common"
 7)
 8
 9// Footer is a Bubble Tea model that displays help and other info.
10type Footer struct {
11	common common.Common
12	help   help.Model
13	keymap help.KeyMap
14}
15
16// New creates a new Footer.
17func New(c common.Common, keymap help.KeyMap) *Footer {
18	h := help.New()
19	h.Styles.ShortKey = c.Styles.HelpKey
20	h.Styles.ShortDesc = c.Styles.HelpValue
21	h.Styles.FullKey = c.Styles.HelpKey
22	h.Styles.FullDesc = c.Styles.HelpValue
23	f := &Footer{
24		common: c,
25		help:   h,
26		keymap: keymap,
27	}
28	return f
29}
30
31// SetSize implements common.Component.
32func (f *Footer) SetSize(width, height int) {
33	f.common.Width = width
34	f.common.Height = height
35}
36
37// Init implements tea.Model.
38func (f *Footer) Init() tea.Cmd {
39	return nil
40}
41
42// Update implements tea.Model.
43func (f *Footer) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
44	switch msg := msg.(type) {
45	case tea.KeyMsg:
46		switch msg.String() {
47		case "?":
48			f.help.ShowAll = !f.help.ShowAll
49		}
50	}
51	return f, nil
52}
53
54// View implements tea.Model.
55func (f *Footer) View() string {
56	if f.keymap == nil {
57		return ""
58	}
59	s := f.common.Styles.Footer.Copy().Width(f.common.Width)
60	return s.Render(f.help.View(f.keymap))
61}