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