1package footer
2
3import (
4 "github.com/charmbracelet/bubbles/help"
5 "github.com/charmbracelet/bubbles/key"
6 tea "github.com/charmbracelet/bubbletea"
7 "github.com/charmbracelet/lipgloss"
8 "github.com/charmbracelet/soft-serve/ui/common"
9)
10
11// Footer is a Bubble Tea model that displays help and other info.
12type Footer struct {
13 common common.Common
14 help help.Model
15 keymap help.KeyMap
16}
17
18// New creates a new Footer.
19func New(c common.Common, keymap help.KeyMap) *Footer {
20 h := help.New()
21 h.Styles.ShortKey = c.Styles.HelpKey
22 h.Styles.ShortDesc = c.Styles.HelpValue
23 h.Styles.FullKey = c.Styles.HelpKey
24 h.Styles.FullDesc = c.Styles.HelpValue
25 f := &Footer{
26 common: c,
27 help: h,
28 keymap: keymap,
29 }
30 f.SetSize(c.Width, c.Height)
31 return f
32}
33
34// SetSize implements common.Component.
35func (f *Footer) SetSize(width, height int) {
36 f.common.SetSize(width, height)
37 f.help.Width = width -
38 f.common.Styles.Footer.GetHorizontalFrameSize()
39}
40
41// Init implements tea.Model.
42func (f *Footer) Init() tea.Cmd {
43 return nil
44}
45
46// Update implements tea.Model.
47func (f *Footer) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
48 return f, nil
49}
50
51// View implements tea.Model.
52func (f *Footer) View() string {
53 if f.keymap == nil {
54 return ""
55 }
56 s := f.common.Styles.Footer.Copy().
57 Width(f.common.Width)
58 helpView := f.help.View(f.keymap)
59 return s.Render(helpView)
60}
61
62// ShortHelp returns the short help key bindings.
63func (f *Footer) ShortHelp() []key.Binding {
64 return f.keymap.ShortHelp()
65}
66
67// FullHelp returns the full help key bindings.
68func (f *Footer) FullHelp() [][]key.Binding {
69 return f.keymap.FullHelp()
70}
71
72// ShowAll returns whether the full help is shown.
73func (f *Footer) ShowAll() bool {
74 return f.help.ShowAll
75}
76
77// SetShowAll sets whether the full help is shown.
78func (f *Footer) SetShowAll(show bool) {
79 f.help.ShowAll = show
80}
81
82// Height returns the height of the footer.
83func (f *Footer) Height() int {
84 return lipgloss.Height(f.View())
85}