[erlang-questions] escript capture special keys
Fred Hebert
mononcqc@REDACTED
Mon Jun 1 15:16:50 CEST 2015
On 06/01, ino murko wrote:
>Hi,
>
>is there a way to capture specific keys from escript executable?
>
>Background info: I'm trying to implement command history with up and down
>arrows.
>
My understanding is that escripts use an older driver/tty than the
Erlang shell usually does and there's no way around that. This causes
some problem when wanting to say, capture passwords and hiding the
characters (see
https://github.com/tsloughter/rebar3_hex/blob/64c49f62958514cf7d64cbafb190b55b1c136758/src/rebar3_hex_user.erl#L122-L131
for a workaround)
However, for shell history and line numbers from an escript, there's a
"fun" hacky way to do it in which you can reuse the Erlang shell
architecture and boot your own there, and/or by stealing the stdio file
descriptors.
Rebar3 does specifically that when setting up `rebar3 shell` so it
provides command stack and search regular Erlang supports:
https://github.com/rebar/rebar3/blob/master/src/rebar_prv_shell.erl#L97-L119
It's all very hackish, but appears to work pretty damn well still.
The hack shows itself whenever you close the shell with ^C, which skips
over the whole:
BREAK: (a)bort (c)ontinue (p)roc info (i)nfo (l)oaded
(v)ersion (k)ill (D)b-tables (d)istribution
Menu and just exits right away. After that, output gets kind of mangled
on the bash/zsh shell (something looks weird with regards to what the
window size is), and I have never managed to find a workaround for that.
^G q and q() or init:stop() do not have that problem.
Regards,
Fred.
More information about the erlang-questions
mailing list