Skip to content
Myr

docs: readme improvements (#448)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* 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)

authored by Christian Rocha · committed by GitHub · parent d0f3e1e · Browse files · 2 files+18 added−18 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+18 added−18 removed

  • other:+18 added−18 removed

2 files+18 added−18 removed

modified:tutorials/basics/README.md+1 added-1 removed
57 unmodified lines
5859```go60func initialModel() model {61 return model{62 // Our shopping list is a grocery list62 // Our to-do list is a grocery list63 choices: []string{"Buy carrots", "Buy celery", "Buy kohlrabi"},6465 // A map which indicates which choices are selected. We're using66 // the map like a mathematical set. The keys refer to the indexes
175 unmodified lines
modified:README.md+17 added-17 removed
1Bubble Tea2==========1# Bubble Tea23<p>4 <img src="https://stuff.charm.sh/bubbletea/bubbletea-github-header-simple.png" width="313" alt="Bubble Tea Title Treatment"><br>5 <a href="https://github.com/charmbracelet/bubbletea/releases"><img src="https://img.shields.io/github/release/charmbracelet/bubbletea.svg" alt="Latest Release"></a>
44 unmodified lines
50This tutorial assumes you have a working knowledge of Go.5152[elm]: https://guide.elm-lang.org/architecture/5355## Enough! Let's get to it.54### Enough! Let's get to it.5556For this tutorial, we're making a shopping list.5758To start we'll define our package and import some libraries. Our only external
16 unmodified lines
75* **Init**, a function that returns an initial command for the application to run.76* **Update**, a function that handles incoming events and updates the model accordingly.77* **View**, a function that renders the UI based on the data in the model.7880## The Model79### The Model8081So let's start by defining our model which will store our application's state.82It can be any type, but a `struct` usually makes the most sense.83
4 unmodified lines
88 selected map[int]struct{} // which to-do items are selected89}90```9193## Initialization92### Initialization9394Next, we’ll define our application’s initial state. In this case, we’re defining95a function to return our initial model, however, we could just as easily define96the initial model as a variable elsewhere, too.9798```go99func initialModel() model {100 return model{102 // Our shopping list is a grocery list101 // Our to-do list is a grocery list102 choices: []string{"Buy carrots", "Buy celery", "Buy kohlrabi"},103104 // A map which indicates which choices are selected. We're using105 // the map like a mathematical set. The keys refer to the indexes
13 unmodified lines
119 return nil120}121```122124## The Update Method123### The Update Method124125Next up is the update method. The update function is called when ”things126happen.” Its job is to look at what has happened and return an updated model in127response. It can also return a `Cmd` to make more things happen, but for now
59 unmodified lines
187You may have noticed that <kbd>ctrl+c</kbd> and <kbd>q</kbd> above return188a `tea.Quit` command with the model. That’s a special command which instructs189the Bubble Tea runtime to quit, exiting the program.190192## The View Method191### The View Method192193At last, it’s time to render our UI. Of all the methods, the view is the194simplest. We look at the model in its current state and use it to return196a `string`. That string is our UI!195a `string`. That string is our UI!196197Because the view describes the entire UI of your application, you don’t have to198worry about redrawing logic and stuff like that. Bubble Tea takes care of it199for you.
29 unmodified lines
229 return s230}231```232234## All Together Now233### All Together Now234235The last step is to simply run our program. We pass our initial model to236`tea.NewProgram` and let it rip:237
40 unmodified lines
278actually watch out what address the first `dlv` run tells you to connect to.279280### Logging Stuff281283You can log to a debug file to print debug Bubble Tea applications. To do so,284include something like…282You can’t really log to stdout with Bubble Tea because your TUI is busy283occupying that! You can, however, log to a file by including something like284the following prior to starting your Bubble Tea program:285286```go287if len(os.Getenv("DEBUG")) > 0 {288 f, err := tea.LogToFile("debug.log", "debug")
4 unmodified lines
293 defer f.Close()294}295```296297…before you start your Bubble Tea program. To see what’s printed in real time,298run `tail -f debug.log` while you run your program in another window.297To see what’s being logged in real time, run `tail -f debug.log` while you run298your program in another window.299300## Libraries we use with Bubble Tea301302* [Bubbles][bubbles]: Common Bubble Tea components such as text inputs, viewports, spinners and so on
23 unmodified lines
326* [container-canary](https://github.com/NVIDIA/container-canary): a container validator327* [dns53](https://github.com/purpleclay/dns53): dynamic DNS with Amazon Route53. Expose your EC2 quickly, securely and privately328* [fm](https://github.com/knipferrc/fm): a terminal-based file manager329* [flapioca](https://github.com/kbrgl/flapioca): Flappy Bird on the CLI!330* [fztea](https://github.com/jon4hz/fztea): connect to your Flipper's UI over serial or make it accessible via SSH 330* [fztea](https://github.com/jon4hz/fztea): connect to your Flipper's UI over serial or make it accessible via SSH331* [fork-cleaner](https://github.com/caarlos0/fork-cleaner): cleans up old and inactive forks in your GitHub account332* [gambit](https://github.com/maaslalani/gambit): play chess in the terminal333* [gembro](https://git.sr.ht/~rafael/gembro): a mouse-driven Gemini browser334* [gh-b](https://github.com/joaom00/gh-b): GitHub CLI extension to easily manage your branches
49 unmodified lines
384## License385386[MIT](https://github.com/charmbracelet/bubbletea/raw/master/LICENSE)387388***388* * *389390Part of [Charm](https://charm.sh).391392<a href="https://charm.sh/"><img alt="The Charm logo" src="https://stuff.charm.sh/charm-badge.jpg" width="400"></a>393394Charm热爱开源 • Charm loves open source394Charm 热爱开源 • Charm loves open source