Created
May 18, 2022 12:52
-
-
Save meowgorithm/db4bbb2cffcf66205efd73f272a5364d to your computer and use it in GitHub Desktop.
69 FPS in Bubble Tea
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"time" | |
tea "github.com/charmbracelet/bubbletea" | |
) | |
type stepMsg time.Time | |
func stepAnimation() tea.Cmd { | |
return tea.Tick(time.Second/69, func(t time.Time) tea.Msg { | |
return stepMsg(t) | |
}) | |
} | |
type model struct { | |
frame int | |
} | |
func (m model) Init() tea.Cmd { | |
return stepAnimation() | |
} | |
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { | |
switch msg.(type) { | |
case tea.KeyMsg: | |
return m, tea.Quit | |
case stepMsg: | |
m.frame++ | |
return m, stepAnimation() | |
} | |
return m, nil | |
} | |
func (m model) View() string { | |
return fmt.Sprintf("Frame: %d", m.frame) | |
} | |
func main() { | |
if err := tea.NewProgram(model{}).Start(); err != nil { | |
fmt.Println("Oh no!", err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment