Is there a commonly accepted way to have several "pages" in a bubbletea app
As the title imply, I am looking at how one would design a bubbletea app with several pages/views, each having a model, and wether there is a standard/widely accepted way to do it. I know how I would implement it in an ad-hoc fashion, but I wonder if there is some generic solution.
I do this frequently. I make a model which is just a wrapper for the "pages." I usually call it a ModalScreenUI. It will have "modes" and a single struct field in the model to contain the current mode. The update/view will just do a switch on the mode field and call the subordinate update/view method of the wrapped "page" model, whatever it is.
Ever needed a stack of modes where you can push and pop? Like a pause menu in a game that can be pushed on top of any level.
I don't see why you couldn't do a stack-based implementation for the UI instead of a modal like I suggested. I'm not sure how to render on top of an existing block of text, but there are probably package level functions in bubbletea or the other charm libs that do it.
Hey, do you have any toy project I'm GitHub implementing that?
https://github.com/gravestench/torchbearer/blob/main/pkg/services/tui/modal_ui_model.go
I simply create a New method for each model and return it as the tea.Model on page change
So you don't preserve the state of previous page?
There's not much state in my application besides the main page. I manage the state seperately and rehydrate it in the "New" method for each model
https://shi.foo/weblog/multi-view-interfaces-in-bubble-tea
Yeah, an ad-hoc solution, but the pattern is globally always the same I guess:
a model for each page with their own methods
a root model to pass data between pages and keep state along