Documentation
¶
Overview ¶
Package modelstack impliments a tea.Model (from Bubbletea) that listens for PushModel and PopModel tea.Msg-s to switch control between several tea.Model-s, including some initialization maintinance.
This allows easier re-use of tea.Model-s 'within' each other. However it breaks some assumptions about how your model will be used by bubbletea. The noteable behavioral differences are listed here:
- .Init() is called on your tea.Model every time it (re)gains control (not just once).
- While another tea.Model is in control, your tea.Model will not receive any tea.Msg-s.
- When a tea.Cmd resolves, its tea.Msg will be sent to the currently active tea.Model, regardless of which tea.Model sent the tea.Cmd.
For the most part, things should "just work", but keep a few things in mind when designing tea.Model-s you want to be compatible with this package:
- Be sure to initialize ticks in .Init()
- Wait for tea.Cmd-s you want to resolve before passing control. tea.Sequence can be useful for this.
- Be able to handle tea.Msg-s going missing if it's possible for control to be lost mid-processing of a tea.Cmd.
- Remember the model on the stack is the same model, not a re-initialized one (though .Init() is called again).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ModelStack ¶
type ModelStack struct {
// contains filtered or unexported fields
}
ModelStack is a tea.Model that listens for PushModel and PopModel tea.Msg's to switch control between several tea.Model's
func New ¶
func New(m tea.Model, opts ...Option) ModelStack
New creates a new Modelstack with an initial tea.Model
func (ModelStack) Init ¶
func (m ModelStack) Init() tea.Cmd
Init fulfills the tea.Model interface, currently it just calls Init() on the current tea.Model on the stack
func (ModelStack) Update ¶
Update fulfills the tea.Model interface, intercepting PushModel and PopModel tea.Msg's, as well as information needed to initialize models as they switch control (e.g. the most recent tea.WindowSizeMsg)
func (ModelStack) View ¶
func (m ModelStack) View() string
View fulfills the tea.Model interface, rendering the currently active tea.Model on its stack
type Option ¶
type Option func(*ModelStack)
Option is used to set options when initializing a ModelStack
func WithSlogger ¶
WithSlogger attaches a *slog.Logger to a ModelStack
type PopModel ¶
type PopModel struct { // Msgs are tea.Msg-s that will be passed to the parent model synchronously // when it regains control (before its first call to .View(), after calling // .Init()) Msgs []tea.Msg }
PopModel is a tea.Msg that instructs a ModelStack to remove the current tea.Model from the stack and pass control to the previous tea.Model