Comments (4)
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.
from bubbletea.
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?
from bubbletea.
Yes, that is simple example of usage.
From interface perspective I think if you have possibility to extend interface func NewProgram(init Init, update Update, view View) *Program
to some way that you have access to model via instance of program to process Model outside that will be useful for people using tool for example as input to process.
What I can show download?
- [ ] nodejs
- [ ] ruby
- [ ] go
press q to quit/continue
and as output will be:
You select nodejs and I'm downloading latest nodejs from ...
in func main can be for example:
func main() {
p := tea.NewProgram(initialize, update, view)
if err := p.Start(); err != nil {
fmt.Printf("Alas, there's been an error: %v", err)
os.Exit(1)
} else {
m := p.GetModel() // whatever make sense
makeDownload(m.url)
}
}
or
func main() {
p, model := tea.NewProgram(initialize, update, view)
if err := p.Start(); err != nil {
fmt.Printf("Alas, there's been an error: %v", err)
os.Exit(1)
} else {
makeDownload(model.url)
}
}
from bubbletea.
That's a good idea. Since Program.Start()
blocks we could potentially do something like:
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 tea.Model
you'd need to assert the model to whatever type you're actually using for the model (same as you'd do in the update function).
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.
from bubbletea.
Related Issues (20)
- First line not rendering until event happens HOT 3
- Part of the screen is not rendering when the view is exactly the size of the screen HOT 3
- Proposal: Model v2, program context HOT 1
- Exiting fullscreen glitch when also removing a line in output HOT 2
- Proposal: use x/input to handle input events HOT 1
- `tea.unknownCSISequenceMsg: unknown message type` panics HOT 3
- The visible area in viewport may seem incorrect when content exceed the viewport.Width HOT 10
- Flickering on Windows when using bubbletea >=0.26.0 HOT 2
- SetWindowTitle panic after upgrade from v0.26.2 -> v0.26.3 HOT 1
- When a large update is performed, it will cause a flash. HOT 1
- PR #1033 broke the tabs example HOT 2
- View() gets stuck rendering a lipgloss.AdaptiveColor style (in an oddly specific situation) HOT 4
- Pager example with high performance rendering loses first line on resize HOT 3
- Bubbletea table and Lip Gloss color do not work with ssh.Channel. HOT 1
- Overriding the default help view
- Async Clipboard
- Automatic command chaining: Cmd -> Cmd -> Msg HOT 1
- Allow WindowSizeMsg to be sent on sub-model Init HOT 5
- Progress bar behaving strangely
- Any support for charts?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bubbletea.