How does Printf work? #367
-
|
EDIT: I realized I was very wrong in how I thought this all worked. Nevertheless, I figured I'd just edit this discussion instead of making a new one. How does one use the I thought perhaps you had to give a pointer to the Program to your model, but when I do (see below), I still get no output. 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.Type.String() {
case "ctrl+c":
return m, tea.Quit
case "p":
m.p.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)
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
|
Hey @Kaychub ! Thanks for reaching out. A few things, the switch needs to be Here is the working version of what you're aiming to accomplish |
Beta Was this translation helpful? Give feedback.
Hey @Kaychub ! Thanks for reaching out.
A few things, the switch needs to be
switch msg.String()to register the keypress and instead ofm.p.Println("Why can't I see this?")it should betea.Println("Why can't I see this"). I'll look into updating our docs on pkg.go.dev to include an example. I hope that helps clear things up! Let us know if you have any other questionsHere is the working version of what you're aiming to accomplish