Skip to main content

Get the Reddit app

Scan this QR code to download the app now
Or check it out in the app stores
r/golang icon
r/golang icon
Go to golang
r/golang
A banner for the subreddit

Ask questions and post articles about the Go programming language and related tools, events etc.


Members Online

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.

Share
Sort by:
Best
Open comment sort options
u/idhats avatar

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.

u/idhats avatar

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.

More replies

Hey, do you have any toy project I'm GitHub implementing that?

u/idhats avatar
More replies
More replies
u/Odd_Measurement_6131 avatar

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?

u/Odd_Measurement_6131 avatar

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

More replies
More replies

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

More replies