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/server/ui/common"
9)
10
11// ToggleFooterMsg is a message sent to show/hide the footer.
12type ToggleFooterMsg struct{}
13
14// Footer is a Bubble Tea model that displays help and other info.
15type Footer struct {
16 common common.Common
17 help help.Model
18 keymap help.KeyMap
19}
20
21// New creates a new Footer.
22func New(c common.Common, keymap help.KeyMap) *Footer {
23 h := help.New()
24 h.Styles.ShortKey = c.Styles.HelpKey
25 h.Styles.ShortDesc = c.Styles.HelpValue
26 h.Styles.FullKey = c.Styles.HelpKey
27 h.Styles.FullDesc = c.Styles.HelpValue
28 f := &Footer{
29 common: c,
30 help: h,
31 keymap: keymap,
32 }
33 f.SetSize(c.Width, c.Height)
34 return f
35}
36
37// SetSize implements common.Component.
38func (f *Footer) SetSize(width, height int) {
39 f.common.SetSize(width, height)
40 f.help.Width = width -
41 f.common.Styles.Footer.GetHorizontalFrameSize()
42}
43
44// Init implements tea.Model.
45func (f *Footer) Init() tea.Cmd {
46 return nil
47}
48
49// Update implements tea.Model.
50func (f *Footer) Update(_ tea.Msg) (tea.Model, tea.Cmd) {
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().
60 Width(f.common.Width)
61 helpView := f.help.View(f.keymap)
62 return f.common.Zone.Mark(
63 "footer",
64 s.Render(helpView),
65 )
66}
67
68// ShortHelp returns the short help key bindings.
69func (f *Footer) ShortHelp() []key.Binding {
70 return f.keymap.ShortHelp()
71}
72
73// FullHelp returns the full help key bindings.
74func (f *Footer) FullHelp() [][]key.Binding {
75 return f.keymap.FullHelp()
76}
77
78// ShowAll returns whether the full help is shown.
79func (f *Footer) ShowAll() bool {
80 return f.help.ShowAll
81}
82
83// SetShowAll sets whether the full help is shown.
84func (f *Footer) SetShowAll(show bool) {
85 f.help.ShowAll = show
86}
87
88// Height returns the height of the footer.
89func (f *Footer) Height() int {
90 return lipgloss.Height(f.View())
91}
92
93// ToggleFooterCmd sends a ToggleFooterMsg to show/hide the help footer.
94func ToggleFooterCmd() tea.Msg {
95 return ToggleFooterMsg{}
96}