How to implement a simple text menu in console? #7601
Replies: 1 comment
-
Posted at 2019-01-06 by @allObjects Not a perfect solution, but until you have something more elaborate: make the menu point A, B and C... and ask to enter A, B or C appended with (), for example: B(). This is like ad-hoc invoking the function B() on the Espruino board. Before showing the menu, define the A(), B() and C() ... functions (body) and delete them after menu input... (Instead of define and delete, assign A, B and C to and existing empty function, before the menu you assign them the desired existing functions, and afterwards you re-assign them again to the empty function.) That's the least intrusive option. The other option is to loop something into the console loop: before it reaches the JavaScript interpreter, you catch it, test it, and do what you need, and if it is not the menu thing, you pass it untouched... (Loopback?) may be you can put something into the echo-routined (post vs pre, and then clean out the expression input buffer of the JavaScript interpreter)... About the details: I'm not knowledgeable enough, would need to do some research. You can make the both flag/state controlled, so you do not have to setup and tear down for every menu. Posted at 2019-01-07 by @fanoush At least when console is on Serial1 you can move it somewhere else (LoopbackA.setConsole();) and then read Serial1 directly. And after reading answer you can set console back via Serial1.setConsole() Not sure if it is posible with bluetooth console too, possibly yes? Posted at 2019-01-08 by wklenk I like the idea with having A(), B(), C() function names. Posted at 2019-01-09 by @gfwilliams As @fanoush says you can move the console elsewhere. Maybe try something like:
Note that while the console is out the way, As @allObjects says, having Another option based on that is to use 'getters' that got introduced in new Espruino 2v00ish, which will work in a similar way, but without you needing the brackets:
Posted at 2019-01-09 by @allObjects @gfwilliams, getters are THE PERFECT solution... NICE ...how could I not think about... (never used getters, not even in my browser world, where most of my JS exposure happened...) Posted at 2019-01-10 by @fanoush
Well, in this specific case I would call it very nice hack, not perfect solution ;-) However something like console.pause()/resume() would help in this case so that it doesn't need to be reassigned twice with that ->xxx message. Also maybe console.current referencing which Serial device is current console would help in case of temporary reassignment (or is there a way to get it?). Posted at 2019-01-10 by @gfwilliams You can get the current device with Posted at 2019-01-10 by @fanoush
Yes. perhaps with some harmless Null device that would just drop the bytes if LoopbackA is not harmless (i.e. buffering the data for LoopbackB, eating memory). |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-01-06 by wklenk
Hi,
I am using a RAK8212 and want to implement a simple interactive text menu.
I am connected via BLE.
The text menu could look like this:
Bluetooth.read(1) returns immediately.
Bluetooth.on('data', function() {...}) also doesn't work, as the application has no such a thing as a event loop that runs all the time.
Any ideas how to create a interactive text menu in the console?
Beta Was this translation helpful? Give feedback.
All reactions