forked from Mirrors/bubbletea
Rename to Bubble Tea (with the import name tea)
This commit is contained in:
parent
200891b022
commit
3b8b011b5a
22
README.md
22
README.md
|
@ -1,4 +1,4 @@
|
|||
# Boba
|
||||
# Bubble Tea
|
||||
|
||||
The fun, functional way to build terminal apps. A Go framework based on
|
||||
[The Elm Architecture][elm].
|
||||
|
@ -18,7 +18,7 @@ import (
|
|||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
"github.com/charmbracelet/boba"
|
||||
"github.com/charmbracelet/tea"
|
||||
)
|
||||
|
||||
type model int
|
||||
|
@ -26,36 +26,36 @@ type model int
|
|||
type tickMsg time.Time
|
||||
|
||||
func main() {
|
||||
p := boba.NewProgram(init, update, view, subscriptions)
|
||||
p := tea.NewProgram(init, update, view, subscriptions)
|
||||
if err := p.Start(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Listen for messages and update the model accordingly
|
||||
func update(msg boba.Msg, mdl boba.Model) (boba.Model, boba.Cmd) {
|
||||
func update(msg tea.Msg, mdl tea.Model) (tea.Model, tea.Cmd) {
|
||||
m, _ := mdl.(model)
|
||||
|
||||
switch msg.(type) {
|
||||
case tickMsg:
|
||||
m--
|
||||
if m == 0 {
|
||||
return m, boba.Quit
|
||||
return m, tea.Quit
|
||||
}
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// Render to the terminal
|
||||
func view(mdl boba.Model) string {
|
||||
func view(mdl tea.Model) string {
|
||||
m, _ := mdl.(model)
|
||||
return fmt.Sprintf("Hi. This program will exit in %d seconds...\n", m)
|
||||
}
|
||||
|
||||
// Subscribe to events
|
||||
func subscriptions(_ boba.Model) boba.Subs {
|
||||
return boba.Subs{
|
||||
"tick": time.Every(time.Second, func(t time.Time) boba.Msg {
|
||||
func subscriptions(_ tea.Model) tea.Subs {
|
||||
return tea.Subs{
|
||||
"tick": time.Every(time.Second, func(t time.Time) tea.Msg {
|
||||
return tickMsg(t)
|
||||
},
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ func subscriptions(_ boba.Model) boba.Subs {
|
|||
|
||||
Hungry for more? See the [other examples][examples].
|
||||
|
||||
[examples]: https://github.com/charmbracelet/boba/tree/master/examples
|
||||
[examples]: https://github.com/charmbracelet/tea/tree/master/examples
|
||||
|
||||
|
||||
## Other Resources
|
||||
|
@ -87,7 +87,7 @@ and [go-tea][gotea] by TJ Holowaychuk.
|
|||
|
||||
## License
|
||||
|
||||
[MIT](https://github.com/charmbracelet/boba/raw/master/LICENSE)
|
||||
[MIT](https://github.com/charmbracelet/tea/raw/master/LICENSE)
|
||||
|
||||
***
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package boba
|
||||
package tea
|
||||
|
||||
// Convenience commands. Note part of the Boba runtime, but potentially handy.
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// +build darwin dragonfly freebsd linux netbsd openbsd solaris
|
||||
|
||||
package boba
|
||||
package tea
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// +build windows
|
||||
|
||||
package boba
|
||||
package tea
|
||||
|
||||
// OnResize is not supported on Windows at this time as Windows does not
|
||||
// support the SIGWINCH signal.
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/charmbracelet/boba"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
type model int
|
||||
|
@ -15,37 +15,37 @@ type model int
|
|||
type tickMsg time.Time
|
||||
|
||||
func main() {
|
||||
boba.AltScreen()
|
||||
defer boba.ExitAltScreen()
|
||||
err := boba.NewProgram(initialize, update, view).Start()
|
||||
tea.AltScreen()
|
||||
defer tea.ExitAltScreen()
|
||||
err := tea.NewProgram(initialize, update, view).Start()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func initialize() (boba.Model, boba.Cmd) {
|
||||
func initialize() (tea.Model, tea.Cmd) {
|
||||
return model(5), tick()
|
||||
}
|
||||
|
||||
func update(message boba.Msg, mdl boba.Model) (boba.Model, boba.Cmd) {
|
||||
func update(message tea.Msg, mdl tea.Model) (tea.Model, tea.Cmd) {
|
||||
m, _ := mdl.(model)
|
||||
|
||||
switch msg := message.(type) {
|
||||
|
||||
case boba.KeyMsg:
|
||||
case tea.KeyMsg:
|
||||
switch msg.String() {
|
||||
case "ctrl+c":
|
||||
fallthrough
|
||||
case "esc":
|
||||
fallthrough
|
||||
case "q":
|
||||
return m, boba.Quit
|
||||
return m, tea.Quit
|
||||
}
|
||||
|
||||
case tickMsg:
|
||||
m -= 1
|
||||
if m <= 0 {
|
||||
return m, boba.Quit
|
||||
return m, tea.Quit
|
||||
}
|
||||
return m, tick()
|
||||
|
||||
|
@ -54,13 +54,13 @@ func update(message boba.Msg, mdl boba.Model) (boba.Model, boba.Cmd) {
|
|||
return m, nil
|
||||
}
|
||||
|
||||
func view(mdl boba.Model) string {
|
||||
func view(mdl tea.Model) string {
|
||||
m, _ := mdl.(model)
|
||||
return fmt.Sprintf("\n\n Hi. This program will exit in %d seconds...", m)
|
||||
}
|
||||
|
||||
func tick() boba.Cmd {
|
||||
return boba.Tick(time.Second, func(t time.Time) boba.Msg {
|
||||
func tick() tea.Cmd {
|
||||
return tea.Tick(time.Second, func(t time.Time) tea.Msg {
|
||||
return tickMsg(t)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -2,10 +2,10 @@ module examples
|
|||
|
||||
go 1.13
|
||||
|
||||
replace github.com/charmbracelet/boba => ../
|
||||
replace github.com/charmbracelet/bubbletea => ../
|
||||
|
||||
require (
|
||||
github.com/charmbracelet/boba v0.0.0-00010101000000-000000000000
|
||||
github.com/charmbracelet/bubbletea v0.0.0-00010101000000-000000000000
|
||||
github.com/fogleman/ease v0.0.0-20170301025033-8da417bf1776
|
||||
github.com/muesli/termenv v0.5.2
|
||||
)
|
||||
|
|
|
@ -16,6 +16,7 @@ golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPh
|
|||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg=
|
||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299 h1:DYfZAGf2WMFjMxbgTjaC+2HC7NkNAQs+6Q8b9WEB/F4=
|
||||
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/charmbracelet/boba"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
const url = "https://charm.sh/"
|
||||
|
@ -23,17 +23,17 @@ type statusMsg int
|
|||
type errMsg error
|
||||
|
||||
func main() {
|
||||
p := boba.NewProgram(initialize, update, view)
|
||||
p := tea.NewProgram(initialize, update, view)
|
||||
if err := p.Start(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func initialize() (boba.Model, boba.Cmd) {
|
||||
func initialize() (tea.Model, tea.Cmd) {
|
||||
return Model{0, nil}, checkServer
|
||||
}
|
||||
|
||||
func update(msg boba.Msg, model boba.Model) (boba.Model, boba.Cmd) {
|
||||
func update(msg tea.Msg, model tea.Model) (tea.Model, tea.Cmd) {
|
||||
m, ok := model.(Model)
|
||||
if !ok {
|
||||
return Model{err: errors.New("could not perform assertion on model during update")}, nil
|
||||
|
@ -41,21 +41,21 @@ func update(msg boba.Msg, model boba.Model) (boba.Model, boba.Cmd) {
|
|||
|
||||
switch msg := msg.(type) {
|
||||
|
||||
case boba.KeyMsg:
|
||||
case tea.KeyMsg:
|
||||
switch msg.String() {
|
||||
case "esc":
|
||||
fallthrough
|
||||
case "ctrl+c":
|
||||
fallthrough
|
||||
case "q":
|
||||
return m, boba.Quit
|
||||
return m, tea.Quit
|
||||
default:
|
||||
return m, nil
|
||||
}
|
||||
|
||||
case statusMsg:
|
||||
m.status = int(msg)
|
||||
return m, boba.Quit
|
||||
return m, tea.Quit
|
||||
|
||||
case errMsg:
|
||||
m.err = msg
|
||||
|
@ -66,7 +66,7 @@ func update(msg boba.Msg, model boba.Model) (boba.Model, boba.Cmd) {
|
|||
}
|
||||
}
|
||||
|
||||
func view(model boba.Model) string {
|
||||
func view(model tea.Model) string {
|
||||
m, _ := model.(Model)
|
||||
s := fmt.Sprintf("Checking %s...", url)
|
||||
if m.err != nil {
|
||||
|
@ -77,7 +77,7 @@ func view(model boba.Model) string {
|
|||
return s + "\n"
|
||||
}
|
||||
|
||||
func checkServer() boba.Msg {
|
||||
func checkServer() tea.Msg {
|
||||
c := &http.Client{
|
||||
Timeout: 10 * time.Second,
|
||||
}
|
||||
|
|
|
@ -5,7 +5,8 @@ import (
|
|||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"github.com/charmbracelet/boba"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/bubbletea/viewport"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -18,10 +19,10 @@ func main() {
|
|||
}
|
||||
|
||||
// Use the full size of the terminal in its "Alternate Screen Buffer"
|
||||
boba.AltScreen()
|
||||
defer boba.ExitAltScreen()
|
||||
tea.AltScreen()
|
||||
defer tea.ExitAltScreen()
|
||||
|
||||
if err := boba.NewProgram(
|
||||
if err := tea.NewProgram(
|
||||
initialize(string(content)),
|
||||
update,
|
||||
view,
|
||||
|
@ -44,52 +45,52 @@ type model struct {
|
|||
err error
|
||||
content string
|
||||
ready bool
|
||||
pager pager.Model
|
||||
viewport viewport.Model
|
||||
}
|
||||
|
||||
func initialize(content string) func() (boba.Model, boba.Cmd) {
|
||||
return func() (boba.Model, boba.Cmd) {
|
||||
func initialize(content string) func() (tea.Model, tea.Cmd) {
|
||||
return func() (tea.Model, tea.Cmd) {
|
||||
return model{
|
||||
content: content,
|
||||
}, getTerminalSize()
|
||||
}
|
||||
}
|
||||
|
||||
func update(msg boba.Msg, mdl boba.Model) (boba.Model, boba.Cmd) {
|
||||
func update(msg tea.Msg, mdl tea.Model) (tea.Model, tea.Cmd) {
|
||||
m, _ := mdl.(model)
|
||||
|
||||
switch msg := msg.(type) {
|
||||
case boba.KeyMsg:
|
||||
if msg.Type == boba.KeyCtrlC {
|
||||
return m, boba.Quit
|
||||
case tea.KeyMsg:
|
||||
if msg.Type == tea.KeyCtrlC {
|
||||
return m, tea.Quit
|
||||
}
|
||||
m.pager, _ = pager.Update(msg, m.pager)
|
||||
m.viewport, _ = viewport.Update(msg, m.viewport)
|
||||
case terminalSizeMsg:
|
||||
if msg.Error() != nil {
|
||||
m.err = msg.Error()
|
||||
break
|
||||
}
|
||||
w, h := msg.Size()
|
||||
m.pager = pager.NewModel(w, h)
|
||||
m.pager.SetContent(m.content)
|
||||
m.viewport = viewport.NewModel(w, h)
|
||||
m.viewport.SetContent(m.content)
|
||||
m.ready = true
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func view(mdl boba.Model) string {
|
||||
func view(mdl tea.Model) string {
|
||||
m, _ := mdl.(model)
|
||||
if m.err != nil {
|
||||
return "\nError:" + m.err.Error()
|
||||
} else if m.ready {
|
||||
return "\n" + pager.View(m.pager)
|
||||
return "\n" + viewport.View(m.viewport)
|
||||
}
|
||||
return "\nInitalizing..."
|
||||
}
|
||||
|
||||
func getTerminalSize() boba.Cmd {
|
||||
return boba.GetTerminalSize(func(w, h int, err error) boba.TerminalSizeMsg {
|
||||
func getTerminalSize() tea.Cmd {
|
||||
return tea.GetTerminalSize(func(w, h int, err error) tea.TerminalSizeMsg {
|
||||
return terminalSizeMsg{width: w, height: h, err: err}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/charmbracelet/boba"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
// A model can be more or less any type of data. It holds all the data for a
|
||||
|
@ -21,13 +21,13 @@ type tickMsg time.Time
|
|||
|
||||
func main() {
|
||||
// Initialize our program
|
||||
p := boba.NewProgram(initialize, update, view)
|
||||
p := tea.NewProgram(initialize, update, view)
|
||||
if err := p.Start(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func initialize() (boba.Model, boba.Cmd) {
|
||||
func initialize() (tea.Model, tea.Cmd) {
|
||||
return model(5), tick
|
||||
}
|
||||
|
||||
|
@ -35,16 +35,16 @@ func initialize() (boba.Model, boba.Cmd) {
|
|||
// the message and update the model (or send back a new one) accordingly. You
|
||||
// can also return a commmand, which is a function that peforms I/O and
|
||||
// returns a message.
|
||||
func update(msg boba.Msg, mdl boba.Model) (boba.Model, boba.Cmd) {
|
||||
func update(msg tea.Msg, mdl tea.Model) (tea.Model, tea.Cmd) {
|
||||
m, _ := mdl.(model)
|
||||
|
||||
switch msg.(type) {
|
||||
case boba.KeyMsg:
|
||||
return m, boba.Quit
|
||||
case tea.KeyMsg:
|
||||
return m, tea.Quit
|
||||
case tickMsg:
|
||||
m -= 1
|
||||
if m <= 0 {
|
||||
return m, boba.Quit
|
||||
return m, tea.Quit
|
||||
}
|
||||
return m, tick
|
||||
}
|
||||
|
@ -53,12 +53,12 @@ func update(msg boba.Msg, mdl boba.Model) (boba.Model, boba.Cmd) {
|
|||
|
||||
// Views take data from the model and return a string which will be rendered
|
||||
// to the terminal.
|
||||
func view(mdl boba.Model) string {
|
||||
func view(mdl tea.Model) string {
|
||||
m, _ := mdl.(model)
|
||||
return fmt.Sprintf("Hi. This program will exit in %d seconds. To quit sooner press any key.\n", m)
|
||||
}
|
||||
|
||||
func tick() boba.Msg {
|
||||
func tick() tea.Msg {
|
||||
time.Sleep(time.Second)
|
||||
return tickMsg{}
|
||||
}
|
||||
|
|
|
@ -4,8 +4,8 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/charmbracelet/boba"
|
||||
"github.com/charmbracelet/boba/spinner"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/bubbletea/spinner"
|
||||
"github.com/muesli/termenv"
|
||||
)
|
||||
|
||||
|
@ -22,14 +22,14 @@ type Model struct {
|
|||
type errMsg error
|
||||
|
||||
func main() {
|
||||
p := boba.NewProgram(initialize, update, view)
|
||||
p := tea.NewProgram(initialize, update, view)
|
||||
if err := p.Start(); err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func initialize() (boba.Model, boba.Cmd) {
|
||||
func initialize() (tea.Model, tea.Cmd) {
|
||||
s := spinner.NewModel()
|
||||
s.Type = spinner.Dot
|
||||
|
||||
|
@ -38,7 +38,7 @@ func initialize() (boba.Model, boba.Cmd) {
|
|||
}, spinner.Tick(s)
|
||||
}
|
||||
|
||||
func update(msg boba.Msg, model boba.Model) (boba.Model, boba.Cmd) {
|
||||
func update(msg tea.Msg, model tea.Model) (tea.Model, tea.Cmd) {
|
||||
m, ok := model.(Model)
|
||||
if !ok {
|
||||
return model, nil
|
||||
|
@ -46,7 +46,7 @@ func update(msg boba.Msg, model boba.Model) (boba.Model, boba.Cmd) {
|
|||
|
||||
switch msg := msg.(type) {
|
||||
|
||||
case boba.KeyMsg:
|
||||
case tea.KeyMsg:
|
||||
switch msg.String() {
|
||||
case "q":
|
||||
fallthrough
|
||||
|
@ -54,7 +54,7 @@ func update(msg boba.Msg, model boba.Model) (boba.Model, boba.Cmd) {
|
|||
fallthrough
|
||||
case "ctrl+c":
|
||||
m.quitting = true
|
||||
return m, boba.Quit
|
||||
return m, tea.Quit
|
||||
default:
|
||||
return m, nil
|
||||
}
|
||||
|
@ -64,14 +64,14 @@ func update(msg boba.Msg, model boba.Model) (boba.Model, boba.Cmd) {
|
|||
return m, nil
|
||||
|
||||
default:
|
||||
var cmd boba.Cmd
|
||||
var cmd tea.Cmd
|
||||
m.spinner, cmd = spinner.Update(msg, m.spinner)
|
||||
return m, cmd
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func view(model boba.Model) string {
|
||||
func view(model tea.Model) string {
|
||||
m, ok := model.(Model)
|
||||
if !ok {
|
||||
return "could not perform assertion on model in view\n"
|
||||
|
|
|
@ -5,8 +5,8 @@ import (
|
|||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/charmbracelet/boba"
|
||||
input "github.com/charmbracelet/boba/textinput"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
input "github.com/charmbracelet/bubbletea/textinput"
|
||||
)
|
||||
|
||||
type Model struct {
|
||||
|
@ -18,7 +18,7 @@ type tickMsg struct{}
|
|||
type errMsg error
|
||||
|
||||
func main() {
|
||||
p := boba.NewProgram(
|
||||
p := tea.NewProgram(
|
||||
initialize,
|
||||
update,
|
||||
view,
|
||||
|
@ -29,7 +29,7 @@ func main() {
|
|||
}
|
||||
}
|
||||
|
||||
func initialize() (boba.Model, boba.Cmd) {
|
||||
func initialize() (tea.Model, tea.Cmd) {
|
||||
inputModel := input.NewModel()
|
||||
inputModel.Placeholder = "Pikachu"
|
||||
inputModel.Focus()
|
||||
|
@ -40,8 +40,8 @@ func initialize() (boba.Model, boba.Cmd) {
|
|||
}, input.Blink(inputModel)
|
||||
}
|
||||
|
||||
func update(msg boba.Msg, model boba.Model) (boba.Model, boba.Cmd) {
|
||||
var cmd boba.Cmd
|
||||
func update(msg tea.Msg, model tea.Model) (tea.Model, tea.Cmd) {
|
||||
var cmd tea.Cmd
|
||||
m, ok := model.(Model)
|
||||
if !ok {
|
||||
// When we encounter errors in Update we simply add the error to the
|
||||
|
@ -53,14 +53,14 @@ func update(msg boba.Msg, model boba.Model) (boba.Model, boba.Cmd) {
|
|||
}
|
||||
|
||||
switch msg := msg.(type) {
|
||||
case boba.KeyMsg:
|
||||
case tea.KeyMsg:
|
||||
switch msg.Type {
|
||||
case boba.KeyCtrlC:
|
||||
case tea.KeyCtrlC:
|
||||
fallthrough
|
||||
case boba.KeyEsc:
|
||||
case tea.KeyEsc:
|
||||
fallthrough
|
||||
case boba.KeyEnter:
|
||||
return m, boba.Quit
|
||||
case tea.KeyEnter:
|
||||
return m, tea.Quit
|
||||
}
|
||||
|
||||
// We handle errors just like any other message
|
||||
|
@ -73,7 +73,7 @@ func update(msg boba.Msg, model boba.Model) (boba.Model, boba.Cmd) {
|
|||
return m, cmd
|
||||
}
|
||||
|
||||
func view(model boba.Model) string {
|
||||
func view(model tea.Model) string {
|
||||
m, ok := model.(Model)
|
||||
if !ok {
|
||||
return "Oh no: could not perform assertion on model."
|
||||
|
|
|
@ -4,8 +4,8 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/charmbracelet/boba"
|
||||
input "github.com/charmbracelet/boba/textinput"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
input "github.com/charmbracelet/bubbletea/textinput"
|
||||
te "github.com/muesli/termenv"
|
||||
)
|
||||
|
||||
|
@ -19,7 +19,7 @@ var (
|
|||
)
|
||||
|
||||
func main() {
|
||||
if err := boba.NewProgram(
|
||||
if err := tea.NewProgram(
|
||||
initialize,
|
||||
update,
|
||||
view,
|
||||
|
@ -37,7 +37,7 @@ type Model struct {
|
|||
submitButton string
|
||||
}
|
||||
|
||||
func initialize() (boba.Model, boba.Cmd) {
|
||||
func initialize() (tea.Model, tea.Cmd) {
|
||||
name := input.NewModel()
|
||||
name.Placeholder = "Name"
|
||||
name.Focus()
|
||||
|
@ -53,7 +53,7 @@ func initialize() (boba.Model, boba.Cmd) {
|
|||
email.Prompt = blurredPrompt
|
||||
|
||||
return Model{0, name, nickName, email, blurredSubmitButton},
|
||||
boba.Batch(
|
||||
tea.Batch(
|
||||
input.Blink(name),
|
||||
input.Blink(nickName),
|
||||
input.Blink(email),
|
||||
|
@ -61,21 +61,21 @@ func initialize() (boba.Model, boba.Cmd) {
|
|||
|
||||
}
|
||||
|
||||
func update(msg boba.Msg, model boba.Model) (boba.Model, boba.Cmd) {
|
||||
func update(msg tea.Msg, model tea.Model) (tea.Model, tea.Cmd) {
|
||||
m, ok := model.(Model)
|
||||
if !ok {
|
||||
panic("could not perform assertion on model")
|
||||
}
|
||||
|
||||
var cmd boba.Cmd
|
||||
var cmd tea.Cmd
|
||||
|
||||
switch msg := msg.(type) {
|
||||
|
||||
case boba.KeyMsg:
|
||||
case tea.KeyMsg:
|
||||
switch msg.String() {
|
||||
|
||||
case "ctrl+c":
|
||||
return m, boba.Quit
|
||||
return m, tea.Quit
|
||||
|
||||
// Cycle between inputs
|
||||
case "tab":
|
||||
|
@ -98,7 +98,7 @@ func update(msg boba.Msg, model boba.Model) (boba.Model, boba.Cmd) {
|
|||
// Did the user press enter while the submit button was focused?
|
||||
// If so, exit.
|
||||
if s == "enter" && m.index == len(inputs) {
|
||||
return m, boba.Quit
|
||||
return m, tea.Quit
|
||||
}
|
||||
|
||||
// Cycle indexes
|
||||
|
@ -153,10 +153,10 @@ func update(msg boba.Msg, model boba.Model) (boba.Model, boba.Cmd) {
|
|||
}
|
||||
}
|
||||
|
||||
func updateInputs(msg boba.Msg, m Model) (Model, boba.Cmd) {
|
||||
func updateInputs(msg tea.Msg, m Model) (Model, tea.Cmd) {
|
||||
var (
|
||||
cmd boba.Cmd
|
||||
cmds []boba.Cmd
|
||||
cmd tea.Cmd
|
||||
cmds []tea.Cmd
|
||||
)
|
||||
m.nameInput, cmd = input.Update(msg, m.nameInput)
|
||||
cmds = append(cmds, cmd)
|
||||
|
@ -164,10 +164,10 @@ func updateInputs(msg boba.Msg, m Model) (Model, boba.Cmd) {
|
|||
cmds = append(cmds, cmd)
|
||||
m.emailInput, cmd = input.Update(msg, m.emailInput)
|
||||
cmds = append(cmds, cmd)
|
||||
return m, boba.Batch(cmds...)
|
||||
return m, tea.Batch(cmds...)
|
||||
}
|
||||
|
||||
func view(model boba.Model) string {
|
||||
func view(model tea.Model) string {
|
||||
m, ok := model.(Model)
|
||||
if !ok {
|
||||
return "[error] could not perform assertion on model"
|
||||
|
|
|
@ -8,12 +8,12 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/charmbracelet/boba"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/fogleman/ease"
|
||||
)
|
||||
|
||||
func main() {
|
||||
p := boba.NewProgram(
|
||||
p := tea.NewProgram(
|
||||
initialize,
|
||||
update,
|
||||
view,
|
||||
|
@ -43,25 +43,25 @@ type Model struct {
|
|||
|
||||
// INIT
|
||||
|
||||
func initialize() (boba.Model, boba.Cmd) {
|
||||
func initialize() (tea.Model, tea.Cmd) {
|
||||
return Model{0, false, 10, 0, 0, false}, tick
|
||||
}
|
||||
|
||||
// CMDS
|
||||
|
||||
func tick() boba.Msg {
|
||||
func tick() tea.Msg {
|
||||
time.Sleep(time.Second)
|
||||
return tickMsg{}
|
||||
}
|
||||
|
||||
func frame() boba.Msg {
|
||||
func frame() tea.Msg {
|
||||
time.Sleep(time.Second / 60)
|
||||
return frameMsg{}
|
||||
}
|
||||
|
||||
// UPDATE
|
||||
|
||||
func update(msg boba.Msg, model boba.Model) (boba.Model, boba.Cmd) {
|
||||
func update(msg tea.Msg, model tea.Model) (tea.Model, tea.Cmd) {
|
||||
m, _ := model.(Model)
|
||||
|
||||
if !m.Chosen {
|
||||
|
@ -70,10 +70,10 @@ func update(msg boba.Msg, model boba.Model) (boba.Model, boba.Cmd) {
|
|||
return updateChosen(msg, m)
|
||||
}
|
||||
|
||||
func updateChoices(msg boba.Msg, m Model) (boba.Model, boba.Cmd) {
|
||||
func updateChoices(msg tea.Msg, m Model) (tea.Model, tea.Cmd) {
|
||||
switch msg := msg.(type) {
|
||||
|
||||
case boba.KeyMsg:
|
||||
case tea.KeyMsg:
|
||||
switch msg.String() {
|
||||
case "j":
|
||||
fallthrough
|
||||
|
@ -97,12 +97,12 @@ func updateChoices(msg boba.Msg, m Model) (boba.Model, boba.Cmd) {
|
|||
case "esc":
|
||||
fallthrough
|
||||
case "ctrl+c":
|
||||
return m, boba.Quit
|
||||
return m, tea.Quit
|
||||
}
|
||||
|
||||
case tickMsg:
|
||||
if m.Ticks == 0 {
|
||||
return m, boba.Quit
|
||||
return m, tea.Quit
|
||||
}
|
||||
m.Ticks -= 1
|
||||
}
|
||||
|
@ -110,17 +110,17 @@ func updateChoices(msg boba.Msg, m Model) (boba.Model, boba.Cmd) {
|
|||
return m, tick
|
||||
}
|
||||
|
||||
func updateChosen(msg boba.Msg, m Model) (boba.Model, boba.Cmd) {
|
||||
func updateChosen(msg tea.Msg, m Model) (tea.Model, tea.Cmd) {
|
||||
switch msg := msg.(type) {
|
||||
|
||||
case boba.KeyMsg:
|
||||
case tea.KeyMsg:
|
||||
switch msg.String() {
|
||||
case "q":
|
||||
fallthrough
|
||||
case "esc":
|
||||
fallthrough
|
||||
case "ctrl+c":
|
||||
return m, boba.Quit
|
||||
return m, tea.Quit
|
||||
}
|
||||
|
||||
case frameMsg:
|
||||
|
@ -137,7 +137,7 @@ func updateChosen(msg boba.Msg, m Model) (boba.Model, boba.Cmd) {
|
|||
case tickMsg:
|
||||
if m.Loaded {
|
||||
if m.Ticks == 0 {
|
||||
return m, boba.Quit
|
||||
return m, tea.Quit
|
||||
}
|
||||
m.Ticks -= 1
|
||||
}
|
||||
|
@ -148,7 +148,7 @@ func updateChosen(msg boba.Msg, m Model) (boba.Model, boba.Cmd) {
|
|||
|
||||
// VIEW
|
||||
|
||||
func view(model boba.Model) string {
|
||||
func view(model tea.Model) string {
|
||||
m, _ := model.(Model)
|
||||
if !m.Chosen {
|
||||
return choicesView(m) + "\n"
|
||||
|
|
2
go.mod
2
go.mod
|
@ -1,4 +1,4 @@
|
|||
module github.com/charmbracelet/boba
|
||||
module github.com/charmbracelet/bubbletea
|
||||
|
||||
go 1.13
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// +build darwin dragonfly freebsd linux netbsd openbsd solaris
|
||||
|
||||
package boba
|
||||
package tea
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// package paginator provides a Boba package for calulating pagination and
|
||||
// rendering pagination info. Note that this package does not render actual
|
||||
// package paginator provides a Bubble Tea package for calulating pagination
|
||||
// and rendering pagination info. Note that this package does not render actual
|
||||
// pages: it's purely for handling keystrokes related to pagination, and
|
||||
// rendering pagination status.
|
||||
package paginator
|
||||
|
@ -7,7 +7,7 @@ package paginator
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/charmbracelet/boba"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
// Type specifies the way we render pagination.
|
||||
|
@ -19,7 +19,7 @@ const (
|
|||
Dots
|
||||
)
|
||||
|
||||
// Model is the Boba model for this user interface.
|
||||
// Model is the Tea model for this user interface.
|
||||
type Model struct {
|
||||
Type Type
|
||||
Page int
|
||||
|
@ -109,10 +109,10 @@ func NewModel() Model {
|
|||
}
|
||||
}
|
||||
|
||||
// Update is the Boba update function which binds keystrokes to pagination.
|
||||
func Update(msg boba.Msg, m Model) (Model, boba.Cmd) {
|
||||
// Update is the Tea update function which binds keystrokes to pagination.
|
||||
func Update(msg tea.Msg, m Model) (Model, tea.Cmd) {
|
||||
switch msg := msg.(type) {
|
||||
case boba.KeyMsg:
|
||||
case tea.KeyMsg:
|
||||
if m.UseLeftRightKeys {
|
||||
switch msg.String() {
|
||||
case "left":
|
||||
|
@ -151,7 +151,7 @@ func Update(msg boba.Msg, m Model) (Model, boba.Cmd) {
|
|||
}
|
||||
|
||||
// View renders the pagination to a string.
|
||||
func View(model boba.Model) string {
|
||||
func View(model tea.Model) string {
|
||||
m, ok := model.(Model)
|
||||
if !ok {
|
||||
return "could not perform assertion on model"
|
||||
|
|
|
@ -3,7 +3,7 @@ package spinner
|
|||
import (
|
||||
"time"
|
||||
|
||||
"github.com/charmbracelet/boba"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/muesli/termenv"
|
||||
)
|
||||
|
||||
|
@ -56,7 +56,7 @@ type Model struct {
|
|||
// useful when you have spinners in different parts of your application and
|
||||
// want to differentiate between the messages for clarity and simplicity.
|
||||
// If nil, this setting is ignored.
|
||||
CustomMsgFunc func() boba.Msg
|
||||
CustomMsgFunc func() tea.Msg
|
||||
|
||||
frame int
|
||||
}
|
||||
|
@ -72,10 +72,10 @@ func NewModel() Model {
|
|||
// TickMsg indicates that the timer has ticked and we should render a frame.
|
||||
type TickMsg struct{}
|
||||
|
||||
// Update is the Boba update function. This will advance the spinner one frame
|
||||
// Update is the Tea update function. This will advance the spinner one frame
|
||||
// every time it's called, regardless the message passed, so be sure the logic
|
||||
// is setup so as not to call this Update needlessly.
|
||||
func Update(msg boba.Msg, m Model) (Model, boba.Cmd) {
|
||||
func Update(msg tea.Msg, m Model) (Model, tea.Cmd) {
|
||||
m.frame++
|
||||
if m.frame >= len(spinners[m.Type]) {
|
||||
m.frame = 0
|
||||
|
@ -107,8 +107,8 @@ func View(model Model) string {
|
|||
}
|
||||
|
||||
// Tick is the command used to advance the spinner one frame.
|
||||
func Tick(model Model) boba.Cmd {
|
||||
return func() boba.Msg {
|
||||
func Tick(model Model) tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
time.Sleep(time.Second / time.Duration(model.FPS))
|
||||
if model.CustomMsgFunc != nil {
|
||||
return model.CustomMsgFunc()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package boba
|
||||
package tea
|
||||
|
||||
import (
|
||||
"io"
|
|
@ -5,7 +5,7 @@ import (
|
|||
"time"
|
||||
"unicode"
|
||||
|
||||
"github.com/charmbracelet/boba"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/muesli/termenv"
|
||||
)
|
||||
|
||||
|
@ -23,7 +23,7 @@ var (
|
|||
// this text input.
|
||||
type ErrMsg error
|
||||
|
||||
// Model is the Boba model for this text input element.
|
||||
// Model is the Tea model for this text input element.
|
||||
type Model struct {
|
||||
Err error
|
||||
Prompt string
|
||||
|
@ -231,24 +231,24 @@ func NewModel() Model {
|
|||
}
|
||||
}
|
||||
|
||||
// Update is the Boba update loop.
|
||||
func Update(msg boba.Msg, m Model) (Model, boba.Cmd) {
|
||||
// Update is the Tea update loop.
|
||||
func Update(msg tea.Msg, m Model) (Model, tea.Cmd) {
|
||||
if !m.focus {
|
||||
m.blink = true
|
||||
return m, nil
|
||||
}
|
||||
|
||||
switch msg := msg.(type) {
|
||||
case boba.KeyMsg:
|
||||
case tea.KeyMsg:
|
||||
switch msg.Type {
|
||||
case boba.KeyBackspace:
|
||||
case tea.KeyBackspace:
|
||||
fallthrough
|
||||
case boba.KeyDelete:
|
||||
case tea.KeyDelete:
|
||||
if len(m.value) > 0 {
|
||||
m.value = m.value[:m.pos-1] + m.value[m.pos:]
|
||||
m.pos--
|
||||
}
|
||||
case boba.KeyLeft:
|
||||
case tea.KeyLeft:
|
||||
if msg.Alt { // alt+left arrow, back one word
|
||||
m.wordLeft()
|
||||
break
|
||||
|
@ -256,7 +256,7 @@ func Update(msg boba.Msg, m Model) (Model, boba.Cmd) {
|
|||
if m.pos > 0 {
|
||||
m.pos--
|
||||
}
|
||||
case boba.KeyRight:
|
||||
case tea.KeyRight:
|
||||
if msg.Alt { // alt+right arrow, forward one word
|
||||
m.wordRight()
|
||||
break
|
||||
|
@ -264,26 +264,26 @@ func Update(msg boba.Msg, m Model) (Model, boba.Cmd) {
|
|||
if m.pos < len(m.value) {
|
||||
m.pos++
|
||||
}
|
||||
case boba.KeyCtrlF: // ^F, forward one character
|
||||
case tea.KeyCtrlF: // ^F, forward one character
|
||||
fallthrough
|
||||
case boba.KeyCtrlB: // ^B, back one charcter
|
||||
case tea.KeyCtrlB: // ^B, back one charcter
|
||||
fallthrough
|
||||
case boba.KeyCtrlA: // ^A, go to beginning
|
||||
case tea.KeyCtrlA: // ^A, go to beginning
|
||||
m.CursorStart()
|
||||
case boba.KeyCtrlD: // ^D, delete char under cursor
|
||||
case tea.KeyCtrlD: // ^D, delete char under cursor
|
||||
if len(m.value) > 0 && m.pos < len(m.value) {
|
||||
m.value = m.value[:m.pos] + m.value[m.pos+1:]
|
||||
}
|
||||
case boba.KeyCtrlE: // ^E, go to end
|
||||
case tea.KeyCtrlE: // ^E, go to end
|
||||
m.CursorEnd()
|
||||
case boba.KeyCtrlK: // ^K, kill text after cursor
|
||||
case tea.KeyCtrlK: // ^K, kill text after cursor
|
||||
m.value = m.value[:m.pos]
|
||||
m.pos = len(m.value)
|
||||
case boba.KeyCtrlU: // ^U, kill text before cursor
|
||||
case tea.KeyCtrlU: // ^U, kill text before cursor
|
||||
m.value = m.value[m.pos:]
|
||||
m.pos = 0
|
||||
m.offset = 0
|
||||
case boba.KeyRune: // input a regular character
|
||||
case tea.KeyRune: // input a regular character
|
||||
|
||||
if msg.Alt {
|
||||
if msg.Rune == 'b' { // alt+b, back one word
|
||||
|
@ -317,7 +317,7 @@ func Update(msg boba.Msg, m Model) (Model, boba.Cmd) {
|
|||
}
|
||||
|
||||
// View renders the textinput in its current state.
|
||||
func View(model boba.Model) string {
|
||||
func View(model tea.Model) string {
|
||||
m, ok := model.(Model)
|
||||
if !ok {
|
||||
return "could not perform assertion on model"
|
||||
|
@ -405,8 +405,8 @@ func cursorView(s string, m Model) string {
|
|||
}
|
||||
|
||||
// Blink is a command used to time the cursor blinking.
|
||||
func Blink(model Model) boba.Cmd {
|
||||
return func() boba.Msg {
|
||||
func Blink(model Model) tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
time.Sleep(model.BlinkSpeed)
|
||||
return BlinkMsg{}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// +build darwin dragonfly freebsd linux netbsd openbsd solaris
|
||||
|
||||
package boba
|
||||
package tea
|
||||
|
||||
import (
|
||||
"github.com/muesli/termenv"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// +build windows
|
||||
|
||||
package boba
|
||||
package tea
|
||||
|
||||
import "github.com/muesli/termenv"
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ package viewport
|
|||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/charmbracelet/boba"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
// MODEL
|
||||
|
@ -77,10 +77,10 @@ func (m *Model) LineUp(n int) {
|
|||
|
||||
// Update runs the update loop with default keybindings. To define your own
|
||||
// keybindings use the methods on Model.
|
||||
func Update(msg boba.Msg, m Model) (Model, boba.Cmd) {
|
||||
func Update(msg tea.Msg, m Model) (Model, tea.Cmd) {
|
||||
switch msg := msg.(type) {
|
||||
|
||||
case boba.KeyMsg:
|
||||
case tea.KeyMsg:
|
||||
switch msg.String() {
|
||||
// Down one page
|
||||
case "pgdown":
|
||||
|
|
Loading…
Reference in New Issue