main.go (753B)
1 package main 2 3 import ( 4 "log" 5 "math/rand" 6 "time" 7 8 tea "github.com/charmbracelet/bubbletea" 9 gloss "github.com/charmbracelet/lipgloss" 10 ) 11 12 func (m model) Init() tea.Cmd { 13 return nil 14 } 15 16 func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { 17 switch msg := msg.(type) { 18 case tea.WindowSizeMsg: 19 m.width = msg.Width 20 m.height = msg.Height 21 case tea.KeyMsg: 22 if msg.Type == tea.KeyCtrlC || msg.String() == "q" { 23 return m, tea.Quit 24 } 25 } 26 return m, nil 27 } 28 29 func (m model) View() string { 30 return gloss.Place( 31 m.width, 32 m.height, 33 gloss.Center, 34 gloss.Bottom, 35 base(m.conf.base), 36 ) 37 } 38 39 func main() { 40 rand.Seed(time.Now().UnixNano()) 41 if err := tea.NewProgram(initialModel(), tea.WithAltScreen()).Start(); err != nil { 42 log.Fatal(err) 43 } 44 }