Skip to content

Instantly share code, notes, and snippets.

@baniol
Created December 2, 2022 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baniol/7e098298bca7e1f3abfcd8b9fe09db31 to your computer and use it in GitHub Desktop.
Save baniol/7e098298bca7e1f3abfcd8b9fe09db31 to your computer and use it in GitHub Desktop.
basic structure for bubbletea
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