blessed
blessed copied to clipboard
Question: Routing between screens
I am trying to understand how to add routes to my blessed
application. I have two different boxes (each represent a different screen) and I want one of them to be visible and active at the time and then the user can switch between. What would be the optimal way of doing that? Should I append both and hide()/show()
one of them each time? Should I append()
the one that the user wants to switch to and remove()
the other? Should I append both and then control and the Z axis (setFront()
/setBack()
) of each? Thank you
Interesting! also wandering which would be the best approach. Instantiate only one or all? destroy the screen? and recreate it each time? I would like to know more about this, sorry for the OT. I think it depends on how important is the switch effect speed in your case.
Currently What I'm doing, (just started/learning) is destroying the view and painting it all again. My app is stateful so is not much risk of forgotten references. But a problem I'm having is the following. When talking about routes, how to you manage the URL concept in the terminal?Wonder if you artificially create it or are using some existing concept? Anyway I'm re-thinking is destroying the screens is really necessary. Thanks!
After some experimentation, it turns out appending and removing children from screen can cause some big issues. So the best way is to add all UI elements at once (for different "scenes"), and then hide/show individual UI elements as necessary.
I did something similar hide/show for an utility to maximize/restore a box - also needed to restore positions since I often work with layouts
https://github.com/cancerberoSgx/accursed/blob/master/src/blessed/maximize.ts and this other feature https://github.com/cancerberoSgx/accursed/blob/master/src/blessed/visibleOnAncestorFocus.tsx