blessed icon indicating copy to clipboard operation
blessed copied to clipboard

Question: Routing between screens

Open kbariotis opened this issue 5 years ago • 3 comments

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

kbariotis avatar Oct 30 '18 20:10 kbariotis

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!

cancerberoSgx avatar Apr 11 '19 15:04 cancerberoSgx

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.

poteat avatar Jul 10 '19 21:07 poteat

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

cancerberoSgx avatar Jul 11 '19 04:07 cancerberoSgx