This repository has been archived on 2024-07-28. You can view files and clone it, but cannot push or open issues or pull requests.

70 lines
1.2 KiB
Go

package models
import (
"strings"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
)
var profileNameButtonStyle = lipgloss.NewStyle().
BorderStyle(lipgloss.NormalBorder()).
Padding(0, 1).
Bold(true)
type profileBarModel struct {
state int
profileNames []string
width int
height int
}
func newProfileBarModel(profileNames []string) profileBarModel {
return profileBarModel{
state: 0,
profileNames: profileNames,
height: 2,
}
}
func (m profileBarModel) Init() tea.Cmd {
return nil
}
func (m profileBarModel) Update(msg tea.Msg) (profileBarModel, tea.Cmd) {
// TODO(d1): bubblezone handle clicks, fire msgs to mainModel to switch
switch msg := msg.(type) {
case tea.WindowSizeMsg:
m.width = msg.Width
}
return m, nil
}
func (m profileBarModel) View() string {
body := strings.Builder{}
var profileNames []string
for idx, profileName := range m.profileNames {
rendered := profileNameButtonStyle.Render(profileName)
if idx > 0 {
rendered = profileNameButtonStyle.
MarginLeft(1).
Render(profileName)
}
profileNames = append(profileNames, rendered)
}
body.WriteString(
lipgloss.JoinHorizontal(
lipgloss.Left,
profileNames...,
),
)
return body.String()
}