[erlang-questions] Reading (and ignoring) escape-sequences

Mazen Harake mazen.harake@REDACTED
Thu Mar 25 12:45:43 CET 2010


On 25/03/2010 00:22, Richard O'Keefe wrote:
>
> On Mar 25, 2010, at 12:11 AM, Mazen Harake wrote:
>
>> An even better solution would be if this was done at a lower level so 
>> that perhaps (like ncurses) in erlang you would get e.g. 40x as the 
>> character for UpArrow (or whatever, it would probably be defined as 
>> macros anyway).
>
> And that's what I recommended:  doing it in ncurses and feeding Erlang
> a byte stream that is NOT ambiguous.  (However, as noted above, even
> ncurses is not and these days CANNOT be infallible.)

I tested this now and it seems to work well. In my driver I now make an 
initial port_command which calls driver_async which runs an input 
function. Even though this function is intended to return at some point 
and data be collected using ready_async I put it in an endless loop 
which only does getch(). When getch() returns I send a message straight 
back to Erlang. This wasn't enough though... so I also did a middle 
buffer process; if an Erlang program does cecho:getch() it will block by 
first sending a message to the middle process saying that it is waiting 
for input and then blocks waiting in a receive. When a message comes 
from the driver it checks if any process is waiting for input, if there 
is it gets the character, if it doesn't then the message from the port 
is simply discarded. Using this together with keypad(stdscr, TRUE) I now 
get unambiguous codes back (without the keypad() I seem to get only the 
'\027'), the only work left is to map all the keys (probably steal them 
from ncurses.h).

Initial tests indicate good results. This is great because I would 
_never_ have used a terminal GUI which asks me to hit _space_ for going 
down a list and _bksp_ for going up... it is simply not good usability.

Anyway, thank you for your time.

/Mazen


---------------------------------------------------

---------------------------------------------------

WE'VE CHANGED NAMES!

Since January 1st 2010 Erlang Training and Consulting Ltd. has become ERLANG SOLUTIONS LTD.

www.erlang-solutions.com



More information about the erlang-questions mailing list