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.FullKey = c.Styles.HelpKey
21	f := &Footer{
22		common: c,
23		help:   h,
24		keymap: keymap,
25	}
26	return f
27}
28
29// SetSize implements common.Component.
30func (f *Footer) SetSize(width, height int) {
31	f.common.Width = width
32	f.common.Height = height
33}
34
35// Init implements tea.Model.
36func (f *Footer) Init() tea.Cmd {
37	return nil
38}
39
40// Update implements tea.Model.
41func (f *Footer) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
42	return f, nil
43}
44
45// View implements tea.Model.
46func (f *Footer) View() string {
47	if f.keymap == nil {
48		return ""
49	}
50	s := f.common.Styles.Footer.Copy().Width(f.common.Width)
51	return s.Render(f.help.View(f.keymap))
52}