forked from Mirrors/bubbletea
Language improvements to the command tutorial
This commit is contained in:
parent
9c70f5f126
commit
b4d65cfe44
|
@ -210,7 +210,7 @@ The last step is to simply run our program. We pass our functions to
|
||||||
|
|
||||||
This tutorial covers the basics of building an interactive terminal UI, but
|
This tutorial covers the basics of building an interactive terminal UI, but
|
||||||
in the real world you'll also need to perform I/O. To learn about that have a
|
in the real world you'll also need to perform I/O. To learn about that have a
|
||||||
look at the [Cmd Tutorial][cmd]. It's pretty simple.
|
look at the [Command Tutorial][cmd]. It's pretty simple.
|
||||||
|
|
||||||
There are also several [Bubble Tea examples][examples] available and, of course,
|
There are also several [Bubble Tea examples][examples] available and, of course,
|
||||||
there are [Go Docs][docs].
|
there are [Go Docs][docs].
|
||||||
|
|
|
@ -36,7 +36,7 @@ a `const`.
|
||||||
## The Model
|
## The Model
|
||||||
|
|
||||||
Next we'll define our model. The only things we need to store are the status
|
Next we'll define our model. The only things we need to store are the status
|
||||||
code of HTTP response and a possible error.
|
code of the HTTP response and a possible error.
|
||||||
|
|
||||||
```go
|
```go
|
||||||
type model struct {
|
type model struct {
|
||||||
|
@ -107,17 +107,20 @@ them here. This makes dealing with many asynchronous operations very easy.
|
||||||
|
|
||||||
case statusMsg:
|
case statusMsg:
|
||||||
// The server returned a status message. Save it to our model. Also
|
// The server returned a status message. Save it to our model. Also
|
||||||
// exit because we have nothing else to do.
|
// tell the Bubble Tea runtime we ant to exit because we have
|
||||||
|
// nothing else to do. Don't worry, we'll still be able to render
|
||||||
|
// a final view with our status message.
|
||||||
m.status = int(msg)
|
m.status = int(msg)
|
||||||
return m, tea.Quit
|
return m, tea.Quit
|
||||||
|
|
||||||
case errMsg:
|
case errMsg:
|
||||||
// There was an error. Note it in the model. And exit the program.
|
// There was an error. Note it in the model. And tell the runtime
|
||||||
|
// we're done and want to quit.
|
||||||
m.err = msg
|
m.err = msg
|
||||||
return m, tea.Quit
|
return m, tea.Quit
|
||||||
|
|
||||||
case tea.KeyMsg:
|
case tea.KeyMsg:
|
||||||
// Ctrl+c quits. Even with short running programs it's good to have
|
// Ctrl+c exits. Even with short running programs it's good to have
|
||||||
// a quit key, just incase your logic is off. Users will be very
|
// a quit key, just incase your logic is off. Users will be very
|
||||||
// annoyed if they can't exit.
|
// annoyed if they can't exit.
|
||||||
if msg.Type == tea.KeyCtrlC {
|
if msg.Type == tea.KeyCtrlC {
|
||||||
|
@ -170,7 +173,7 @@ The only thing left to do is run the program, so let's do that!
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
And that's that. There's one more thing you should is helpful to know about
|
And that's that. There's one more thing you that is helpful to know about
|
||||||
`Cmd`s, though.
|
`Cmd`s, though.
|
||||||
|
|
||||||
## One More Thing About Commands
|
## One More Thing About Commands
|
||||||
|
@ -195,9 +198,9 @@ that returns a command. For example:
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Just make sure you do as much work as you can in the innermost function, because
|
Just make sure you do as much stuff as you can in the innermost function,
|
||||||
that's the one that runs asynchronously.
|
because that's the one that runs asynchronously.
|
||||||
n
|
|
||||||
## Anyway, Now What?
|
## Anyway, Now What?
|
||||||
|
|
||||||
After doing this tutorial and [the previous one][basics] you should be ready to
|
After doing this tutorial and [the previous one][basics] you should be ready to
|
||||||
|
|
Loading…
Reference in New Issue