docs(readme): updates for v2 (#1589)
Co-authored-by: Christian Rocha <christian@rocha.is>
This commit is contained in:
parent
323a3936e4
commit
ceab368db0
7 changed files with 112 additions and 133 deletions
72
README.md
72
README.md
|
|
@ -1,14 +1,9 @@
|
|||
# Bubble Tea
|
||||
|
||||
<p>
|
||||
<picture>
|
||||
<source media="(prefers-color-scheme: light)" srcset="https://stuff.charm.sh/bubbletea/bubble-tea-v2-light.png" width="308">
|
||||
<source media="(prefers-color-scheme: dark)" srcset="https://stuff.charm.sh/bubbletea/bubble-tea-v2-dark.png" width="312">
|
||||
<img src="https://stuff.charm.sh/bubbletea/bubble-tea-v2-light.png" width="308" />
|
||||
</picture>
|
||||
<br>
|
||||
<img src="https://github.com/user-attachments/assets/c7f51b04-617f-4fee-9e78-33e74f8229a8" width="350"><br>
|
||||
<a href="https://github.com/charmbracelet/bubbletea/releases"><img src="https://img.shields.io/github/release/charmbracelet/bubbletea.svg" alt="Latest Release"></a>
|
||||
<a href="https://pkg.go.dev/github.com/charmbracelet/bubbletea?tab=doc"><img src="https://godoc.org/github.com/charmbracelet/bubbletea?status.svg" alt="GoDoc"></a>
|
||||
<a href="https://pkg.go.dev/charm.land/bubbletea/v2?tab=doc"><img src="https://godoc.org/charm.land/bubbletea/v2?status.svg" alt="GoDoc"></a>
|
||||
<a href="https://github.com/charmbracelet/bubbletea/actions"><img src="https://github.com/charmbracelet/bubbletea/actions/workflows/build.yml/badge.svg?branch=main" alt="Build Status"></a>
|
||||
</p>
|
||||
|
||||
|
|
@ -22,12 +17,12 @@ complex terminal applications, either inline, full-window, or a mix of both.
|
|||
|
||||
Bubble Tea is in use in production and includes a number of features and
|
||||
performance optimizations we’ve added along the way. Among those is
|
||||
a framerate-based renderer, mouse support, focus reporting and more.
|
||||
a high-performance cell-based renderer, built-in color downsampling,
|
||||
declarative views, high-fidelity keyboard and mouse handling, native clipboard
|
||||
support, and more.
|
||||
|
||||
To get started, see the tutorial below, the [examples][examples], the
|
||||
[docs][docs], the [video tutorials][youtube] and some common [resources](#libraries-we-use-with-bubble-tea).
|
||||
|
||||
[youtube]: https://charm.sh/yt
|
||||
[docs][docs], and some common [resources](#libraries-we-use-with-bubble-tea).
|
||||
|
||||
## By the way
|
||||
|
||||
|
|
@ -72,7 +67,7 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
|
||||
tea "github.com/charmbracelet/bubbletea/v2"
|
||||
tea "charm.land/bubbletea/v2"
|
||||
)
|
||||
```
|
||||
|
||||
|
|
@ -98,9 +93,9 @@ type model struct {
|
|||
|
||||
## 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
|
||||
the initial model as a variable elsewhere, too.
|
||||
Next, we’ll define our application’s initial state. `Init` can return a `Cmd`
|
||||
that could perform some initial I/O. For now, we don’t need to do any I/O, so
|
||||
for the command, we’ll just return `nil`, which translates to “no command.”
|
||||
|
||||
```go
|
||||
func initialModel() model {
|
||||
|
|
@ -122,25 +117,15 @@ to do any I/O, so for the command, we'll just return `nil`, which translates to
|
|||
"no command."
|
||||
|
||||
```go
|
||||
func (m model) Init() (tea.Model, tea.Cmd) {
|
||||
m = {
|
||||
// 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
|
||||
// the map like a mathematical set. The keys refer to the indexes
|
||||
// of the `choices` slice, above.
|
||||
selected: make(map[int]struct{}),
|
||||
}
|
||||
|
||||
func (m model) Init() tea.Cmd {
|
||||
// Just return `nil`, which means "no I/O right now, please."
|
||||
return m, nil
|
||||
return nil
|
||||
}
|
||||
```
|
||||
|
||||
### The Update Method
|
||||
|
||||
Next up is the update method. The update function is called when ”things
|
||||
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
|
||||
response. It can also return a `Cmd` to make more things happen, but for now
|
||||
don't worry about that part.
|
||||
|
|
@ -184,8 +169,8 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||
m.cursor++
|
||||
}
|
||||
|
||||
// The "enter" key and the space bar (a literal space) toggle the
|
||||
// selected state for the item that the cursor is pointing at.
|
||||
// The "enter" key and the space bar toggle the selected state
|
||||
// for the item that the cursor is pointing at.
|
||||
case "enter", "space":
|
||||
_, ok := m.selected[m.cursor]
|
||||
if ok {
|
||||
|
|
@ -209,15 +194,16 @@ the Bubble Tea runtime to quit, exiting the program.
|
|||
### 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!
|
||||
simplest. We look at the model in its current state and use it to build a
|
||||
`tea.View`. The view declares our UI content and, optionally, terminal features
|
||||
like alt screen mode, mouse tracking, cursor position, and more.
|
||||
|
||||
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
|
||||
for you.
|
||||
|
||||
```go
|
||||
func (m model) View() string {
|
||||
func (m model) View() tea.View {
|
||||
// The header
|
||||
s := "What should we buy at the market?\n\n"
|
||||
|
||||
|
|
@ -244,7 +230,7 @@ func (m model) View() string {
|
|||
s += "\nPress q to quit.\n"
|
||||
|
||||
// Send the UI for rendering
|
||||
return s
|
||||
return tea.NewView(s)
|
||||
}
|
||||
```
|
||||
|
||||
|
|
@ -274,7 +260,7 @@ there are [Go Docs][docs].
|
|||
|
||||
[cmd]: https://github.com/charmbracelet/bubbletea/tree/main/tutorials/commands/
|
||||
[examples]: https://github.com/charmbracelet/bubbletea/tree/main/examples
|
||||
[docs]: https://pkg.go.dev/github.com/charmbracelet/bubbletea?tab=doc
|
||||
[docs]: https://pkg.go.dev/charm.land/bubbletea/v2?tab=doc
|
||||
|
||||
## Debugging
|
||||
|
||||
|
|
@ -337,7 +323,7 @@ your program in another window.
|
|||
|
||||
## Bubble Tea in the Wild
|
||||
|
||||
There are over [10,000 applications](https://github.com/charmbracelet/bubbletea/network/dependents) built with Bubble Tea! Here are a handful of ’em.
|
||||
There are over [18,000 applications](https://github.com/charmbracelet/bubbletea/network/dependents) built with Bubble Tea! Here are a handful of ’em.
|
||||
|
||||
### Staff favourites
|
||||
|
||||
|
|
@ -350,14 +336,14 @@ There are over [10,000 applications](https://github.com/charmbracelet/bubbletea/
|
|||
|
||||
### In Industry
|
||||
|
||||
- Microsoft Azure – [Aztify](https://github.com/Azure/aztfy): bring Microsoft Azure resources under Terraform
|
||||
- Daytona – [Daytona](https://github.com/daytonaio/daytona): open source dev environment manager
|
||||
- Microsoft Azure – [Aztify](https://github.com/Azure/aztfy): bring Microsoft Azure resources under Terraform
|
||||
- Daytona – [Daytona](https://github.com/daytonaio/daytona): an AI infrastructure platform
|
||||
- Cockroach Labs – [CockroachDB](https://github.com/cockroachdb/cockroach): a cloud-native, high-availability distributed SQL database
|
||||
- Truffle Security Co. – [Trufflehog](https://github.com/trufflesecurity/trufflehog): find leaked credentials
|
||||
- NVIDIA – [container-canary](https://github.com/NVIDIA/container-canary): a container validator
|
||||
- AWS – [eks-node-viewer](https://github.com/awslabs/eks-node-viewer): a tool for visualizing dynamic node usage within an EKS cluster
|
||||
- MinIO – [mc](https://github.com/minio/mc): the official [MinIO](https://min.io) client
|
||||
- Ubuntu – [Authd](https://github.com/ubuntu/authd): an authentication daemon for cloud-based identity providers
|
||||
- Truffle Security Co. – [Trufflehog](https://github.com/trufflesecurity/trufflehog): find leaked credentials
|
||||
- NVIDIA – [container-canary](https://github.com/NVIDIA/container-canary): a container validator
|
||||
- AWS – [eks-node-viewer](https://github.com/awslabs/eks-node-viewer): a tool for visualizing dynamic node usage within an EKS cluster
|
||||
- MinIO – [mc](https://github.com/minio/mc): the official [MinIO](https://min.io) client
|
||||
- Ubuntu – [Authd](https://github.com/ubuntu/authd): an authentication daemon for cloud-based identity providers
|
||||
|
||||
### Charm stuff
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
# Bubble Tea Basics
|
||||
|
||||
Bubble Tea is based on the functional design paradigms of [The Elm
|
||||
Architecture][elm], which happens to work nicely with Go. It's a delightful way
|
||||
Architecture][elm], which happens to work nicely with Go. It’s a delightful way
|
||||
to build applications.
|
||||
|
||||
This tutorial assumes you have a working knowledge of Go.
|
||||
|
|
@ -12,12 +12,12 @@ By the way, the non-annotated source code for this program is available
|
|||
[elm]: https://guide.elm-lang.org/architecture/
|
||||
[tut-source]: https://github.com/charmbracelet/bubbletea/tree/master/tutorials/basics
|
||||
|
||||
## Enough! Let's get to it.
|
||||
## Enough! Let’s get to it.
|
||||
|
||||
For this tutorial, we're making a shopping list.
|
||||
For this tutorial, we’re making a shopping list.
|
||||
|
||||
To start we'll define our package and import some libraries. Our only external
|
||||
import will be the Bubble Tea library, which we'll call `tea` for short.
|
||||
To start we’ll define our package and import some libraries. Our only external
|
||||
import will be the Bubble Tea library, which we’ll call `tea` for short.
|
||||
|
||||
```go
|
||||
package main
|
||||
|
|
@ -26,7 +26,7 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
|
||||
tea "github.com/charmbracelet/bubbletea/v2"
|
||||
tea "charm.land/bubbletea/v2"
|
||||
)
|
||||
```
|
||||
|
||||
|
|
@ -39,7 +39,7 @@ state and three simple methods on that model:
|
|||
|
||||
## The Model
|
||||
|
||||
So let's start by defining our model which will store our application's state.
|
||||
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.
|
||||
|
||||
```go
|
||||
|
|
@ -70,34 +70,22 @@ func initialModel() model {
|
|||
}
|
||||
```
|
||||
|
||||
After that, we’ll define our application’s initial state in the `Init` method. `Init`
|
||||
can return a `Cmd` that could perform some initial I/O. For now, we don't need
|
||||
to do any I/O, so for the command, we'll just return `nil`, which translates to
|
||||
"no command."
|
||||
After that, we’ll define the `Init` method. `Init` can return a `Cmd` that
|
||||
could perform some initial I/O. For now, we don’t need to do any I/O, so for
|
||||
the command, we’ll just return `nil`, which translates to "no command."
|
||||
|
||||
```go
|
||||
func (m model) Init() (tea.Model, tea.Cmd) {
|
||||
m = {
|
||||
// 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
|
||||
// the map like a mathematical set. The keys refer to the indexes
|
||||
// of the `choices` slice, above.
|
||||
selected: make(map[int]struct{}),
|
||||
}
|
||||
|
||||
// Just return `nil`, which means "no I/O right now, please."
|
||||
return m, nil
|
||||
func (m model) Init() tea.Cmd {
|
||||
return nil
|
||||
}
|
||||
```
|
||||
|
||||
## The Update Method
|
||||
|
||||
Next up is the update method. The update function is called when ”things
|
||||
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
|
||||
response. It can also return a `Cmd` to make more things happen, but for now
|
||||
don't worry about that part.
|
||||
don’t worry about that part.
|
||||
|
||||
In our case, when a user presses the down arrow, `Update`’s job is to notice
|
||||
that the down arrow was pressed and move the cursor accordingly (or not).
|
||||
|
|
@ -109,7 +97,7 @@ tick, or a response from a server.
|
|||
We usually figure out which type of `Msg` we received with a type switch, but
|
||||
you could also use a type assertion.
|
||||
|
||||
For now, we'll just deal with `tea.KeyPressMsg` messages, which are
|
||||
For now, we’ll just deal with `tea.KeyPressMsg` messages, which are
|
||||
automatically sent to the update function when keys are pressed.
|
||||
|
||||
```go
|
||||
|
|
@ -164,14 +152,16 @@ the Bubble Tea runtime to quit, exiting the program.
|
|||
|
||||
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 `tea.View`. The view declares our UI content and, optionally, terminal
|
||||
features like full-window mode (aka, altscreen mode), mouse tracking, cursor
|
||||
position, and more.
|
||||
|
||||
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
|
||||
for you.
|
||||
|
||||
```go
|
||||
func (m model) View() string {
|
||||
func (m model) View() tea.View {
|
||||
// The header
|
||||
s := "What should we buy at the market?\n\n"
|
||||
|
||||
|
|
@ -198,13 +188,13 @@ func (m model) View() string {
|
|||
s += "\nPress q to quit.\n"
|
||||
|
||||
// Send the UI for rendering
|
||||
return s
|
||||
return tea.NewView(s)
|
||||
}
|
||||
```
|
||||
|
||||
## All Together Now
|
||||
|
||||
The last step is to simply run our program. We pass an empty model
|
||||
The last step is to simply run our program. We pass our initial model to
|
||||
`tea.NewProgram` and let it rip:
|
||||
|
||||
```go
|
||||
|
|
@ -220,15 +210,15 @@ func main() {
|
|||
## What’s Next?
|
||||
|
||||
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
|
||||
look at the [Command Tutorial][cmd]. It's pretty simple.
|
||||
in the real world you’ll also need to perform I/O. To learn about that have a
|
||||
look at the [Command Tutorial][cmd]. It’s pretty simple.
|
||||
|
||||
There are also several [Bubble Tea examples][examples] available and, of course,
|
||||
there are [Go Docs][docs].
|
||||
|
||||
[cmd]: http://github.com/charmbracelet/bubbletea/tree/master/tutorials/commands/
|
||||
[examples]: http://github.com/charmbracelet/bubbletea/tree/master/examples
|
||||
[docs]: https://pkg.go.dev/github.com/charmbracelet/bubbletea?tab=doc
|
||||
[docs]: https://pkg.go.dev/charm.land/bubbletea/v2?tab=doc
|
||||
|
||||
## Additional Resources
|
||||
|
||||
|
|
@ -237,7 +227,7 @@ there are [Go Docs][docs].
|
|||
|
||||
### Feedback
|
||||
|
||||
We'd love to hear your thoughts on this tutorial. Feel free to drop us a note!
|
||||
We’d love to hear your thoughts on this tutorial. Feel free to drop us a note!
|
||||
|
||||
- [Twitter](https://twitter.com/charmcli)
|
||||
- [The Fediverse](https://mastodon.social/@charmcli)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
|
||||
tea "github.com/charmbracelet/bubbletea/v2"
|
||||
tea "charm.land/bubbletea/v2"
|
||||
)
|
||||
|
||||
type model struct {
|
||||
|
|
@ -26,7 +26,7 @@ func initialModel() model {
|
|||
}
|
||||
|
||||
func (m model) Init() tea.Cmd {
|
||||
return tea.SetWindowTitle("Grocery List")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
|
|
@ -56,7 +56,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||
return m, nil
|
||||
}
|
||||
|
||||
func (m model) View() string {
|
||||
func (m model) View() tea.View {
|
||||
s := "What should we buy at the market?\n\n"
|
||||
|
||||
for i, choice := range m.choices {
|
||||
|
|
@ -75,7 +75,10 @@ func (m model) View() string {
|
|||
|
||||
s += "\nPress q to quit.\n"
|
||||
|
||||
return s
|
||||
v := tea.NewView(s)
|
||||
v.WindowTitle = "Grocery List"
|
||||
|
||||
return v
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
|
|
|||
|
|
@ -9,12 +9,12 @@ You can find the non-annotated version of this program [on GitHub][source].
|
|||
[basics]: https://github.com/charmbracelet/bubbletea/tree/master/tutorials/basics
|
||||
[source]: https://github.com/charmbracelet/bubbletea/blob/master/tutorials/commands/main.go
|
||||
|
||||
## Let's Go!
|
||||
## Let’s Go!
|
||||
|
||||
For this tutorial we're building a very simple program that makes an HTTP
|
||||
For this tutorial we’re building a very simple program that makes an HTTP
|
||||
request to a server and reports the status code of the response.
|
||||
|
||||
We'll import a few necessary packages and put the URL we're going to check in
|
||||
We’ll import a few necessary packages and put the URL we’re going to check in
|
||||
a `const`.
|
||||
|
||||
```go
|
||||
|
|
@ -26,7 +26,7 @@ import (
|
|||
"os"
|
||||
"time"
|
||||
|
||||
tea "github.com/charmbracelet/bubbletea/v2"
|
||||
tea "charm.land/bubbletea/v2"
|
||||
)
|
||||
|
||||
const url = "https://charm.sh/"
|
||||
|
|
@ -34,7 +34,7 @@ const url = "https://charm.sh/"
|
|||
|
||||
## 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 the HTTP response and a possible error.
|
||||
|
||||
```go
|
||||
|
|
@ -51,7 +51,7 @@ time, ticking a timer, reading from the disk, and network stuff are all I/O and
|
|||
should be run through commands. That might sound harsh, but it will keep your
|
||||
Bubble Tea program straightforward and simple.
|
||||
|
||||
Anyway, let's write a `Cmd` that makes a request to a server and returns the
|
||||
Anyway, let’s write a `Cmd` that makes a request to a server and returns the
|
||||
result as a `Msg`.
|
||||
|
||||
```go
|
||||
|
|
@ -80,19 +80,19 @@ type errMsg struct{ err error }
|
|||
func (e errMsg) Error() string { return e.err.Error() }
|
||||
```
|
||||
|
||||
And notice that we've defined two new `Msg` types. They can be any type, even
|
||||
an empty struct. We'll come back to them later in our update function.
|
||||
First, let's write our initialization function.
|
||||
And notice that we’ve defined two new `Msg` types. They can be any type, even
|
||||
an empty struct. We’ll come back to them later in our update function.
|
||||
First, let’s write our initialization function.
|
||||
|
||||
## The Initialization Method
|
||||
|
||||
The initialization method is very simple: we return the `Cmd` we made earlier.
|
||||
Note that we don't call the function; the Bubble Tea runtime will do that when
|
||||
Note that we don’t call the function; the Bubble Tea runtime will do that when
|
||||
the time is right.
|
||||
|
||||
```go
|
||||
func (m model) Init() (tea.Model, tea.Cmd) {
|
||||
return m, checkServer
|
||||
func (m model) Init() tea.Cmd {
|
||||
return checkServer
|
||||
}
|
||||
```
|
||||
|
||||
|
|
@ -138,13 +138,13 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||
## The View Function
|
||||
|
||||
Our view is very straightforward. We look at the current model and build a
|
||||
string accordingly:
|
||||
`tea.View` accordingly:
|
||||
|
||||
```go
|
||||
func (m model) View() string {
|
||||
func (m model) View() tea.View {
|
||||
// If there's an error, print it out and don't do anything else.
|
||||
if m.err != nil {
|
||||
return fmt.Sprintf("\nWe had some trouble: %v\n\n", m.err)
|
||||
return tea.NewView(fmt.Sprintf("\nWe had some trouble: %v\n\n", m.err))
|
||||
}
|
||||
|
||||
// Tell the user we're doing something.
|
||||
|
|
@ -156,14 +156,14 @@ func (m model) View() string {
|
|||
}
|
||||
|
||||
// Send off whatever we came up with above for rendering.
|
||||
return "\n" + s + "\n\n"
|
||||
return tea.NewView("\n" + s + "\n\n")
|
||||
}
|
||||
```
|
||||
|
||||
## Run the program
|
||||
|
||||
The only thing left to do is run the program, so let's do that! Our initial
|
||||
model doesn't need any data at all in this case, we just initialize it with
|
||||
The only thing left to do is run the program, so let’s do that! Our initial
|
||||
model doesn’t need any data at all in this case, we just initialize it with
|
||||
a `model` struct with default values.
|
||||
|
||||
```go
|
||||
|
|
@ -175,13 +175,13 @@ func main() {
|
|||
}
|
||||
```
|
||||
|
||||
And that's that. There's one more thing that is helpful to know about
|
||||
And that’s that. There’s one more thing that is helpful to know about
|
||||
`Cmd`s, though.
|
||||
|
||||
## One More Thing About Commands
|
||||
|
||||
`Cmd`s are defined in Bubble Tea as `type Cmd func() Msg`. So they're just
|
||||
functions that don't take any arguments and return a `Msg`, which can be
|
||||
`Cmd`s are defined in Bubble Tea as `type Cmd func() Msg`. So they’re just
|
||||
functions that don’t take any arguments and return a `Msg`, which can be
|
||||
any type. If you need to pass arguments to a command, you just make a function
|
||||
that returns a command. For example:
|
||||
|
||||
|
|
@ -209,7 +209,7 @@ func checkSomeUrl(url string) tea.Cmd {
|
|||
```
|
||||
|
||||
Anyway, just make sure you do as much stuff as you can in the innermost
|
||||
function, because that's the one that runs asynchronously.
|
||||
function, because that’s the one that runs asynchronously.
|
||||
|
||||
## Now What?
|
||||
|
||||
|
|
@ -221,7 +221,7 @@ a component library for Bubble Tea.
|
|||
And, of course, check out the [Go Docs][docs].
|
||||
|
||||
[bubbles]: https://github.com/charmbracelet/bubbles
|
||||
[docs]: https://pkg.go.dev/github.com/charmbracelet/bubbletea?tab=doc
|
||||
[docs]: https://pkg.go.dev/charm.land/bubbletea/v2?tab=doc
|
||||
[examples]: https://github.com/charmbracelet/bubbletea/tree/master/examples
|
||||
|
||||
## Additional Resources
|
||||
|
|
@ -231,7 +231,7 @@ And, of course, check out the [Go Docs][docs].
|
|||
|
||||
### Feedback
|
||||
|
||||
We'd love to hear your thoughts on this tutorial. Feel free to drop us a note!
|
||||
We’d love to hear your thoughts on this tutorial. Feel free to drop us a note!
|
||||
|
||||
- [Twitter](https://twitter.com/charmcli)
|
||||
- [The Fediverse](https://mastodon.social/@charmcli)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import (
|
|||
"os"
|
||||
"time"
|
||||
|
||||
tea "github.com/charmbracelet/bubbletea/v2"
|
||||
tea "charm.land/bubbletea/v2"
|
||||
)
|
||||
|
||||
const url = "https://charm.sh/"
|
||||
|
|
@ -58,16 +58,16 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||
return m, nil
|
||||
}
|
||||
|
||||
func (m model) View() string {
|
||||
func (m model) View() tea.View {
|
||||
if m.err != nil {
|
||||
return fmt.Sprintf("\nWe had some trouble: %v\n\n", m.err)
|
||||
return tea.NewView(fmt.Sprintf("\nWe had some trouble: %v\n\n", m.err))
|
||||
}
|
||||
|
||||
s := fmt.Sprintf("Checking %s ... ", url)
|
||||
if m.status > 0 {
|
||||
s += fmt.Sprintf("%d %s!", m.status, http.StatusText(m.status))
|
||||
}
|
||||
return "\n" + s + "\n\n"
|
||||
return tea.NewView("\n" + s + "\n\n")
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
|
|
|||
|
|
@ -4,26 +4,26 @@ go 1.24.2
|
|||
|
||||
toolchain go1.24.10
|
||||
|
||||
require github.com/charmbracelet/bubbletea/v2 v2.0.0-20240918180721-14cb6b5de1d2
|
||||
require charm.land/bubbletea/v2 v2.0.0-00010101000000-000000000000
|
||||
|
||||
require (
|
||||
github.com/charmbracelet/colorprofile v0.3.3 // indirect
|
||||
github.com/charmbracelet/ultraviolet v0.0.0-20251114171239-77547d5f3edd // indirect
|
||||
github.com/charmbracelet/x/ansi v0.11.1 // indirect
|
||||
github.com/charmbracelet/colorprofile v0.4.1 // indirect
|
||||
github.com/charmbracelet/ultraviolet v0.0.0-20260205113103-524a6607adb8 // indirect
|
||||
github.com/charmbracelet/x/ansi v0.11.6 // indirect
|
||||
github.com/charmbracelet/x/term v0.2.2 // indirect
|
||||
github.com/charmbracelet/x/termios v0.1.1 // indirect
|
||||
github.com/charmbracelet/x/windows v0.2.2 // indirect
|
||||
github.com/clipperhouse/displaywidth v0.5.0 // indirect
|
||||
github.com/clipperhouse/displaywidth v0.9.0 // indirect
|
||||
github.com/clipperhouse/stringish v0.1.1 // indirect
|
||||
github.com/clipperhouse/uax29/v2 v2.3.0 // indirect
|
||||
github.com/clipperhouse/uax29/v2 v2.5.0 // indirect
|
||||
github.com/lucasb-eyer/go-colorful v1.3.0 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.19 // indirect
|
||||
github.com/muesli/cancelreader v0.2.2 // indirect
|
||||
github.com/rivo/uniseg v0.4.7 // indirect
|
||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
|
||||
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
|
||||
golang.org/x/sync v0.18.0 // indirect
|
||||
golang.org/x/sys v0.38.0 // indirect
|
||||
golang.org/x/sync v0.19.0 // indirect
|
||||
golang.org/x/sys v0.40.0 // indirect
|
||||
)
|
||||
|
||||
replace github.com/charmbracelet/bubbletea/v2 => ../
|
||||
replace charm.land/bubbletea/v2 => ../
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
github.com/aymanbagabas/go-udiff v0.2.0 h1:TK0fH4MteXUDspT88n8CKzvK0X9O2xu9yQjWpi6yML8=
|
||||
github.com/aymanbagabas/go-udiff v0.2.0/go.mod h1:RE4Ex0qsGkTAJoQdQQCA0uG+nAzJO/pI/QwceO5fgrA=
|
||||
github.com/charmbracelet/colorprofile v0.3.3 h1:DjJzJtLP6/NZ8p7Cgjno0CKGr7wwRJGxWUwh2IyhfAI=
|
||||
github.com/charmbracelet/colorprofile v0.3.3/go.mod h1:nB1FugsAbzq284eJcjfah2nhdSLppN2NqvfotkfRYP4=
|
||||
github.com/charmbracelet/ultraviolet v0.0.0-20251114171239-77547d5f3edd h1:oSO6mMvVUMsxAceDne7XfMr1KPzxFwCkFf8Yw8zkb7I=
|
||||
github.com/charmbracelet/ultraviolet v0.0.0-20251114171239-77547d5f3edd/go.mod h1:6lfcr3MNP+kZR25sF1nQwJFuQnNYBlFy3PGX5rvslXc=
|
||||
github.com/charmbracelet/x/ansi v0.11.1 h1:iXAC8SyMQDJgtcz9Jnw+HU8WMEctHzoTAETIeA3JXMk=
|
||||
github.com/charmbracelet/x/ansi v0.11.1/go.mod h1:M49wjzpIujwPceJ+t5w3qh2i87+HRtHohgb5iTyepL0=
|
||||
github.com/charmbracelet/colorprofile v0.4.1 h1:a1lO03qTrSIRaK8c3JRxJDZOvhvIeSco3ej+ngLk1kk=
|
||||
github.com/charmbracelet/colorprofile v0.4.1/go.mod h1:U1d9Dljmdf9DLegaJ0nGZNJvoXAhayhmidOdcBwAvKk=
|
||||
github.com/charmbracelet/ultraviolet v0.0.0-20260205113103-524a6607adb8 h1:eyFRbAmexyt43hVfeyBofiGSEmJ7krjLOYt/9CF5NKA=
|
||||
github.com/charmbracelet/ultraviolet v0.0.0-20260205113103-524a6607adb8/go.mod h1:SQpCTRNBtzJkwku5ye4S3HEuthAlGy2n9VXZnWkEW98=
|
||||
github.com/charmbracelet/x/ansi v0.11.6 h1:GhV21SiDz/45W9AnV2R61xZMRri5NlLnl6CVF7ihZW8=
|
||||
github.com/charmbracelet/x/ansi v0.11.6/go.mod h1:2JNYLgQUsyqaiLovhU2Rv/pb8r6ydXKS3NIttu3VGZQ=
|
||||
github.com/charmbracelet/x/exp/golden v0.0.0-20241212170349-ad4b7ae0f25f h1:UytXHv0UxnsDFmL/7Z9Q5SBYPwSuRLXHbwx+6LycZ2w=
|
||||
github.com/charmbracelet/x/exp/golden v0.0.0-20241212170349-ad4b7ae0f25f/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U=
|
||||
github.com/charmbracelet/x/term v0.2.2 h1:xVRT/S2ZcKdhhOuSP4t5cLi5o+JxklsoEObBSgfgZRk=
|
||||
|
|
@ -14,12 +14,12 @@ github.com/charmbracelet/x/termios v0.1.1 h1:o3Q2bT8eqzGnGPOYheoYS8eEleT5ZVNYNy8
|
|||
github.com/charmbracelet/x/termios v0.1.1/go.mod h1:rB7fnv1TgOPOyyKRJ9o+AsTU/vK5WHJ2ivHeut/Pcwo=
|
||||
github.com/charmbracelet/x/windows v0.2.2 h1:IofanmuvaxnKHuV04sC0eBy/smG6kIKrWG2/jYn2GuM=
|
||||
github.com/charmbracelet/x/windows v0.2.2/go.mod h1:/8XtdKZzedat74NQFn0NGlGL4soHB0YQZrETF96h75k=
|
||||
github.com/clipperhouse/displaywidth v0.5.0 h1:AIG5vQaSL2EKqzt0M9JMnvNxOCRTKUc4vUnLWGgP89I=
|
||||
github.com/clipperhouse/displaywidth v0.5.0/go.mod h1:R+kHuzaYWFkTm7xoMmK1lFydbci4X2CicfbGstSGg0o=
|
||||
github.com/clipperhouse/displaywidth v0.9.0 h1:Qb4KOhYwRiN3viMv1v/3cTBlz3AcAZX3+y9OLhMtAtA=
|
||||
github.com/clipperhouse/displaywidth v0.9.0/go.mod h1:aCAAqTlh4GIVkhQnJpbL0T/WfcrJXHcj8C0yjYcjOZA=
|
||||
github.com/clipperhouse/stringish v0.1.1 h1:+NSqMOr3GR6k1FdRhhnXrLfztGzuG+VuFDfatpWHKCs=
|
||||
github.com/clipperhouse/stringish v0.1.1/go.mod h1:v/WhFtE1q0ovMta2+m+UbpZ+2/HEXNWYXQgCt4hdOzA=
|
||||
github.com/clipperhouse/uax29/v2 v2.3.0 h1:SNdx9DVUqMoBuBoW3iLOj4FQv3dN5mDtuqwuhIGpJy4=
|
||||
github.com/clipperhouse/uax29/v2 v2.3.0/go.mod h1:Wn1g7MK6OoeDT0vL+Q0SQLDz/KpfsVRgg6W7ihQeh4g=
|
||||
github.com/clipperhouse/uax29/v2 v2.5.0 h1:x7T0T4eTHDONxFJsL94uKNKPHrclyFI0lm7+w94cO8U=
|
||||
github.com/clipperhouse/uax29/v2 v2.5.0/go.mod h1:Wn1g7MK6OoeDT0vL+Q0SQLDz/KpfsVRgg6W7ihQeh4g=
|
||||
github.com/lucasb-eyer/go-colorful v1.3.0 h1:2/yBRLdWBZKrf7gB40FoiKfAWYQ0lqNcbuQwVHXptag=
|
||||
github.com/lucasb-eyer/go-colorful v1.3.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
||||
github.com/mattn/go-runewidth v0.0.19 h1:v++JhqYnZuu5jSKrk9RbgF5v4CGUjqRfBm05byFGLdw=
|
||||
|
|
@ -32,7 +32,7 @@ github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavM
|
|||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
|
||||
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
|
||||
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
|
||||
golang.org/x/sync v0.18.0 h1:kr88TuHDroi+UVf+0hZnirlk8o8T+4MrK6mr60WkH/I=
|
||||
golang.org/x/sync v0.18.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
|
||||
golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc=
|
||||
golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
||||
golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=
|
||||
golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
|
||||
golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ=
|
||||
golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
||||
|
|
|
|||
Loading…
Reference in a new issue