1package statusbar
2
3import (
4 tea "github.com/charmbracelet/bubbletea"
5 "github.com/charmbracelet/lipgloss"
6 "github.com/charmbracelet/soft-serve/ui/common"
7)
8
9type StatusBarMsg struct {
10 Key string
11 Value string
12 Info string
13 Branch string
14}
15
16type StatusBar struct {
17 common common.Common
18 msg StatusBarMsg
19}
20
21type Model interface {
22 StatusBarValue() string
23 StatusBarInfo() string
24}
25
26func New(c common.Common) *StatusBar {
27 s := &StatusBar{
28 common: c,
29 }
30 return s
31}
32
33func (s *StatusBar) SetSize(width, height int) {
34 s.common.Width = width
35 s.common.Height = height
36}
37
38func (s *StatusBar) Init() tea.Cmd {
39 return nil
40}
41
42func (s *StatusBar) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
43 switch msg := msg.(type) {
44 case StatusBarMsg:
45 s.msg = msg
46 }
47 return s, nil
48}
49
50func (s *StatusBar) View() string {
51 st := s.common.Styles
52 w := lipgloss.Width
53 key := st.StatusBarKey.Render(s.msg.Key)
54 info := ""
55 if s.msg.Info != "" {
56 info = st.StatusBarInfo.Render(s.msg.Info)
57 }
58 branch := st.StatusBarBranch.Render(s.msg.Branch)
59 value := st.StatusBarValue.
60 Width(s.common.Width - w(key) - w(info) - w(branch)).
61 Render(s.msg.Value)
62
63 return lipgloss.JoinHorizontal(lipgloss.Top,
64 key,
65 value,
66 info,
67 branch,
68 )
69}