[erlang-questions] Reading (and ignoring) escape-sequences
Anthony Shipman
als@REDACTED
Thu Mar 25 10:43:23 CET 2010
On Thu, 25 Mar 2010 09:22:42 am Richard O'Keefe wrote:
> Because there _isn't_ any good way to handle it.
> Possible approaches:
> (0) use a window library like Erlang's gs for menus
> (1) don't use ESC
> (2) tell the emulator to send non-ESC sequences for arrows
> (3) use UNIX ptys to put some program of your own between Erlang
> and a "terminal", using ncurses to recognise "keys" and
> forwarding an unambiguous byte stream to Erlang.
What ncurses does is fiddle with the line discipline to set a 100ms
time delay. If a second character does not arrive from the tty
within this time it reports a single Esc to the program. If an arrow
key is pressed then all of the characters of the escape sequence will
be presented to the program.
I don't know of any way of doing this with a standard Erlang module but you
might be able to fake it by doing something like
os:cmd("/bin/stty -icanon min 2 time 1")
or erlang:open_port if that doesn't work. Don't forget to restore
the settings after.
--
Anthony Shipman Mamas don't let your babies
als@REDACTED grow up to be outsourced.
More information about the erlang-questions
mailing list