forked from Mirrors/bubbletea
docs: readme improvements (#448)
* docs: fix hierarchy in literate version of the basics tutorial * docs: small correction to comment in literate tutorial * docs: improve wording in logging section of the README * docs: fix spelling (thanks maas)
This commit is contained in:
parent
d0f3e1e052
commit
bf3996256b
34
README.md
34
README.md
|
@ -1,5 +1,4 @@
|
|||
Bubble Tea
|
||||
==========
|
||||
# Bubble Tea
|
||||
|
||||
<p>
|
||||
<img src="https://stuff.charm.sh/bubbletea/bubbletea-github-header-simple.png" width="313" alt="Bubble Tea Title Treatment"><br>
|
||||
|
@ -52,7 +51,7 @@ This tutorial assumes you have a working knowledge of Go.
|
|||
|
||||
[elm]: https://guide.elm-lang.org/architecture/
|
||||
|
||||
## Enough! Let's get to it.
|
||||
### Enough! Let's get to it.
|
||||
|
||||
For this tutorial, we're making a shopping list.
|
||||
|
||||
|
@ -77,7 +76,7 @@ state and three simple methods on that model:
|
|||
* **Update**, a function that handles incoming events and updates the model accordingly.
|
||||
* **View**, a function that renders the UI based on the data in the model.
|
||||
|
||||
## The Model
|
||||
### The Model
|
||||
|
||||
So let's start by defining our model which will store our application's state.
|
||||
It can be any type, but a `struct` usually makes the most sense.
|
||||
|
@ -90,7 +89,7 @@ type model struct {
|
|||
}
|
||||
```
|
||||
|
||||
## Initialization
|
||||
### Initialization
|
||||
|
||||
Next, we’ll define our application’s initial state. In this case, we’re defining
|
||||
a function to return our initial model, however, we could just as easily define
|
||||
|
@ -99,7 +98,7 @@ the initial model as a variable elsewhere, too.
|
|||
```go
|
||||
func initialModel() model {
|
||||
return model{
|
||||
// Our shopping list is a grocery list
|
||||
// Our to-do list is a grocery list
|
||||
choices: []string{"Buy carrots", "Buy celery", "Buy kohlrabi"},
|
||||
|
||||
// A map which indicates which choices are selected. We're using
|
||||
|
@ -121,7 +120,7 @@ func (m model) Init() tea.Cmd {
|
|||
}
|
||||
```
|
||||
|
||||
## The Update Method
|
||||
### The Update Method
|
||||
|
||||
Next up is the update method. The update function is called when ”things
|
||||
happen.” Its job is to look at what has happened and return an updated model in
|
||||
|
@ -189,11 +188,11 @@ You may have noticed that <kbd>ctrl+c</kbd> and <kbd>q</kbd> above return
|
|||
a `tea.Quit` command with the model. That’s a special command which instructs
|
||||
the Bubble Tea runtime to quit, exiting the program.
|
||||
|
||||
## The View Method
|
||||
### The View Method
|
||||
|
||||
At last, it’s time to render our UI. Of all the methods, the view is the
|
||||
simplest. We look at the model in its current state and use it to return
|
||||
a `string`. That string is our UI!
|
||||
a `string`. That string is our UI!
|
||||
|
||||
Because the view describes the entire UI of your application, you don’t have to
|
||||
worry about redrawing logic and stuff like that. Bubble Tea takes care of it
|
||||
|
@ -231,7 +230,7 @@ func (m model) View() string {
|
|||
}
|
||||
```
|
||||
|
||||
## All Together Now
|
||||
### All Together Now
|
||||
|
||||
The last step is to simply run our program. We pass our initial model to
|
||||
`tea.NewProgram` and let it rip:
|
||||
|
@ -280,8 +279,9 @@ actually watch out what address the first `dlv` run tells you to connect to.
|
|||
|
||||
### Logging Stuff
|
||||
|
||||
You can log to a debug file to print debug Bubble Tea applications. To do so,
|
||||
include something like…
|
||||
You can’t really log to stdout with Bubble Tea because your TUI is busy
|
||||
occupying that! You can, however, log to a file by including something like
|
||||
the following prior to starting your Bubble Tea program:
|
||||
|
||||
```go
|
||||
if len(os.Getenv("DEBUG")) > 0 {
|
||||
|
@ -294,8 +294,8 @@ if len(os.Getenv("DEBUG")) > 0 {
|
|||
}
|
||||
```
|
||||
|
||||
…before you start your Bubble Tea program. To see what’s printed in real time,
|
||||
run `tail -f debug.log` while you run your program in another window.
|
||||
To see what’s being logged in real time, run `tail -f debug.log` while you run
|
||||
your program in another window.
|
||||
|
||||
## Libraries we use with Bubble Tea
|
||||
|
||||
|
@ -327,7 +327,7 @@ For some Bubble Tea programs in production, see:
|
|||
* [dns53](https://github.com/purpleclay/dns53): dynamic DNS with Amazon Route53. Expose your EC2 quickly, securely and privately
|
||||
* [fm](https://github.com/knipferrc/fm): a terminal-based file manager
|
||||
* [flapioca](https://github.com/kbrgl/flapioca): Flappy Bird on the CLI!
|
||||
* [fztea](https://github.com/jon4hz/fztea): connect to your Flipper's UI over serial or make it accessible via SSH
|
||||
* [fztea](https://github.com/jon4hz/fztea): connect to your Flipper's UI over serial or make it accessible via SSH
|
||||
* [fork-cleaner](https://github.com/caarlos0/fork-cleaner): cleans up old and inactive forks in your GitHub account
|
||||
* [gambit](https://github.com/maaslalani/gambit): play chess in the terminal
|
||||
* [gembro](https://git.sr.ht/~rafael/gembro): a mouse-driven Gemini browser
|
||||
|
@ -385,10 +385,10 @@ of days past.
|
|||
|
||||
[MIT](https://github.com/charmbracelet/bubbletea/raw/master/LICENSE)
|
||||
|
||||
***
|
||||
* * *
|
||||
|
||||
Part of [Charm](https://charm.sh).
|
||||
|
||||
<a href="https://charm.sh/"><img alt="The Charm logo" src="https://stuff.charm.sh/charm-badge.jpg" width="400"></a>
|
||||
|
||||
Charm热爱开源 • Charm loves open source
|
||||
Charm 热爱开源 • Charm loves open source
|
||||
|
|
|
@ -59,7 +59,7 @@ the initial model as a variable elsewhere, too.
|
|||
```go
|
||||
func initialModel() model {
|
||||
return model{
|
||||
// Our shopping list is a grocery list
|
||||
// Our to-do list is a grocery list
|
||||
choices: []string{"Buy carrots", "Buy celery", "Buy kohlrabi"},
|
||||
|
||||
// A map which indicates which choices are selected. We're using
|
||||
|
|
Loading…
Reference in New Issue