diff --git a/README.md b/README.md index d733d5d..56c077d 100644 --- a/README.md +++ b/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) *** diff --git a/commands.go b/commands.go index ff7a7b3..d634534 100644 --- a/commands.go +++ b/commands.go @@ -1,4 +1,4 @@ -package boba +package tea // Convenience commands. Note part of the Boba runtime, but potentially handy. diff --git a/commands_unix.go b/commands_unix.go index 5dc56cb..9951a86 100644 --- a/commands_unix.go +++ b/commands_unix.go @@ -1,6 +1,6 @@ // +build darwin dragonfly freebsd linux netbsd openbsd solaris -package boba +package tea import ( "os" diff --git a/commands_windows.go b/commands_windows.go index b96d7ca..464069b 100644 --- a/commands_windows.go +++ b/commands_windows.go @@ -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. diff --git a/examples/fullscreen/main.go b/examples/fullscreen/main.go index 445db07..2186d3d 100644 --- a/examples/fullscreen/main.go +++ b/examples/fullscreen/main.go @@ -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) }) } diff --git a/examples/go.mod b/examples/go.mod index 4549c07..2935ecd 100644 --- a/examples/go.mod +++ b/examples/go.mod @@ -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 ) diff --git a/examples/go.sum b/examples/go.sum index 7d6c3fb..fb00e06 100644 --- a/examples/go.sum +++ b/examples/go.sum @@ -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= diff --git a/examples/http/main.go b/examples/http/main.go index 62f1dc2..f31ac08 100644 --- a/examples/http/main.go +++ b/examples/http/main.go @@ -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, } diff --git a/examples/pager/main.go b/examples/pager/main.go index 760c9c1..30b800b 100644 --- a/examples/pager/main.go +++ b/examples/pager/main.go @@ -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, @@ -41,55 +42,55 @@ func (t terminalSizeMsg) Size() (int, int) { return t.width, t.height } func (t terminalSizeMsg) Error() error { return t.err } type model struct { - err error - content string - ready bool - pager pager.Model + err error + content string + ready bool + 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} }) } diff --git a/examples/simple/main.go b/examples/simple/main.go index b09abf1..288bdb1 100644 --- a/examples/simple/main.go +++ b/examples/simple/main.go @@ -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{} } diff --git a/examples/spinner/main.go b/examples/spinner/main.go index 488254b..95750c2 100644 --- a/examples/spinner/main.go +++ b/examples/spinner/main.go @@ -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" diff --git a/examples/textinput/main.go b/examples/textinput/main.go index 571ef47..b226757 100644 --- a/examples/textinput/main.go +++ b/examples/textinput/main.go @@ -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." diff --git a/examples/textinputs/main.go b/examples/textinputs/main.go index 75eb85b..1948862 100644 --- a/examples/textinputs/main.go +++ b/examples/textinputs/main.go @@ -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" diff --git a/examples/views/main.go b/examples/views/main.go index 4afc459..b14f2f2 100644 --- a/examples/views/main.go +++ b/examples/views/main.go @@ -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" diff --git a/go.mod b/go.mod index 91ecca7..a69549c 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/charmbracelet/boba +module github.com/charmbracelet/bubbletea go 1.13 diff --git a/key.go b/key.go index af13a93..f15bc25 100644 --- a/key.go +++ b/key.go @@ -1,4 +1,4 @@ -package boba +package tea import ( "errors" diff --git a/logging.go b/logging.go index 8d0f18b..e4f2385 100644 --- a/logging.go +++ b/logging.go @@ -1,6 +1,6 @@ // +build darwin dragonfly freebsd linux netbsd openbsd solaris -package boba +package tea import ( "log" diff --git a/paginator/paginator.go b/paginator/paginator.go index 924a48e..ee6b9eb 100644 --- a/paginator/paginator.go +++ b/paginator/paginator.go @@ -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" diff --git a/spinner/spinner.go b/spinner/spinner.go index acd2d5a..2f7bb73 100644 --- a/spinner/spinner.go +++ b/spinner/spinner.go @@ -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() diff --git a/boba.go b/tea.go similarity index 99% rename from boba.go rename to tea.go index a01bc96..2fdf2c5 100644 --- a/boba.go +++ b/tea.go @@ -1,4 +1,4 @@ -package boba +package tea import ( "io" diff --git a/textinput/textinput.go b/textinput/textinput.go index c43adf2..3d4a6c7 100644 --- a/textinput/textinput.go +++ b/textinput/textinput.go @@ -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{} } diff --git a/tty_unix.go b/tty_unix.go index b911585..8fe0339 100644 --- a/tty_unix.go +++ b/tty_unix.go @@ -1,6 +1,6 @@ // +build darwin dragonfly freebsd linux netbsd openbsd solaris -package boba +package tea import ( "github.com/muesli/termenv" diff --git a/tty_windows.go b/tty_windows.go index ae333e9..89d7e24 100644 --- a/tty_windows.go +++ b/tty_windows.go @@ -1,6 +1,6 @@ // +build windows -package boba +package tea import "github.com/muesli/termenv" diff --git a/viewport/viewport.go b/viewport/viewport.go index 2caed53..b56c251 100644 --- a/viewport/viewport.go +++ b/viewport/viewport.go @@ -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":