What I did recently when developing a TUI was that I put the state in a dict, start the app in an infinite loop and whenever it quit, reload module, keep the state and instantiate the class with that state again. Something like this:

    import tui
    state = {"current_step_index": 0, "variables": None}
    while True:
        app = tui.App(state)
        tui.run()
        state = app.get_state()
        importlib.reload(tui)