Get console user input as typed, char by char : <p>I have a console application in Elixir. I need to interpret user’s input on by keypress basis. For instance, I need to treat “q” as a command to end the session, without user to explicitly press <kbd>⏎</kbd> a.k.a. “carriage return.”</p>

<p><a href="http://elixir-lang.org/docs/stable/elixir/IO.html#getn/2"><code>IO.getn/2</code></a> surprisingly waits for the <kbd>⏎</kbd> to be pressed, buffering an input (I am nearly sure, that this buffering is done by console itself, but <code>man stty</code> does not provide any help/flag to turn buffering off.)</p>

<p><code>Mix.Utils</code> <a href="https://github.com/hexpm/hex/blob/1523f44e8966d77a2c71738629912ad59627b870/lib/mix/hex/utils.ex#L32-L58">use the infinite loop</a> to hide user input (basically sending backspace control sequence to console every 1ms,) <code>IEx</code> code wraps calls to standard erlang’s <code>io</code>, that provides the only ability to set a callback on <kbd>Tab</kbd> (for autocompletion.)</p>

<p>My guess would be I have to use <a href="http://elixir-lang.org/docs/stable/elixir/Port.html#summary"><code>Port</code></a>, attach it to <code>:stdin</code> and spawn a process to listen to the input. Unfortunately, I am stuck with trying to implement the latter, since I need to attach to the currently running console, not create a new port to some other process (as it is <a href="http://www.theerlangelist.com/article/outside_elixir">perfectly described here</a>.)</p>

<p>Am I missing something obvious on how am I to attach a <code>Port</code> to the current process’ <code>:stdin</code> (which is btw listed in <code>Port.list/0</code>,) or should I’ve built the whole 3-piped architecture to redirect what’s typed to <code>:stdin</code> and whatever my program wants to <code>puts</code> to <code>:stdout</code>?</p>
