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.
Files
cairde/internal/models/title.go

68 lines
1.2 KiB
Go

package models
import (
"fmt"
"strings"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
)
var titleStyle = lipgloss.NewStyle().
Align(lipgloss.Center).
Bold(true)
var backgroundStyle = lipgloss.NewStyle().
Align(lipgloss.Center)
type titleModel struct {
programName string
programVersion string
title string
width int
height int
}
func newTitleModel(programName, programVersion string) titleModel {
return titleModel{
programName: programName,
programVersion: programVersion,
title: fmt.Sprintf("%s@%s", programName, programVersion),
height: 1,
}
}
func (m titleModel) Init() tea.Cmd {
return nil
}
func (m titleModel) Update(msg tea.Msg) (titleModel, tea.Cmd) {
switch msg := msg.(type) {
case tea.WindowSizeMsg:
m.width = msg.Width
}
return m, nil
}
func (m titleModel) View() string {
body := strings.Builder{}
body.WriteString(
lipgloss.PlaceHorizontal(
m.width,
lipgloss.Center,
titleStyle.
Width(m.width).
Height(m.height).
Render(
backgroundStyle.
Width(lipgloss.Width(m.title)+2).
Render(m.title),
),
),
)
return body.String()
}