The goal of bubblenav is to provide easy to use navigation helpers for bubbletea applications.
Simply wrap your actual models with nav.NavPage
or nav.NavStack
and emit nav.Push(tea.Model) tea.Cmd
to push a new app model as a new page. Call nav.Pop()
to remove the current page from the top of the stack.
- Bubblenav will call the
Init()
method of yourtea.Model
. - Only the currently active page model will receive
Update
. - Recorded
tea.WindowSizeMsg
will be repeated for new pages. esc
will pop the currnet page.- Unless
DisableQuitKeyBindings()
called,q
andctrl+c
will quit. - With
Replace
you navigate irreversibly and replace the current page.
package tui
import (
tea "github.com/charmbracelet/bubbletea"
nav "github.com/vknabel/go-bubblenav"
)
func main() {
var initial tea.Model = initialModel()
wrapped := nav.NavPage(initial)
err := tea.NewProgram(wrapped).Start()
if err != nil {
panic(err)
}
}
// ...
func (m myModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
switch msg.String() {
case "n":
return m, nav.Push(nextPage())
}
}
return m, nil
}
go get github.com/vknabel/go-bubblenav
- Decide between
nav.NavPage
andnav.NavStack
and remove the other. Both are different implementations of the same concept. - Implement a modal.
Licensed under the MIT License.