styles.go

 1package tui
 2
 3import (
 4	"fmt"
 5
 6	"charm.land/bubbles/v2/spinner"
 7	tea "charm.land/bubbletea/v2"
 8	"charm.land/lipgloss/v2"
 9	"github.com/floatpane/matcha/theme"
10)
11
12// ASCII logo for Matcha displayed during loading screens
13const asciiLogo = `
14                	__       __
15   ____ ___  ____ _/ /______/ /_  ____ _
16  / __ '__ \/ __ '/ __/ ___/ __ \/ __ '/
17 / / / / / / /_/ / /_/ /__/ / / / /_/ /
18/_/ /_/ /_/\__,_/\__/\___/_/ /_/\__,_/
19`
20
21var (
22	DialogBoxStyle = lipgloss.NewStyle().
23			Border(lipgloss.RoundedBorder()).
24			BorderForeground(lipgloss.Color("#25A065")).
25			Padding(1, 2).
26			BorderTop(true).
27			BorderLeft(true).
28			BorderRight(true).
29			BorderBottom(true)
30
31	HelpStyle    = lipgloss.NewStyle().Foreground(lipgloss.Color("240"))
32	TipStyle     = lipgloss.NewStyle().Foreground(lipgloss.Color("214")).Italic(true)
33	SuccessStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("42")).Bold(true)
34	InfoStyle    = lipgloss.NewStyle().Foreground(lipgloss.Color("42")).Bold(true)
35
36	H1Style = lipgloss.NewStyle().
37		Foreground(lipgloss.Color("42")).
38		Bold(true).
39		Align(lipgloss.Center)
40
41	H2Style = lipgloss.NewStyle().
42		Foreground(lipgloss.Color("42")).
43		Bold(false). // Less bold
44		Align(lipgloss.Center)
45
46	BodyStyle = lipgloss.NewStyle().
47			Bold(true) // A bit bold
48)
49
50var DocStyle = lipgloss.NewStyle().Margin(1, 2)
51
52// A simple model for showing a status message
53type Status struct {
54	spinner spinner.Model
55	message string
56}
57
58func NewStatus(msg string) Status {
59	s := spinner.New()
60	s.Spinner = spinner.Dot
61	s.Style = lipgloss.NewStyle().Foreground(theme.ActiveTheme.Accent)
62	return Status{spinner: s, message: msg}
63}
64
65func (m Status) Init() tea.Cmd { return m.spinner.Tick }
66
67func (m Status) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
68	var cmd tea.Cmd
69	m.spinner, cmd = m.spinner.Update(msg)
70	return m, cmd
71}
72
73func (m Status) View() tea.View {
74	logoStyle := lipgloss.NewStyle().Foreground(theme.ActiveTheme.Accent)
75	styledLogo := logoStyle.Render(asciiLogo)
76
77	spinnerLine := fmt.Sprintf("   %s %s", m.spinner.View(), m.message)
78
79	return tea.NewView(fmt.Sprintf("%s\n%s\n\n", styledLogo, spinnerLine))
80}