1package main
2
3// This example is used for spinner tuning.
4
5import (
6 "fmt"
7 "os"
8
9 tea "charm.land/bubbletea/v2"
10
11 "github.com/charmbracelet/crush/internal/ui/spinner"
12)
13
14// Model is the Bubble Tea model for the example program.
15type Model struct {
16 spinner spinner.Spinner
17 quitting bool
18}
19
20// Init initializes the model. It satisfies tea.Model.
21func (m Model) Init() tea.Cmd {
22 return m.spinner.Start()
23}
24
25// Update updates the model per on incoming messages. It satisfies tea.Model.
26func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
27 switch msg := msg.(type) {
28 case tea.KeyPressMsg:
29 switch msg.String() {
30 case "q", "ctrl+c":
31 m.quitting = true
32 return m, tea.Quit
33 }
34 }
35
36 var cmd tea.Cmd
37 m.spinner, cmd = m.spinner.Update(msg)
38 return m, cmd
39}
40
41// View renders the model to a string. It satisfies tea.Model.
42func (m Model) View() tea.View {
43 if m.quitting {
44 return tea.NewView("")
45 }
46 return tea.NewView(m.spinner.View())
47}
48
49func main() {
50 if _, err := tea.NewProgram(Model{
51 spinner: spinner.NewSpinner("Romanticizing"),
52 }).Run(); err != nil {
53 fmt.Fprintf(os.Stderr, "Error running program: %v\n", err)
54 os.Exit(1)
55 }
56}