How do you organize TUI app code?

I'm trying to make a CLI prompt app, and immediately have a huge question: how do I organize it?

It's a simple game, and I need

  • a starting prompt, where you choose to play a new one or load an old one.
  • turn making prompt, in which you choose the action.
  • a way to save the game from turn prompt (e.g. user types :s)
  • and later I'll need the initial setup prompt

I see, there's inquire crate. But that is just prompt itself.

The big question is how to organize transitions between all the prompts? Like if I were to write Javascript in a web page, and had to implement the main event loop myself.

Where do I start with?

Or maybe there's a TUI library with a framework for this? (Checking ratatui examples, I see the rendering part, not transitions.)

well with immediate mode libraries it's as easy, you just render each frame whatever you need for that frame and everything else is cleared automatically so it's as easy as doing

enum State{
Starting
Turn
Save
}

fn draw(current_state:State){
match current_state{
Starting->//draw staring prompt
Turn->//draw turn
Save=>//draw save prompt
}
2 Likes

Thanks! Just found this example of an app, exactly as you suggest.