1package statusbar23import (4 tea "charm.land/bubbletea/v2"5 "charm.land/lipgloss/v2"6 "github.com/charmbracelet/soft-serve/pkg/ui/common"7 "github.com/charmbracelet/x/ansi"8)910// Model is a status bar model.11type Model struct {12 common common.Common13 key string14 value string15 info string16 extra string17}1819// New creates a new status bar component.20func New(c common.Common) *Model {21 s := &Model{22 common: c,23 }24 return s25}2627// SetSize implements common.Component.28func (s *Model) SetSize(width, height int) {29 s.common.Width = width30 s.common.Height = height31}3233// SetStatus sets the status bar status.34func (s *Model) SetStatus(key, value, info, extra string) {35 if key != "" {36 s.key = key37 }38 if value != "" {39 s.value = value40 }41 if info != "" {42 s.info = info43 }44 if extra != "" {45 s.extra = extra46 }47}4849// Init implements tea.Model.50func (s *Model) Init() tea.Cmd {51 return nil52}5354// Update implements tea.Model.55func (s *Model) Update(msg tea.Msg) (common.Model, tea.Cmd) {56 switch msg := msg.(type) {57 case tea.WindowSizeMsg:58 s.SetSize(msg.Width, msg.Height)59 }60 return s, nil61}6263// View implements tea.Model.64func (s *Model) View() string {65 st := s.common.Styles66 w := lipgloss.Width67 help := s.common.Zone.Mark(68 "repo-help",69 st.StatusBarHelp.Render("? Help"),70 )71 key := st.StatusBarKey.Render(s.key)72 info := ""73 if s.info != "" {74 info = st.StatusBarInfo.Render(s.info)75 }76 branch := st.StatusBarBranch.Render(s.extra)77 maxWidth := s.common.Width - w(key) - w(info) - w(branch) - w(help)78 v := ansi.Truncate(s.value, maxWidth-st.StatusBarValue.GetHorizontalFrameSize(), "…")79 value := st.StatusBarValue.80 Width(maxWidth).81 Render(v)8283 return lipgloss.NewStyle().MaxWidth(s.common.Width).84 Render(85 lipgloss.JoinHorizontal(lipgloss.Top,86 key,87 value,88 info,89 branch,90 help,91 ),92 )93}