File tree Expand file tree Collapse file tree 2 files changed +29
-9
lines changed Expand file tree Collapse file tree 2 files changed +29
-9
lines changed Original file line number Diff line number Diff line change @@ -8,25 +8,31 @@ func Model(s string) string {
88 return fmt .Sprintf (`package tui
99
1010import (
11+ "github.com/charmbracelet/bubbles/spinner"
1112 tea "github.com/charmbracelet/bubbletea"
1213)
1314
1415// MainModel is the root state of the app.
1516type MainModel struct {
1617 appName string
18+ spinner spinner.Model
1719 err error
1820}
1921
2022// NewModel configures the initial model at runtime.
2123func NewModel() MainModel {
24+ s := spinner.New()
25+ s.Spinner = spinner.Globe
26+
2227 return MainModel{
2328 appName: "%s",
29+ spinner: s,
2430 }
2531}
2632
2733// Init returns any number of tea.Cmds at runtime.
2834func (m MainModel) Init() tea.Cmd {
29- return nil
35+ return m.spinner.Tick
3036}
3137
3238// Update handles all tea.Msgs in the Bubble Tea event loop.
@@ -42,14 +48,22 @@ func (m MainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
4248 return m, tea.Quit
4349 }
4450
51+ case ErrMsg:
52+ m.err = msg
53+ return m, nil
54+
4555 }
4656
47- return m, cmd
57+ m.spinner, cmd = m.spinner.Update(msg)
58+ return m, cmd
4859}
4960
5061// View renders a string representation of the MainModel.
5162func (m MainModel) View() string {
52- return MainView(m.appName)
63+ return titleView(m.appName) +
64+ descView() +
65+ m.spinner.View() +
66+ footerView()
5367}
5468
5569` , s )
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ var keyParts = []string{
2020}
2121
2222func keySwitchArt(s string) string {
23- var art string
23+ art := "\n"
2424 for i, line := range keyParts {
2525 for _, c := range s {
2626 if i == 4 {
@@ -38,15 +38,21 @@ func keySwitchArt(s string) string {
3838
3939 }
4040
41+ art += "\n"
42+
4143 return art
4244}
4345
44- func MainView(s string) string {
45- titleView := keySwitchArt(s)
46- descView := "Generated by drexler, with love ❤️"
47- quitView := lipgloss.NewStyle().Faint(true).SetString("[ctrl+c to quit]").String()
46+ func titleView(appName string) string {
47+ return keySwitchArt(appName)
48+ }
49+
50+ func descView() string {
51+ return " It's your world "
52+ }
4853
49- return "\n" + titleView + "\n" + descView + "\n\n\n\n\n" + quitView + "\n"
54+ func footerView() string {
55+ return lipgloss.NewStyle().Faint(true).SetString("\n\n\n\n Generated by drexler, with love ❤️\n [ctrl+c to quit]\n").String()
5056}
5157
5258`
You can’t perform that action at this time.
0 commit comments