88 </picture>
99 <br>
1010 <a href="https://github.com/charmbracelet/bubbletea/releases"><img src="https://img.shields.io/github/release/charmbracelet/bubbletea.svg" alt="Latest Release"></a>
11- <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>
11+ <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>
1212 <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>
1313</p >
1414
@@ -21,8 +21,9 @@ complex terminal applications, either inline, full-window, or a mix of both.
2121</p >
2222
2323Bubble Tea is in use in production and includes a number of features and
24- performance optimizations weβve added along the way. Among those is
25- a framerate-based renderer, mouse support, focus reporting and more.
24+ performance optimizations weβve added along the way. Among those is the
25+ cell-based rendering, built-in color downsampling, declarative views,
26+ improved keyboard and mouse handling, native clipboard support, and more.
2627
2728To get started, see the tutorial below, the [ examples] [ examples ] , the
2829[ docs] [ docs ] , the [ video tutorials] [ youtube ] and some common [ resources] ( #libraries-we-use-with-bubble-tea ) .
@@ -72,7 +73,7 @@ import (
7273 " fmt"
7374 " os"
7475
75- tea " github.com/charmbracelet /bubbletea/v2"
76+ tea " charm.land /bubbletea/v2"
7677)
7778```
7879
@@ -98,9 +99,9 @@ type model struct {
9899
99100## Initialization
100101
101- Next, weβll define our applicationβs initial state. In this case, weβre defining
102- a function to return our initial model, however , we could just as easily define
103- the initial model as a variable elsewhere, too.
102+ Next, weβll define our applicationβs initial state. ` Init ` can return a ` Cmd `
103+ that could perform some initial I/O. For now , we donβt need to do any I/O, so
104+ for the command, weβll just return ` nil ` , which translates to βno command.β
104105
105106``` go
106107func initialModel () model {
@@ -122,25 +123,15 @@ to do any I/O, so for the command, we'll just return `nil`, which translates to
122123"no command."
123124
124125``` go
125- func (m model ) Init () (tea .Model , tea .Cmd ) {
126- m = {
127- // Our to-do list is a grocery list
128- choices: []string {" Buy carrots" , " Buy celery" , " Buy kohlrabi" },
129-
130- // A map which indicates which choices are selected. We're using
131- // the map like a mathematical set. The keys refer to the indexes
132- // of the `choices` slice, above.
133- selected: make (map [int ]struct {}),
134- }
135-
126+ func (m model ) Init () tea .Cmd {
136127 // Just return `nil`, which means "no I/O right now, please."
137- return m, nil
128+ return nil
138129}
139130```
140131
141132### The Update Method
142133
143- Next up is the update method. The update function is called when β things
134+ Next up is the update method. The update function is called when β things
144135happen.β Its job is to look at what has happened and return an updated model in
145136response. It can also return a ` Cmd ` to make more things happen, but for now
146137don't worry about that part.
@@ -184,8 +175,8 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
184175 m.cursor ++
185176 }
186177
187- // The "enter" key and the space bar (a literal space) toggle the
188- // selected state for the item that the cursor is pointing at.
178+ // The "enter" key and the space bar toggle the selected state
179+ // for the item that the cursor is pointing at.
189180 case " enter" , " space" :
190181 _ , ok := m.selected [m.cursor ]
191182 if ok {
@@ -209,15 +200,16 @@ the Bubble Tea runtime to quit, exiting the program.
209200### The View Method
210201
211202At last, itβs time to render our UI. Of all the methods, the view is the
212- simplest. We look at the model in its current state and use it to return
213- a ` string ` . That string is our UI!
203+ simplest. We look at the model in its current state and use it to build a
204+ ` tea.View ` . The view declares our UI content and, optionally, terminal features
205+ like alt screen mode, mouse tracking, cursor position, and more.
214206
215207Because the view describes the entire UI of your application, you donβt have to
216208worry about redrawing logic and stuff like that. Bubble Tea takes care of it
217209for you.
218210
219211``` go
220- func (m model ) View () string {
212+ func (m model ) View () tea . View {
221213 // The header
222214 s := " What should we buy at the market?\n\n "
223215
@@ -244,7 +236,7 @@ func (m model) View() string {
244236 s += " \n Press q to quit.\n "
245237
246238 // Send the UI for rendering
247- return s
239+ return tea. NewView (s)
248240}
249241```
250242
@@ -274,7 +266,7 @@ there are [Go Docs][docs].
274266
275267[ cmd ] : https://github.com/charmbracelet/bubbletea/tree/main/tutorials/commands/
276268[ examples ] : https://github.com/charmbracelet/bubbletea/tree/main/examples
277- [ docs ] : https://pkg.go.dev/github.com/charmbracelet/ bubbletea?tab=doc
269+ [ docs ] : https://pkg.go.dev/charm.land/ bubbletea/v2 ?tab=doc
278270
279271## Debugging
280272
@@ -350,14 +342,14 @@ There are over [10,000 applications](https://github.com/charmbracelet/bubbletea/
350342
351343### In Industry
352344
353- - Microsoft Azure βΒ [ Aztify] ( https://github.com/Azure/aztfy ) : bring Microsoft Azure resources under Terraform
354- - Daytona βΒ [ Daytona] ( https://github.com/daytonaio/daytona ) : open source dev environment manager
345+ - Microsoft Azure β [ Aztify] ( https://github.com/Azure/aztfy ) : bring Microsoft Azure resources under Terraform
346+ - Daytona β [ Daytona] ( https://github.com/daytonaio/daytona ) : open source dev environment manager
355347- Cockroach Labs β [ CockroachDB] ( https://github.com/cockroachdb/cockroach ) : a cloud-native, high-availability distributed SQL database
356- - Truffle Security Co. βΒ [ Trufflehog] ( https://github.com/trufflesecurity/trufflehog ) : find leaked credentials
357- - NVIDIA βΒ [ container-canary] ( https://github.com/NVIDIA/container-canary ) : a container validator
358- - AWS βΒ [ eks-node-viewer] ( https://github.com/awslabs/eks-node-viewer ) : a tool for visualizing dynamic node usage within an EKS cluster
359- - MinIO βΒ [ mc] ( https://github.com/minio/mc ) : the official [ MinIO] ( https://min.io ) client
360- - Ubuntu βΒ [ Authd] ( https://github.com/ubuntu/authd ) : an authentication daemon for cloud-based identity providers
348+ - Truffle Security Co. β [ Trufflehog] ( https://github.com/trufflesecurity/trufflehog ) : find leaked credentials
349+ - NVIDIA β [ container-canary] ( https://github.com/NVIDIA/container-canary ) : a container validator
350+ - AWS β [ eks-node-viewer] ( https://github.com/awslabs/eks-node-viewer ) : a tool for visualizing dynamic node usage within an EKS cluster
351+ - MinIO β [ mc] ( https://github.com/minio/mc ) : the official [ MinIO] ( https://min.io ) client
352+ - Ubuntu β [ Authd] ( https://github.com/ubuntu/authd ) : an authentication daemon for cloud-based identity providers
361353
362354### Charm stuff
363355
0 commit comments