Last active
July 20, 2022 19:16
-
-
Save bashbunni/7f87d5e4cb61b936a7469a9719707a80 to your computer and use it in GitHub Desktop.
tea.Println Example
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 ( | |
"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