-
Notifications
You must be signed in to change notification settings - Fork 723
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: How print output from TODO #7
Comments
Hi! So if I understand correctly, you want to capture the output of a choice, exit Bubble Tea, and then do something with that value? |
Yes, that is simple example of usage. From interface perspective I think if you have possibility to extend interface
and as output will be:
in func main can be for example:
or
|
That's a good idea. Since func main() {
finalModel, err := tea.NewProgram(myModel).Start()
if err != nil {
fmt.Printf("Oh no!: %v\n", err)
os.Exit(1)
}
m, ok := finalModel.(myModel)
if ok {
doSomething(model.url)
}
} Because the Bubble Tea runtime only knows the type as Depending on what the rest of your program looks like you could also just perform I/O in a command, which is typically how you’d do I/O in Bubble Tea (quick writeup here incase you haven’t seen it). Something like: func (m MyModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// ...
switch msg := msg.(type) {
case tea.KeyMsg:
switch msg.Type {
case tea.KeyEnter:
m.note = "Now downloading!"
return m, makeDownload(m.url)
}
// ...
}
}
func makeDownload(url string) tea.Cmd {
return func() tea.Msg {
// ... download logic
return downloadStatusMsg{err}
}
} But yes, that’s definitely more involved if the goal is to simply use the library to quickly capture some input. |
After thinking about this some more, I think it makes the most sense to send final results back with a channel. Here's an example. |
I try it example and it's great library, but I can't figure out how you think we can work with output.
Example:
I can just add print for selected output:
I can put into update function to quit and get ugly output:
Do I need extra view for that? Or is some simple way how get pass output via program interface to main function to continue for example with other program? I see example with Msg but look overcomplicated for just work with output from CLI.
The text was updated successfully, but these errors were encountered: