[erlang-questions] escript capture special keys

Fred Hebert mononcqc@REDACTED
Mon Jun 1 15:16:50 CEST 2015

On 06/01, ino murko wrote:
>is there a way to capture specific keys from escript executable?
>Background info: I'm trying to implement command history with up and down

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 
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 

Rebar3 does specifically that when setting up `rebar3 shell` so it 
provides command stack and search regular Erlang supports: 

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.


More information about the erlang-questions mailing list