Skip to content

Instantly share code, notes, and snippets.

@bashbunni
Last active July 20, 2022 19:16
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 bashbunni/7f87d5e4cb61b936a7469a9719707a80 to your computer and use it in GitHub Desktop.
Save bashbunni/7f87d5e4cb61b936a7469a9719707a80 to your computer and use it in GitHub Desktop.
tea.Println Example
package main
import (
"log"
tea "github.com/charmbracelet/bubbletea"
)
type model struct {
p *tea.Program
}
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 "p":
return m, tea.Println("Why can't I see this?")
}
}
return m, nil
}
func (m model) Init() tea.Cmd {
return nil
}
func (m model) View() string {
return "This is the view"
}
func main() {
m := &model{}
p := tea.NewProgram(m)
m.p = p
if err := p.Start(); err != nil {
log.Fatal(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment