Closed aymanbagabas closed 1 month ago
This would be incredibly useful for passing global context to submodels.
After some testing and feedback, we've determined we can proceed towards v2 without the context changes proposed here. This will reduce the barrier to upgrading and keep Bubble Tea easier to work with overall.
Thanks to everyone who helped us test this proposal!
@meowgorithm Since this change isn't happening, how do you recommend passing state between submodules in a bubble tea program?
@carreter you use
p := tea.NewProgram(model{}, tea.WithContext(ctx))
https://github.com/charmbracelet/bubbletea/blob/105d88a7282a810529c37f08fa7c03392860a80e/options.go#L20 though this is only for cancelling the program, not plumbing it into other parts
During the execution of the program, models need to access the underlying terminal features and capabilities. We can achieved this with an API change that introduces Bubble Tea
Context
s. The nice thing about thisContext
type is that it can be used to control executions of goroutines because it embedscontext.Context
. Usingtea.WithContext(ctx)
, users can access the provided context before running the program in their Bubble Tea model.Bubble Tea Model Context
This fixes all sorts of issues with input and color, particularly in Wish. Basically, apps built on Bubble Tea v2 will “just work” if put behind a Wish server.
This also means that Bubble Tea now has first-class Lip Gloss support. Now, with the new advanced input handler, Bubble Tea can read and parse any type of sequence events as the terminal input buffer receive them. This means that important events that can change the look and behavor of our program can be detected in Bubble Tea. When the program starts, it will query the terminal for Kitty Keyboard support and the current terminal's background color. The background color is important because it affects Lip Gloss styles.
You can now use the new
tea.Context
to read different terminal capabilities. Bubble Tea now does all the heavy lifting of detecting terminal colors and background and can createctx.NewStyle()
that are specific to the current running program (whether local or in a remote session). This will also pave the road for future improvements to be added on the context.The new interface will look like this:
How to upgrade
You can find a WIP version of this proposal here