Created
December 2, 2022 15:44
-
-
Save baniol/7e098298bca7e1f3abfcd8b9fe09db31 to your computer and use it in GitHub Desktop.
basic structure for bubbletea
This file contains hidden or 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" | |
tea "github.com/charmbracelet/bubbletea" | |
"os" | |
) | |
func main() { | |
err := tea.NewProgram(&Model{}, tea.WithAltScreen()).Start() | |
if err != nil { | |
fmt.Fprintln(os.Stderr, err) | |
os.Exit(1) | |
} | |
} | |
type Model struct{ | |
count int | |
} | |
func (m *Model) Init() tea.Cmd { | |
return nil | |
} | |
func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { | |
switch msg := msg.(type) { | |
case tea.KeyMsg: | |
switch msg.String(){ | |
case "ctrl+c": | |
return m, tea.Quit | |
case "up": | |
m.count++ | |
case "down": | |
m.count-- | |
} | |
} | |
return m, nil | |
} | |
func (m *Model) View() string { | |
return fmt.Sprintf("Count: %d", m.count) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment